Re: test for list equality
On Fri, Dec 16, 2011 at 12:11 AM, Ian Kelly wrote: > On Thu, Dec 15, 2011 at 11:30 PM, Alec Taylor wrote: >> Just for fun, use the Hungarian Algorithm >> >> (Python implementation: http://software.clapper.org/munkres/) > > That's a pretty silly approach, but okay: > > def listequals(a, b): > if len(a) != len(b): > return False > matrix = [[int(item_a != item_b) for item_b in b] for item_a in a] > path = Munkres().compute(matrix) > return sum(matrix[r][c] for (r, c) in path) == 0 Amendment -- it seems that Hungarian implementation fails on an empty matrix: def listequals(a, b): if len(a) == len(b) == 0: return True if len(a) != len(b): return False matrix = [[int(item_a != item_b) for item_b in b] for item_a in a] path = Munkres().compute(matrix) return sum(matrix[r][c] for (r, c) in path) == 0 -- http://mail.python.org/mailman/listinfo/python-list
Re: test for list equality
On Thu, Dec 15, 2011 at 11:30 PM, Alec Taylor wrote: > Just for fun, use the Hungarian Algorithm > > (Python implementation: http://software.clapper.org/munkres/) That's a pretty silly approach, but okay: def listequals(a, b): if len(a) != len(b): return False matrix = [[int(item_a != item_b) for item_b in b] for item_a in a] path = Munkres().compute(matrix) return sum(matrix[r][c] for (r, c) in path) == 0 -- http://mail.python.org/mailman/listinfo/python-list
Re: ERP with Supply chain management (incl. POS) and Customer relationship management — What's available?
On Thu, Dec 15, 2011 at 5:54 AM, Anurag Chourasia wrote: I am building a POS/CRM (Loyalty Management) system as well. Is it just me, or does the phrase "Loyalty Management" have a faintly ominous ring to it? -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: test for list equality
Just for fun, use the Hungarian Algorithm (Python implementation: http://software.clapper.org/munkres/) On Fri, Dec 16, 2011 at 3:36 AM, noydb wrote: > I want to test for equality between two lists. For example, if I have > two lists that are equal in content but not in order, I want a return > of 'equal' -- dont care if they are not in the same order. In order > to get that equality, would I have to sort both lists regardless? if > yes, how (having issues with list.sort)? > > Another way i tried, that I think is kind-of roundabout is like > x = [2, 5, 1, 88, 9] > y = [5, 2, 9, 1, 88] > inBoth = list(set(x) & set(y)) > > and then test that list.count is equal between inBoth and x and/or y. > > > Any better suggestions? > > Thanks for any help! > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: % is not an operator [was Re: Verbose and flexible args and kwargs syntax]
On Dec 15, 2011 8:01 PM, "MRAB" wrote: > Python has "def", "del", "int", "str", "len", and so on. "rem" or "mod" > (Ada has both, I believe) would be in keeping with the language. I think I would have to object to "rem" purely on the basis that it denotes comments in BASIC. -- http://mail.python.org/mailman/listinfo/python-list
Re: % is not an operator [was Re: Verbose and flexible args and kwargs syntax]
On Dec 16, 3:01 pm, Chris Angelico wrote: > And I would be most sorry to see % renamed to mod in Python. > > "Hello, %s! My favourite number is %d." mod ("Fred",42) # This just > looks wrong. Finally we can give this operator a more fitting name - I propose 'inject' - and put an end to this insane desire to leverage off pre- existing knowledge of other languages. Furthermore, I suggest that no two languages should ever have identical semantics, just to avoid potential confusion. New concepts for all! -- http://mail.python.org/mailman/listinfo/python-list
Re: How to generate "a, b, c, and d"?
On 12/15/2011 9:42 PM, Chris Angelico wrote: On Fri, Dec 16, 2011 at 11:57 AM, Terry Reedy wrote: items[-1] = "and " + items[-1] return ", ".join(items) This works only if you're sure there are at least two items, and if you don't mind two items coming out as "a, and b". Please read the context that you removed. The original second return line and my replacements come after if len(items) <= 2: return " and ".join(items) -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
online data entry jobs
online data entry jobs http://venuonlinejobs.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: % is not an operator [was Re: Verbose and flexible args and kwargs syntax]
On Fri, Dec 16, 2011 at 1:58 PM, MRAB wrote: > In financial circles it could be an operator for calculating > percentages, eg. "5 % x" would be 5 percent of x. > > It's an oddity, but an established one. :-) And I would be most sorry to see % renamed to mod in Python. "Hello, %s! My favourite number is %d." mod ("Fred",42) # This just looks wrong. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Help about Xlib Library in Python
Hi, A question about Xlib Library in Python troubled me for several days and I finally found this email list. I hope someone could answer my question. I think it is easy for experienced user. I would like to write a small script to response my mouse click in root screen and write something in the terminal. My script is like this, but it does not work in my computer. from Xlib import X import Xlib.display def main(): display = Xlib.display.Display() root = display.screen().root root.change_attributes(event_mask= X.ButtonPressMask | X.ButtonReleaseMask) while True: event = root.display.next_event() print "1" if __name__ == "__main__": main() Any hints are welcome Thank you! Ruan zheng-- http://mail.python.org/mailman/listinfo/python-list
Re: AttributeError in "with" statement (3.2.2)
On Thu, 15 Dec 2011 05:35:55 -0800, Steve Howell wrote: > For the special methods like __enter__ and __exit__, the tricky part > isn't understanding what would happen once the methods were called; the > tricky part is getting them to be called in the first place, if they > were not declared inside the class or attached to the class. If you *must* have per-instance special methods, my advice is to use a bit of scaffolding like this: class Whatever: def __enter__(self, *args): try: enter = self.__dict__['__enter__'] except KeyError: do_something_else() # or just let the exception occur else: enter(*args) Otherwise just live with the limitation that you can override all methods per-instance *except* dunders, and design your application accordingly. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: % is not an operator [was Re: Verbose and flexible args and kwargs syntax]
On 16/12/2011 02:14, alex23 wrote: Eelco wrote: To tie it back in with python language design; all the more reason not to opt for pseudo-backwards compatibility. If python wants a remainder function, call it 'remainder'. Not 'rem', not 'mod', and certainly not '%'. Python has "def", "del", "int", "str", "len", and so on. "rem" or "mod" (Ada has both, I believe) would be in keeping with the language. Good luck with the PEP. Its the more pythonic way; a self-describing name, rather than poorly defined or poorly understood cryptology. "Although practicality beats purity." I'm still utterly agog that anyone finds the operator % confusing. In financial circles it could be an operator for calculating percentages, eg. "5 % x" would be 5 percent of x. It's an oddity, but an established one. :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: How to generate "a, b, c, and d"?
On Fri, Dec 16, 2011 at 11:57 AM, Terry Reedy wrote: > items[-1] = "and " + items[-1] > return ", ".join(items) This works only if you're sure there are at least two items, and if you don't mind two items coming out as "a, and b". ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: % is not an operator [was Re: Verbose and flexible args and kwargs syntax]
Eelco wrote: > To tie it back in with python language design; all the more reason not > to opt for pseudo-backwards compatibility. If python wants a remainder > function, call it 'remainder'. Not 'rem', not 'mod', and certainly not > '%'. Good luck with the PEP. > Its the more pythonic way; a self-describing name, rather than > poorly defined or poorly understood cryptology. "Although practicality beats purity." I'm still utterly agog that anyone finds the operator % confusing. -- http://mail.python.org/mailman/listinfo/python-list
Re: test for list equality
On 12/15/2011 12:59 PM, Miki Tebeka wrote: My sort issue... as in this doesn't work if x.sort == y.sort: You're missing the () to make it a function call. Also list.sort() returns none, it mutates the original list. You can either sorted(x) == sorted(y) or set(x) == set(y) or x.sort(); y.sort(); x == y -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: How to generate "a, b, c, and d"?
On 12/15/2011 12:27 PM, MRAB wrote: On 15/12/2011 16:48, Roy Smith wrote: I've got a list, ['a', 'b', 'c', 'd']. I want to generate the string, "a, b, c, and d" (I'll settle for no comma after 'c'). Is there some standard way to do this, handling all the special cases? [] ==> '' ['a'] ==> 'a' ['a', 'b'] ==> 'a and b' ['a', 'b', 'c', 'd'] ==> 'a, b, and c' It seems like the kind of thing django.contrib.humanize would handle, but alas, it doesn't. How about this: def and_list(items): if len(items) <= 2: return " and ".join(items) return ", ".join(items[ : -1]) + ", and " + items[-1] To avoid making a slice copy, last = items.pop() return ", ".join(items) + (", and " + last) I parenthesized the last two small items to avoid copying the long string twice with two appends. Even better is items[-1] = "and " + items[-1] return ", ".join(items) so the entire output is created in one operation with no copy. But I would only mutate the list if I started with items = list(iterable) where iterable was the input, so I was mutating a private copy. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: AttributeError in "with" statement (3.2.2)
On 12/15/2011 12:01 AM, Steven D'Aprano wrote: On Wed, 14 Dec 2011 18:13:36 -0500, Terry Reedy wrote: On 12/14/2011 3:01 AM, Steven D'Aprano wrote: On Wed, 14 Dec 2011 01:29:13 -0500, Terry Reedy wrote: To complement what Eric says below: The with statement is looking for an instance *method*, which by definition, is a function attribute of a *class* (the class of the context manager) that takes an instance of the class as its first parameter. Note in the above that I am talking about *instance methods*. I'm not sure that is correct... I don't think that there is anything "by definition" about where methods live. Since you are disagreeing with my statement that *instance methods* are class attributes, you had better be claiming that *instance methods* can live elsewhere, else your statement has no sense. From the Python glossary: "method: A function which is defined inside a class body." That is actually a bit too narrow, as a function can be added to the class after it is defined. But the point then is that it is treated as if defined inside the class body. Actually, I agree with Greg that rewording like he or I have suggested would be a good idea. So I'm happy for the glossary entry to stay as is, because complicating it would confuse the average coder more than it would educate them. But the definition as given is strictly wrong, because it fails to capture the essence of what distinguishes a method from other objects. It mistakes *how* you normally create a method for *what* a method is, a little like defining "a hamburger is a foodstuff you get from McDonalds by giving them money". Here are three ways that the definition fails: (1) You can create a function inside a class, and it remains a function, so long as the class constructor (metaclass) never gets to build a method object from the function. It is easy to do: just hide it inside a wrapper object. class FunctionInsideClass(object): ... def func(x, y): # define a function inside a class ... return x + 2*y ... print(type(func)) # confirm is actually is a function ... attr = (func,) # hide it from the metaclass ... del func The function is not an attribute of the class, so my revised definition does not fail. print(type(FunctionInsideClass.attr[0])) (2) Instead of hiding the function from the metaclass, you can change the metaclass to something which doesn't make methods out of functions. I won't show an example, because it's tricky to get right (or at least *I* find metaclasses tricky). The default metaclass does not 'make methods out of functions'. Rather, functions that are attributes of an instance of 'type' are treated as methods *when accessed* via an instance of that instance. In Py 2, they were wrapped as unbound methods when accessed via the class, but no longer in Py 3, which simplifies things. Now, perhaps you can define a metaclass that disables method behavior, but practically everything one say about normal Python functioning goes out the window when one invokes 'metaclasses' (which do not even have to be classes!). So I do not consider this relevant to the discussion. (3) So the definition is too broad: you can have functions defined inside classes that are not methods. But it is also too narrow: you can have methods outside of classes. I'm not talking about bound and unbound methods, but about *creating* the method from scratch outside of a class. When you call the method constructor directly, you can create a method from a function defined outside of a class. def func(self, a): ... return self + a ... type(func) # Definitely a function. obj = types.MethodType(func, 42) As I explained before, the intended input of MethodType is an *instance method* and an instance of the class it is an attribute of. (Or, I suspect, a class method and class, which is why the appropriate check in each case should be outside the call. But I am sticking with instance methods here.) If so, the output is a *bound method*. In your example above, func is not an instance method and obj is not a bound method. It is simply an partially evaluated curried function or if you prefer, a bound function. Take you pick, or make up your own term, but it is NOT an instance method, which is the subject under discussion. So obj has nothing to do with the definition of instance method and whether I had any authority for the definition I gave to the OP to help him solve his problem. obj(23) # Works as expected. 65 Yes, and I can think of three other ways to make an 'add42' function. type(obj) So what? That means 'bound method', but since your input function to MethodType is not a method, its output is not a bound method. So there's a method which has never been inside a class, and couldn't even if you tried: int is a built-in immutable type. Calling it a 'method' when it is not even a bound method does not make it an instance method, whic
Python Interpreter Error with PyDev (Eclipse IDE)
Hi, This is my first email to this list, so I apologize if there's a better mailing-list for this type of question. I'm looking to get started with python development, so I downloaded Python 3.2.2 and PyDev IDE for Eclipse. When I go to configure my interpreter for a new python project, Windows gives me the following error: "python.exe has stopped working" and then Eclipse shows "Error getting info on interpreter "See error log for details. No output was in the standard output when trying to create the interpreter info. The error output contains:>>Fatal Python error: Py_Initialize: unable to load the file system codec File "C:\csvn\Python25\\lib\encodings\__init__.py", line 120 raise CodecRegistryError,\ ^ SyntaxError: invalid syntax This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. <<" Does anybody have any idea what this means or what I'm doing wrong? I've tried re-installing Python, but still can't get it to work. And again, if I'm in the wrong place, please direct me to the proper mailing-list or forum. Thanks! Josh P.S. I'm not subscribed to this mailer, so please include me in your replies!-- http://mail.python.org/mailman/listinfo/python-list
Re: Can't get Apache2 tp process py (Ubuntu 11.10)
Ok, figured this out by myself. There was an apache config conflict, and the config without mod_python enabled took over the config with mod_python enabled. -- http://mail.python.org/mailman/listinfo/python-list
Re: % is not an operator [was Re: Verbose and flexible args and kwargs syntax]
On 12/15/2011 6:04 AM, rusi wrote: On Dec 15, 3:58 pm, Chris Angelico wrote: On Thu, Dec 15, 2011 at 9:47 PM, Robert Kern wrote: 42 = 2 mod 5 2 = 42 mod 5 It might make more sense to programmers if you think of it as written: 42 = 2, mod 5 2 = 42, mod 5 Better, using ascii text, would be 42 =mod5 2 where =mod is a parameterized equivalence relation that is coarser than = (which is =mod-infinity). divmod(a,inf) = 0,a. =mod1 is the most coarse relation in that it make every count equivalent. divmod(a,1) = a,1. For the record I should say that the guy who taught me abstract algebra, said about as much: He said that the notation a == b mod n should be written as a ==n b (read the == as 3 horizontal lines and the n as a subscript) The 3 horizontal line symbol is often used for equivalence relations other than =. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Ann: Python-SIMPL online tutorial updated to include examples of cloud interfacing
The Python-SIMPL tutorial is at: http://www.icanprogram.com/06py/lesson1/lesson1.html Several lessons (3,4, 6 &7) have been enhanced to include examples of Python apps interfacing to the cloud housed on a Linode. The open source SIMPL toolkit provides a very lean Send/Receive/Reply (QNX style) messaging library. A SIMPL application consists of 2 or more interacting SIMPL modules. A SIMPL module can be written in any number of supported languages including Python, C, C++, JAVA, Tcl/Tk or PHP. More importantly they can be mixed in any given SIMPL application. Through the use of generic surrogates, SIMPL modules are "naturally" cloud aware often without even a recompile. In this tutorial a SIMPL receiver module (written in C) is exported unchanged to the Linode cloud. Examples of Python modules connecting to this Linode hosted module via the SIMPL TCP/IP surrogates, SIMPL tclSurrogate daemon, and Python-CGI are all illustrated. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: How to generate "a, b, c, and d"?
On Thu, Dec 15, 2011 at 11:51 AM, Tim Chase wrote: > For the fun/challenge? Because you have a REALLY big data source that you > don't want to keep in memory (in addition the resulting string)? If you have that much data, then I question why you would want to build such a large human-readable list in the first place. Nobody is going to want to read that no matter how you format it. -- http://mail.python.org/mailman/listinfo/python-list
RE: Localhost client-server simple ssl socket test program problems
Hello~ Thanks for your fast reply. No, it doesn't ask for password, just a single line with "writing RSA kay", then mypha-nopasswd.key appeared. If my key is not in PEM Format, can openssl with simple commands to switch it to? Or I should re-do the self-signed process with some certain key-words / parameters? And what you mean about Python 2.x's SSL module doesn't support cert directories ? Can you be more specific about that ^^. Do you mean parameters with certfile and keyfile those two should put together or CA certificate need to be chained with other CA? Thanks. Kay > To: python-list@python.org > From: li...@cheimes.de > Subject: Re: Localhost client-server simple ssl socket test program problems > Date: Thu, 15 Dec 2011 21:19:14 +0100 > > Am 15.12.2011 21:09, schrieb Yang Chun-Kai: > > Thanks for tips. > > > > But I dont understand one thing is if Python's SSL lib doesn't support > > encrypted private keys for sockets. > > > > Then why should we "encrypt" the private key with "openssl rsa -in > > /etc/home/ckyang/PHA/testsslsocket/mypha.key -out > > > > /etc/home/ckyang/PHA/testsslsocket/mypha-nopasswd.key" again? > > > > Shouldn't that be decrypted? > > > > And also this solution is not the right one , I use mypha-nopasswd.key > > replace the original one, still not work. > > IIRC the command should decrypt the key. Did it prompt for a password? > > The error could be caused by other issues. For example the key and cert > must be in PEM Format. The PKS#12 isn't supported. I'm not sure if > Python's builtin SSL module loads DER certs. > > You may also missing a valid CA cert chain. Python 2.x's SSL module > doesn't support cert directories so you have to provide a chain file. > The certs in the chain file must be in the right order, too. > > Christian > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Overriding a global
On 14 December 2011 17:06, Jean-Michel Pichavant wrote: > Joshua Landau wrote: > >> [snip] >> Using currentLogger is just padding, in my opinion. *Every *value is >> "current". >> > Not always. I try to keep names on the same object because that object is > supposed to be named that way. > I can change one of the object attribute, but the object named that way > keep being the same. > > Class Foo: > self.__init__(self): >self.banana = 5 > > myFoo = Foo() > > Now there's a slight difference between > > myFoo = Exception() > and > myFoo.banana = 4 > > The first statement rebind myFoo to something complitely different. > the second statement change one of the object rightfully named myFoo .. > attribute (not sure about this construct :D ) > > Int being inmutable, you can rebind a name without changing its meaning. > type(myFoo) before != type(myFoo) after type(myFoo.bannana) before == type(myFoo.bannana) after type(logger) before == type(logger) after You are changing the int to a new value, but it's OK for you - if I understand rightly - because it's not changing its "meaning". The "meaning" of logger is the same too, as it does the same thing, in approximately the same way. I agree that "logger = Exception()" would be vary bad in that sense, too. The point is you use it the same way and it's not going to cause problems from misunderstanding what the object type is. And because "logger = childLogger('this_function')" is explicit and hopefully at the top 'o the function, any conceivable errors should be pretty obvious. Note that I used quotation marks around "meaning" not to mock the use or whatnot, but because I was trying to show that I was trying to use the same version of the word you did. I don't know if that was clear from the passage itself. That said, you did keep the myFoo the same, even with the int change. That makes the change global to all myFoo instances. But I didn't get that as a main point from your argument, and if it was I fear we're too close to recursive arguments. And in regards to your own commentary on your English, I wouldn't like you to see it as trouble. I'm currently thoroughly enjoying the debate, and wouldn't like to see myself scaring you off... -- http://mail.python.org/mailman/listinfo/python-list
Re: [Tutor] Localhost client-server simple ssl socket test program problems
On Fri, Dec 16, 2011 at 6:24 AM, Alexander wrote: > You're trying to connect to the same port on localhost as a client and a > server? I don't know for certain but I don't think that should work. > Two computers? That's bind() on the server and connect() on the client - the normal way to do things. That part of the code is fine (far as I can tell - haven't actually run the code, just eyeballed it). Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list
LoadLibrary and extern ctype
Hi, I've a little problem for define this : extern enum __pmerrno_t { PM_ERR_MEMORY = 1, PM_ERR_SYSTEM, PM_ERR_WRONG_ARCH } pm_errno; I've write : pacman=cdll.LoadLibrary("libpacman.so") ... #errors ( PM_ERR_MEMORY , PM_ERR_SYSTEM, ... PM_ERR_WRONG_ARCH )=map(ctypes.c_int, xrange(1,63)) I would use pacman.pm_errno. That should be a integer but if I print the value it I've : <_FuncPtr object at 0xb73ce984> Howto find the value (or define ) pacman.pm_errno ? The complete code can be find here : http://dors.frugalware.org/tmpgit/frugal-tweak/py-pacman/py-pacman.py and the .h is here http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=blob_plain;f=lib/libpacman/pacman.h;h=0f2a191681085dee99f485bad43a620043528904;hb=HEAD -- #--- #Bouleetbil # #--- # __ #(o)--(o) # /.__.\ # \___/ # ./\. # ( ., ) # \ \_\\//_/ / # ~~ ~~ ~~ #--- -- http://mail.python.org/mailman/listinfo/python-list
Re: Localhost client-server simple ssl socket test program problems
Am 15.12.2011 21:09, schrieb Yang Chun-Kai: > Thanks for tips. > > But I dont understand one thing is if Python's SSL lib doesn't support > encrypted private keys for sockets. > > Then why should we "encrypt" the private key with "openssl rsa -in > /etc/home/ckyang/PHA/testsslsocket/mypha.key -out > > /etc/home/ckyang/PHA/testsslsocket/mypha-nopasswd.key" again? > > Shouldn't that be decrypted? > > And also this solution is not the right one , I use mypha-nopasswd.key > replace the original one, still not work. IIRC the command should decrypt the key. Did it prompt for a password? The error could be caused by other issues. For example the key and cert must be in PEM Format. The PKS#12 isn't supported. I'm not sure if Python's builtin SSL module loads DER certs. You may also missing a valid CA cert chain. Python 2.x's SSL module doesn't support cert directories so you have to provide a chain file. The certs in the chain file must be in the right order, too. Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: AttributeError in "with" statement (3.2.2)
MRAB wrote: To give an analogy, it is like defining mammals as "hairy animals which give birth to live young", which is correct for all mammals except for monotremes, which are mammals which lay eggs. Or the naked mole-rat. Or cetaceans (whales). The way I understand it, the main characteristic shared by all mammals is the presence of mammary glands in females. To wrest this back on topic, sometimes a definition can be improved without making it any more complicated. In the case of methods, perhaps instead of "defined inside a class body" it could say "bound to a name in a class namespace". That's what really matters, not how it came to be there. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
PyDev 2.3.0 Released
Hi All, PyDev 2.3.0 has been released Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com Release Highlights: --- * Pep8.py integrated (must be enabled in PyDev > Editor > Code Analysis > pep8.py). * Faster PyDev startup (internal Jython upgraded to version 2.2.1 -- and also optimized for PyDev). * Action to select/deselect scope (Shift+Alt+Up/Down). * Fix: cache issue where the PYTHONPATH in memory became different from the PYTHONPATH configured for a project. * Fix: OutOfMemoryError when dealing with PyOpenGL. * Fix: deadlock (could occur in a race condition when importing a project with an existing Python configuration). * Fix: code-completion integration issue with IPython 011 (patch from jonahkichwacoders). * Fix: annotation could remain in editor after removing a marker. * Fix: BadLocationException on extract local refactoring. What is PyDev? --- PyDev is a plugin that enables users to use Eclipse for Python, Jython and IronPython 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 Appcelerator http://appcelerator.com/ Aptana http://aptana.com/ PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
RE: Localhost client-server simple ssl socket test program problems
Thanks for tips. But I dont understand one thing is if Python's SSL lib doesn't support encrypted private keys for sockets. Then why should we "encrypt" the private key with "openssl rsa -in /etc/home/ckyang/PHA/testsslsocket/mypha.key -out /etc/home/ckyang/PHA/testsslsocket/mypha-nopasswd.key" again? Shouldn't that be decrypted? And also this solution is not the right one, I use mypha-nopasswd.key replace the original one, still not work. So sad. But thanks. ^ ^ Kay > To: python-list@python.org > From: li...@cheimes.de > Subject: Re: Localhost client-server simple ssl socket test program problems > Date: Thu, 15 Dec 2011 20:45:43 +0100 > > Am 15.12.2011 20:09, schrieb Yang Chun-Kai: > > Server side error: > > > > File "views.py", line 17, in > > connstream = ssl.wrap_socket(newsocket, server_side=True, > > certfile="/etc/home/ckyang/PHA/testsslsocket/mypha.crt", > > keyfile="/etc/home/ckyang/PHA/testsslsocket/mypha.key", > > ssl_version=ssl.PROTOCOL_SSLv23) > > File "/usr/lib/python2.7/ssl.py", line 344, in wrap_socket > > ciphers=ciphers) > > File "/usr/lib/python2.7/ssl.py", line 119, in __init__ > > ciphers) > > ssl.SSLError: [Errno 336265218] _ssl..c:347: error:140B0002:SSL > > routines:SSL_CTX_use_PrivateKey_file:system lib > > This error is most likely caused by an encrypted private key. Python's > SSL lib doesn't support encrypted private keys for sockets. You can > encrypt the private key with > >openssl rsa -in /etc/home/ckyang/PHA/testsslsocket/mypha.key -out > /etc/home/ckyang/PHA/testsslsocket/mypha-nopasswd.key > > Christian > > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Screen Control Fullscreen ON/OFF
On 2011-12-15, Nizamov Shawkat wrote: >>> >>> I would like to make fullscreen white and fullscreen black using >>> Python on Linux. With in the specs of the LCD, I want to be able to >>> display fullscreen white and black approximately at 30Hz. Frequency >>> (on/off per second) will be input manually which is between 1-40Hz. >>> Any idea where to start ? Can Python perform such fast thing ? >> >> Forgot to mention and sorry for the pollution ; >> >> My LCD has 2ms respond time thus it can handle a maximum of 50Hz ON/ >> OFF (white/black) thus seems to fit my 1-40Hz range. I am not asking >> or looking for a fully working code, I just need some directions. > > > It depends on whether you want sync to vblank or not. If not, that is > pretty easy - use sleep() or something similar. If you have to use > sync (screen is always either black or white, never partly black and > white) then it is much much more difficult. Actually I do not know of > any way to sync to it. I'm _guessing_ the results won't be acceptible unless you switch during the veritical blanking period. (_is_ there a vertical blanking period with a DVI or HDMI output?). I have vague recollections that I think opengl has methods to do that. If there is an easy way to do it, it'll probably be using pygame: http://pygame.org/news.html If pygame can't do it, try pyopengl: http://pyopengl.sourceforge.net/ Here's a thread on how to do it on OSX: http://www.idevgames.com/forums/thread-2974.html -- Grant Edwards grant.b.edwardsYow! My face is new, my at license is expired, and I'm gmail.comunder a doctor's care -- http://mail.python.org/mailman/listinfo/python-list
Re: Localhost client-server simple ssl socket test program problems
Am 15.12.2011 20:09, schrieb Yang Chun-Kai: > Server side error: > > File "views.py", line 17, in > connstream = ssl.wrap_socket(newsocket, server_side=True, > certfile="/etc/home/ckyang/PHA/testsslsocket/mypha.crt", > keyfile="/etc/home/ckyang/PHA/testsslsocket/mypha.key", > ssl_version=ssl.PROTOCOL_SSLv23) > File "/usr/lib/python2.7/ssl.py", line 344, in wrap_socket > ciphers=ciphers) > File "/usr/lib/python2.7/ssl.py", line 119, in __init__ > ciphers) > ssl.SSLError: [Errno 336265218] _ssl..c:347: error:140B0002:SSL > routines:SSL_CTX_use_PrivateKey_file:system lib This error is most likely caused by an encrypted private key. Python's SSL lib doesn't support encrypted private keys for sockets. You can encrypt the private key with openssl rsa -in /etc/home/ckyang/PHA/testsslsocket/mypha.key -out /etc/home/ckyang/PHA/testsslsocket/mypha-nopasswd.key Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: file data => array(s)
On 15/12/2011 18:37, Eric wrote: [snip] Neat. This is what I had in mind for a python-esque solution. [snip] FYI, the word is "Pythonic" when talking about the programming language. The word "Pythonesque" refers to Monty Python. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to generate "a, b, c, and d"?
On 15/12/2011 18:51, Tim Chase wrote: On 12/15/11 12:19, Ethan Furman wrote: Tim Chase wrote: On 12/15/11 10:48, Roy Smith wrote: I've got a list, ['a', 'b', 'c', 'd']. I want to generate the string, "a, b, c, and d" (I'll settle for no comma after 'c'). Is there some standard way to do this, handling all the special cases? If you have a list, it's pretty easy as MRAB suggests. For arbitrary iterators, it's a bit more complex. Especially with the odd edge-case of 2 items where there's no comma before the conjunction (where>2 has the comma before the conjunction). If you were willing to forgo the Oxford comma, it would tidy up the code a bit. Why go through all that instead of just converting the iterator into a list at the beginning of MRAB's solution and then running with it? For the fun/challenge? Because you have a REALLY big data source that you don't want to keep in memory (in addition the resulting string)? Yeah, for most non-pathological cases, it would make more sense to just make it a list and then deal with the 4 cases (no elements, one element, 2 elements, and>2 elements) individually. I was going to question it too, but then I wondered what would happen if there were a very large number of items and the string would be too big for memory, for example, writing a list of all the numbers from one to a billion to a file. -- http://mail.python.org/mailman/listinfo/python-list
Re: [Tutor] Localhost client-server simple ssl socket test program problems
2011/12/15 Yang Chun-Kai > Hello,everyone!! > > I am writing a simple ssl client-server test program on my personal laptop. > > And I encounter some problems with my simple programs. > > Please give me some helps. > > > > My server code: > > import socket > import ssl > bindsocket = socket.socket() > bindsocket.bind(('127.0.0.1', 1234)) > bindsocket.listen(5) > print 'server is waiting for connection...' > newsocket, fromaddr = bindsocket.accept() > print 'start ssl socket...' > connstream = ssl.wrap_socket(newsocket, server_side=True, > certfile="/etc/home/ckyang/PHA/testsslsocket/mypha.crt", > keyfile="/etc/home/ckyang/PHA/testsslsocket/mypha.key", > ssl_version=ssl.PROTOCOL_SSLv23) > data = connstream.read() > print 'connected from address', fromaddr > print 'received data as', repr(data) > connstream.close() > > My client code: > > import socket > import ssl > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > ssl_sock = ssl.wrap_socket(s, > ca_certs="/home/ckyang/PHA/testsslsocket/myCA.crt", > cert_reqs=ssl.CERT_REQUIRED) > ssl_sock.connect(("127.0.0.1", 1234)) > ssl_sock.write("hello") > ssl_sock.close() > > > --- > Server side error: > > File "views.py", line 17, in & lt;module> > connstream = ssl.wrap_socket(newsocket, server_side=True, > certfile="/etc/home/ckyang/PHA/testsslsocket/mypha.crt", > keyfile="/etc/home/ckyang/PHA/testsslsocket/mypha.key", > ssl_version=ssl.PROTOCOL_SSLv23) > File "/usr/lib/python2.7/ssl.py", line 344, in wrap_socket > ciphers=ciphers) > File "/usr/lib/python2.7/ssl.py", line 119, in __init__ > ciphers) > ssl.SSLError: [Errno 336265218] _ssl.c:347: error:140B0002:SSL > routines:SSL_CTX_use_PrivateKey_file:system lib > > Client side error: > > File "client.py", line 10, in > ssl_sock.connect(("127.0.0.1", 1234)) > File "/usr/lib/python2.7/ssl.py", line 299, in connect** > self.do_handshake() > File "/usr/lib/python2.7/ssl.py", line 283, in do_handshake > self._sslobj.do_handshake() > socket.error: [Errno 104] Connection reset by peer > > > > So what is wrong with my code? > > The codes are so simple and so much like python official site sample > demonstration, but I still cant get it work, so frustrating. > > Seems the problem happened on server side then cause client side cant > connect well, is that right? > > ** > My platform is ubuntu, with openssl 0.9.8 and python 2.7. > > All certificates and keys self-signed by openssl for test convenience. > > This is the site for referrence : > http://andyjeffries.co.uk/articles/x509-encrypted-authenticated-socket-ruby-client > > Or should I need a real certificate issued by a real CA to let things work? > > Any tips or suggestions welcomed, thank you very much~ > > Good day. > > Kay > > ** > > ___ > Tutor maillist - tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > You're trying to connect to the same port on localhost as a client and a server? I don't know for certain but I don't think that should work. Two computers? -- Alexander 7D9C597B -- http://mail.python.org/mailman/listinfo/python-list
Localhost client-server simple ssl socket test program problems
Hello,everyone!! I am writing a simple ssl client-server test program on my personal laptop. And I encounter some problems with my simple programs. Please give me some helps. My server code: import socketimport sslbindsocket = socket.socket()bindsocket.bind(('127.0.0.1', 1234))bindsocket.listen(5)print 'server is waiting for connection...'newsocket, fromaddr = bindsocket.accept()print 'start ssl socket...'connstream = ssl.wrap_socket(newsocket, server_side=True, certfile="/etc/home/ckyang/PHA/testsslsocket/mypha.crt", keyfile="/etc/home/ckyang/PHA/testsslsocket/mypha.key", ssl_version=ssl.PROTOCOL_SSLv23)data = connstream.read()print 'connected from address', fromaddrprint 'received data as', repr(data)connstream.close() My client code: import socketimport ssls = socket.socket(socket.AF_INET, socket.SOCK_STREAM)ssl_sock = ssl.wrap_socket(s, ca_certs="/home/ckyang/PHA/testsslsocket/myCA.crt", cert_reqs=ssl.CERT_REQUIRED)ssl_sock.connect(("127.0.0.1", 1234))ssl_sock.write("hello")ssl_sock.close() ---Server side error: File "views.py", line 17, in connstream = ssl.wrap_socket(newsocket, server_side=True, certfile="/etc/home/ckyang/PHA/testsslsocket/mypha.crt", keyfile="/etc/home/ckyang/PHA/testsslsocket/mypha.key", ssl_version=ssl.PROTOCOL_SSLv23) File "/usr/lib/python2.7/ssl.py", line 344, in wrap_socketciphers=ciphers) File "/usr/lib/python2.7/ssl.py", line 119, in __init__ciphers)ssl.SSLError: [Errno 336265218] _ssl.c:347: error:140B0002:SSL routines:SSL_CTX_use_PrivateKey_file:system lib Client side error: File "client.py", line 10, in ssl_sock.connect(("127.0.0.1", 1234)) File "/usr/lib/python2.7/ssl.py", line 299, in connectself.do_handshake() File "/usr/lib/python2.7/ssl.py", line 283, in do_handshake self._sslobj.do_handshake()socket.error: [Errno 104] Connection reset by peer So what is wrong with my code? The codes are so simple and so much like python official site sample demonstration, but I still cant get it work, so frustrating. Seems the problem happened on server side then cause client side cant connect well, is that right? My platform is ubuntu, with openssl 0.9.8 and python 2.7. All certificates and keys self-signed by openssl for test convenience. This is the site for referrence : http://andyjeffries.co.uk/articles/x509-encrypted-authenticated-socket-ruby-client Or should I need a real certificate issued by a real CA to let things work? Any tips or suggestions welcomed, thank you very much~ Good day. Kay -- http://mail.python.org/mailman/listinfo/python-list
Re: file data => array(s)
On Dec 14, 4:59 pm, Dave Angel wrote: > On 12/14/2011 05:20 PM, Eric wrote: > > > > > > > > > I'm trying to read some file data into a set of arrays. The file data > > is just four columns of numbers, like so: > > > 1.2 2.2 3.3 0.5 > > 0.1 0.2 1.0 10.1 > > ... and so on > > > I'd like to read this into four arrays, one array for each column. > > Alternatively, I guess something like this is okay too: > > > [[1.2, 2.2, 3.3, 0.5], [0.1, 0.2, 1.0, 10.1], ... and so on] > > > I came up with the following for the four array option: > > > file = open(fileName, 'r') > > for line in file.readlines(): > > The readlines() call is a waste of time/space. file is already an > iterator that'll return lines for you. > > > > > > > > > d1, e1, d2, e2 = map(float, line.split()) > > data1.append(d1) # where data1, err1, data2, err2 are init-ed > > as empty lists > > err1.append(e1) > > data2.append(d2) > > err2.append(e2) > > file.close() > > > But somehow it doesn't seem very python-esque (I'm thinking there's a > > more elegant and succinct way to do it in python). I've also tried > > replacing the above "map" line with: > > > d = d + map(float, line.split()) # where d is initialized as d > > = [] > > > But all I get is one long flat list, not what I want. > > > So is the map and append method the best I can do or is there a > > slicker way? > > > One more thing, no numpy. Nothing against numpy but I'm curious to > > see what can be done with just the box stock python install. > > > TIA, > > eric > > When I see a problem like this, I turn to zip(). It's got some powerful > uses when rows and columns need inverting. > > I didn't try it on an actual file, but the following works: > linedata = [[1.2, 2.2, 3.3, 0.5], [0.1, 0.2, 1.0, 10.1] ] > > data, err1, data2, err2 = zip(*linedata) > > print data > print err1 > print data2 > print err2 > > So you could try (untested) > > file = open(filename, "r") > linedata = [ map(float, line) for line in file] > data, err1, data2, err2 = zip(*linedata) > file.close() > > DaveA Neat. This is what I had in mind for a python-esque solution. Only thing is "map(float,line)" should be "map(float,line.split()). Looks like it should be easy enough to weed out any funky data sets because between map() and zip() it's fairly picky about the amount and type of data. Finally, the input files I'll be using for real aren't just four columns of data. The beginning of the file may have comments (optional) and will have two lines of text to identify the data. Maybe I can still do it w/o readlines. Thanks, eric -- http://mail.python.org/mailman/listinfo/python-list
Re: How to generate "a, b, c, and d"?
FWIW, I ended up with: n = len(names) if n == 0: return '' if n == 1: return names[0] pre = ', '.join(names[:-1]) post = names[-1] return '%s, and %s' (pre, post) the slice-and-join() takes care of both the 2 and >2 element cases at the same time :) It would be nice if there were some standard way to do this. I'm sure I've seen something that was essentially a join() that took two delimiters; one for most elements, the other a special-case for the last one. I can't remember where I saw it. I'm guessing in some web framework. -- http://mail.python.org/mailman/listinfo/python-list
Re: file data => array(s)
On Dec 14, 5:27 pm, Steven D'Aprano wrote: > On Wed, 14 Dec 2011 14:20:40 -0800, Eric wrote: > > I'm trying to read some file data into a set of arrays. The file data > > is just four columns of numbers, like so: > > > 1.2 2.2 3.3 0.5 > > 0.1 0.2 1.0 10.1 > > ... and so on > > > I'd like to read this into four arrays, one array for each column. > > Alternatively, I guess something like this is okay too: > > > [[1.2, 2.2, 3.3, 0.5], [0.1, 0.2, 1.0, 10.1], ... and so on] > > First thing: due to the fundamental nature of binary floating point > numbers, if you convert text like "0.1" to a float, you don't get 0.1, > you get 0.10001. That is because 0.1000...01 is the closest > possible combination of fractions of 1/2, 1/4, 1/8, ... that adds up to > 1/10. > > If this fact disturbs you, you can import the decimal module and use > decimal.Decimal instead; otherwise forget I said anything and continue > using float. I will assume you're happy with floats. > Yeah, I don't think it'll be a problem. As I understand it a float in python is a double in C and all our old C programs used doubles. From PDP-11 to MIPS3k to P2 I've seen what I think may have been rounding or precision errors but I haven't heard any complaints because of them. Thanks, eric -- http://mail.python.org/mailman/listinfo/python-list
Re: How to generate "a, b, c, and d"?
On 12/15/11 12:19, Ethan Furman wrote: Tim Chase wrote: On 12/15/11 10:48, Roy Smith wrote: I've got a list, ['a', 'b', 'c', 'd']. I want to generate the string, "a, b, c, and d" (I'll settle for no comma after 'c'). Is there some standard way to do this, handling all the special cases? If you have a list, it's pretty easy as MRAB suggests. For arbitrary iterators, it's a bit more complex. Especially with the odd edge-case of 2 items where there's no comma before the conjunction (where>2 has the comma before the conjunction). If you were willing to forgo the Oxford comma, it would tidy up the code a bit. Why go through all that instead of just converting the iterator into a list at the beginning of MRAB's solution and then running with it? For the fun/challenge? Because you have a REALLY big data source that you don't want to keep in memory (in addition the resulting string)? Yeah, for most non-pathological cases, it would make more sense to just make it a list and then deal with the 4 cases (no elements, one element, 2 elements, and >2 elements) individually. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: How to generate "a, b, c, and d"?
Tim Chase wrote: On 12/15/11 10:48, Roy Smith wrote: I've got a list, ['a', 'b', 'c', 'd']. I want to generate the string, "a, b, c, and d" (I'll settle for no comma after 'c'). Is there some standard way to do this, handling all the special cases? [] ==> '' ['a'] ==> 'a' ['a', 'b'] ==> 'a and b' ['a', 'b', 'c', 'd'] ==> 'a, b, and c' It seems like the kind of thing django.contrib.humanize would handle, but alas, it doesn't. If you have a list, it's pretty easy as MRAB suggests. For arbitrary iterators, it's a bit more complex. Especially with the odd edge-case of 2 items where there's no comma before the conjunction (where >2 has the comma before the conjunction). If you were willing to forgo the Oxford comma, it would tidy up the code a bit. Sample code below Why go through all that instead of just converting the iterator into a list at the beginning of MRAB's solution and then running with it? ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: test for list equality
On Thu, Dec 15, 2011 at 11:07 AM, noydb wrote: > Ahh, I see (on the sort issue), thanks All! > > Still, any other slicker ways to do this? Just for learning. MRAB's collections.Counter suggestion is what I would do. Very tidy, and also more efficient I think: O(n) instead of O(n log n). -- http://mail.python.org/mailman/listinfo/python-list
Re: test for list equality
> > set(x) == set(y) > > Duplicates cause issues in the set() version: You're right, I stand corrected. -- http://mail.python.org/mailman/listinfo/python-list
Re: Odd behavior of object equality/identity in the context of relative vs fully qualified imports
Nathan Rice wrote: > I just ran into this yesterday, and I am curious if there is a > rational behind it... > > I have a class that uses a dictionary to dispatch from other classes > (k) to functions for those classes (v). I recently ran into a bug > where the dictionary would report that a class which was clearly in > the dictionary's keys was giving a KeyError. id() produced two > distinct values, which I found to be curious, and > issubclass/isinstance tests also failed. When I inspected the two > classes, I found that the only difference between the two was the > __module__ variable, which in one case had a name relative to the > current module (foo), and in another case had the fully qualified name > (bar.foo). When I went ahead and changed the import statement for the > module to import bar.foo rather than import foo, everything worked as > expected. My first thought was that I had another foo module in an > old version of the bar package somewhere on my pythonpath; After a > thorough search this proved not to be the case. > > Has anyone else run into this? Is this intended behavior? If so, why? Not exactly intended, but a logical side effect of how Python identifies its modules. The problem is that you have an entry in sys.path that reaches into the bar package. When you import foo Python does not check whether [path1]/bar/foo.py points to the same file as [path2]/foo.py, it just verifies that the name "foo" is not in the sys.modules cache before it physically imports the file. Therefore you get two distinct imports of "foo.py" stored in the cache as "foo" and "bar.foo". As Python's classes are not declarations, but objects themselves you get distinct classes just as with the following >>> classes = set() >>> for i in range(3): ... class A: pass ... >>> classes = set() >>> for i in range(3): ... class A: pass ... classes.add(A) ... >>> classes set([, , ]) To avoid the problem just remove the offending [path2] from sys.path and always import the foo subpackage with import bar.foo # everywhere or from . import foo # inside bar PS: You may run into similar problems when you import the main module of a program. It will end up in the module cache as filename_sans_extension and "__main__". -- http://mail.python.org/mailman/listinfo/python-list
Re: test for list equality
On 12/15/11 11:59, Miki Tebeka wrote: My sort issue... as in this doesn't work if x.sort == y.sort: You're missing the () to make it a function call. Also list.sort() returns none, it mutates the original list. You can either sorted(x) == sorted(y) or set(x) == set(y) Duplicates cause issues in the set() version: a = [1,2,3,4] b = a + a print sorted(a) == sorted(b) # False print set(a) == set(b) # True They mean different things, and the OP may want one or the other depending on how they want to consider duplicates. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: test for list equality
On 15/12/2011 17:59, Miki Tebeka wrote: My sort issue... as in this doesn't work >>> if x.sort == y.sort: You're missing the () to make it a function call. Also list.sort() returns none, it mutates the original list. You can either sorted(x) == sorted(y) or set(x) == set(y) But don't use sets if there may be duplicates. -- http://mail.python.org/mailman/listinfo/python-list
MySQLdb for Python 2.7.2 for Windows 32 bit?
Is there a MySQLdb binary for Python 2.7.2 for Windows 32 bit? There's a 2.7 binary at "http://www.lfd.uci.edu/~gohlke/pythonlibs/"; but not a 2.7.2 binary. (Also, using modules from untrusted sites is riskier than it used to be. GPL code for major packages with added spyware and adware has appeared on major sites. CNet was heavily criticized for bundling NMap with adware on "download.com") John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: test for list equality
On 15/12/2011 17:49, noydb wrote: On Dec 15, 11:36 am, noydb wrote: I want to test for equality between two lists. For example, if I have two lists that are equal in content but not in order, I want a return of 'equal' -- dont care if they are not in the same order. In order to get that equality, would I have to sort both lists regardless? if yes, how (having issues with list.sort)? Another way i tried, that I think is kind-of roundabout is like x = [2, 5, 1, 88, 9] y = [5, 2, 9, 1, 88] inBoth = list(set(x)& set(y)) and then test that list.count is equal between inBoth and x and/or y. Any better suggestions? Thanks for any help! My sort issue... as in this doesn't work if x.sort == y.sort: ... print 'equal' ... else: ... print 'not equal' ... not equal ??? .sort is a method which sorts the list in-place and returns None. You must provide the () if you want to call it, otherwise you just get a reference to the method: >>> x [2, 5, 1, 88, 9] >>> x.sort >>> x.sort() >>> x [1, 2, 5, 9, 88] There's also a function "sorted" which returns its argument as a sorted list. The argument itself isn't altered: >>> y = [5, 2, 9, 1, 88] >>> sorted(y) [1, 2, 5, 9, 88] >>> y [5, 2, 9, 1, 88] It's all in the documentation! :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: test for list equality
On Dec 15, 11:59 am, Miki Tebeka wrote: > > My sort issue... as in this doesn't work > > >>> if x.sort == y.sort: > > You're missing the () to make it a function call. > Also list.sort() returns none, it mutates the original list. > You can either > sorted(x) == sorted(y) > or > set(x) == set(y) I'm pretty sure we don't want to use set() since it throws away duplicates: >>> x = [1,2,3,4] >>> y = [1,1,2,2,3,3,4] >>> sorted(x) == sorted(y) False >>> set(x) == set(y) True -- http://mail.python.org/mailman/listinfo/python-list
Re: Odd behavior of object equality/identity in the context of relative vs fully qualified imports
On Thu, Dec 15, 2011 at 7:34 AM, Nathan Rice wrote: > I just ran into this yesterday, and I am curious if there is a > rational behind it... > > I have a class that uses a dictionary to dispatch from other classes > (k) to functions for those classes (v). I recently ran into a bug > where the dictionary would report that a class which was clearly in > the dictionary's keys was giving a KeyError. id() produced two > distinct values, which I found to be curious, and > issubclass/isinstance tests also failed. When I inspected the two > classes, I found that the only difference between the two was the > __module__ variable, which in one case had a name relative to the > current module (foo), and in another case had the fully qualified name > (bar.foo). When I went ahead and changed the import statement for the > module to import bar.foo rather than import foo, everything worked as > expected. My first thought was that I had another foo module in an > old version of the bar package somewhere on my pythonpath; After a > thorough search this proved not to be the case. > > Has anyone else run into this? Is this intended behavior? If so, why? I think this may be the same problem that the poster in this thread encountered: http://groups.google.com/group/comp.lang.python/browse_thread/thread/961a90219a61e19d/9ed06601603b58d4 Normally I believe the __module__ attribute should be fully qualified regardless of whether the import was absolute or relative. That you're not seeing this suggests that the "relative" import may actually be an absolute import starting from a different sys.path entry. -- http://mail.python.org/mailman/listinfo/python-list
Re: test for list equality
Ahh, I see (on the sort issue), thanks All! Still, any other slicker ways to do this? Just for learning. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to generate "a, b, c, and d"?
On 12/15/11 10:48, Roy Smith wrote: I've got a list, ['a', 'b', 'c', 'd']. I want to generate the string, "a, b, c, and d" (I'll settle for no comma after 'c'). Is there some standard way to do this, handling all the special cases? [] ==> '' ['a'] ==> 'a' ['a', 'b'] ==> 'a and b' ['a', 'b', 'c', 'd'] ==> 'a, b, and c' It seems like the kind of thing django.contrib.humanize would handle, but alas, it doesn't. If you have a list, it's pretty easy as MRAB suggests. For arbitrary iterators, it's a bit more complex. Especially with the odd edge-case of 2 items where there's no comma before the conjunction (where >2 has the comma before the conjunction). If you were willing to forgo the Oxford comma, it would tidy up the code a bit. Sample code below -tkc def gen_list(i, conjunction="and"): i = iter(i) first = i.next() try: prev = i.next() except StopIteration: yield first else: more_than_two = False for item in i: if not more_than_two: yield first yield prev prev = item more_than_two = True if more_than_two: yield "%s %s" % (conjunction, prev) else: yield "%s %s %s" % (first, conjunction, prev) def listify(lst, conjunction="and"): return ', '.join(gen_list(lst, conjunction)) for test, expected in ( ([], ''), (['a'], 'a'), (['a', 'b'], 'a and b'), (['a', 'b', 'c'], 'a, b, and c'), (['a', 'b', 'c', 'd'], 'a, b, c, and d'), ): result = listify(test) print "%r -> %r (got %r) %s" % ( test, expected, result, result == expected and "PASSED" or "FAILED" ) -- http://mail.python.org/mailman/listinfo/python-list
Re: test for list equality
On Thu, Dec 15, 2011 at 9:57 AM, John Gordon wrote: > In <61edc02c-4f86-45ef-82a1-61c701300...@t38g2000yqe.googlegroups.com> > noydb writes: > > > My sort issue... as in this doesn't work > > >>> if x.sort =3D=3D y.sort: > > ... print 'equal' > > ... else: > > ... print 'not equal' > > ... > > not equal > > > ??? > > Use x.sort() instead of x.sort . > And you cannot use the method in-line - it mutates the list in place, returning None. If you either do not wish to mutate the list, or you absolutely want to do the sort in-line, you need to use the sorted built-in: if sorted(x) == sorted(y): ... However, this will, temporary, use double the memory. > > -- > John Gordon A is for Amy, who fell down the stairs > gor...@panix.com B is for Basil, assaulted by bears >-- Edward Gorey, "The Gashlycrumb Tinies" > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: test for list equality
> My sort issue... as in this doesn't work > >>> if x.sort == y.sort: You're missing the () to make it a function call. Also list.sort() returns none, it mutates the original list. You can either sorted(x) == sorted(y) or set(x) == set(y) -- http://mail.python.org/mailman/listinfo/python-list
Re: test for list equality
noydb, 15.12.2011 18:49: On Dec 15, 11:36 am, noydb wrote: I want to test for equality between two lists. For example, if I have two lists that are equal in content but not in order, I want a return of 'equal' -- dont care if they are not in the same order. In order to get that equality, would I have to sort both lists regardless? if yes, how (having issues with list.sort)? Another way i tried, that I think is kind-of roundabout is like x = [2, 5, 1, 88, 9] y = [5, 2, 9, 1, 88] inBoth = list(set(x)& set(y)) and then test that list.count is equal between inBoth and x and/or y. Any better suggestions? Thanks for any help! My sort issue... as in this doesn't work >>> if x.sort == y.sort: ... print 'equal' ... else: ... print 'not equal' ... not equal alist.sort() is a method, so you have to call it in order to execute it. alist.sort will only give you a reference to the method. Comparing that to another method reference returns False, as expected. Also, calling it does not return anything (useful), it modifies the list in place. If you want to create a new list (which you don't want in this case, but anyway), you can use the sorted() builtin function. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: test for list equality
In <61edc02c-4f86-45ef-82a1-61c701300...@t38g2000yqe.googlegroups.com> noydb writes: > My sort issue... as in this doesn't work > >>> if x.sort =3D=3D y.sort: > ... print 'equal' > ... else: > ... print 'not equal' > ... > not equal > ??? Use x.sort() instead of x.sort . -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" -- http://mail.python.org/mailman/listinfo/python-list
Re: test for list equality
On 15/12/2011 16:36, noydb wrote: I want to test for equality between two lists. For example, if I have two lists that are equal in content but not in order, I want a return of 'equal' -- dont care if they are not in the same order. In order to get that equality, would I have to sort both lists regardless? if yes, how (having issues with list.sort)? Another way i tried, that I think is kind-of roundabout is like x = [2, 5, 1, 88, 9] y = [5, 2, 9, 1, 88] inBoth = list(set(x)& set(y)) and then test that list.count is equal between inBoth and x and/or y. Any better suggestions? Thanks for any help! You could count the number of times each item occurs using the Counter class in the collections module: >>> x = [2, 5, 1, 88, 9] >>> y = [5, 2, 9, 1, 88] >>> from collections import Counter >>> cx = Counter(x) >>> cy = Counter(y) >>> cx Counter({88: 1, 1: 1, 2: 1, 5: 1, 9: 1}) >>> cx == cy True -- http://mail.python.org/mailman/listinfo/python-list
Re: test for list equality
On Dec 15, 11:36 am, noydb wrote: > I want to test for equality between two lists. For example, if I have > two lists that are equal in content but not in order, I want a return > of 'equal' -- dont care if they are not in the same order. In order > to get that equality, would I have to sort both lists regardless? if > yes, how (having issues with list.sort)? > > Another way i tried, that I think is kind-of roundabout is like > x = [2, 5, 1, 88, 9] > y = [5, 2, 9, 1, 88] > inBoth = list(set(x) & set(y)) > > and then test that list.count is equal between inBoth and x and/or y. > > Any better suggestions? > > Thanks for any help! My sort issue... as in this doesn't work >>> if x.sort == y.sort: ... print 'equal' ... else: ... print 'not equal' ... not equal ??? -- http://mail.python.org/mailman/listinfo/python-list
test for list equality
I want to test for equality between two lists. For example, if I have two lists that are equal in content but not in order, I want a return of 'equal' -- dont care if they are not in the same order. In order to get that equality, would I have to sort both lists regardless? if yes, how (having issues with list.sort)? Another way i tried, that I think is kind-of roundabout is like x = [2, 5, 1, 88, 9] y = [5, 2, 9, 1, 88] inBoth = list(set(x) & set(y)) and then test that list.count is equal between inBoth and x and/or y. Any better suggestions? Thanks for any help! -- http://mail.python.org/mailman/listinfo/python-list
Re: How to generate "a, b, c, and d"?
On 15/12/2011 16:48, Roy Smith wrote: I've got a list, ['a', 'b', 'c', 'd']. I want to generate the string, "a, b, c, and d" (I'll settle for no comma after 'c'). Is there some standard way to do this, handling all the special cases? [] ==> '' ['a'] ==> 'a' ['a', 'b'] ==> 'a and b' ['a', 'b', 'c', 'd'] ==> 'a, b, and c' It seems like the kind of thing django.contrib.humanize would handle, but alas, it doesn't. How about this: def and_list(items): if len(items) <= 2: return " and ".join(items) return ", ".join(items[ : -1]) + ", and " + items[-1] print(and_list([])) print(and_list(['a'])) print(and_list(['a', 'b'])) print(and_list(['a', 'b', 'c'])) print(and_list(['a', 'b', 'c', 'd'])) -- http://mail.python.org/mailman/listinfo/python-list
Re: Odd behavior of object equality/identity in the context of relative vs fully qualified imports
It would be more work than I want to go into to provide full context (unless it is to file a bug report, if it actually is a bug). I verified that there are no cyclical dependency issues using snakefood, and I doublechecked that just changing the import from full to partial name is sufficient to reintroduce the bug. Can I get confirmation that this is not expected behavior? I will go ahead and file a bug report it that is the case. Nathan On Thu, Dec 15, 2011 at 10:08 AM, Dave Angel wrote: > On 12/15/2011 09:34 AM, Nathan Rice wrote: >> >> I just ran into this yesterday, and I am curious if there is a >> rational behind it... >> >> I have a class that uses a dictionary to dispatch from other classes >> (k) to functions for those classes (v). I recently ran into a bug >> where the dictionary would report that a class which was clearly in >> the dictionary's keys was giving a KeyError. id() produced two >> distinct values, which I found to be curious, and >> issubclass/isinstance tests also failed. When I inspected the two >> classes, I found that the only difference between the two was the >> __module__ variable, which in one case had a name relative to the >> current module (foo), and in another case had the fully qualified name >> (bar.foo). When I went ahead and changed the import statement for the >> module to import bar.foo rather than import foo, everything worked as >> expected. My first thought was that I had another foo module in an >> old version of the bar package somewhere on my pythonpath; After a >> thorough search this proved not to be the case. >> >> Has anyone else run into this? Is this intended behavior? If so, why? >> >> Nathan > > Hard to tell with such generic information. But I'm guessing you imported > your script from some other module, creating a circular import sequence. > The circular can be a problem in its own right. But even worse, if the > script is part of the chain is that it's loaded twice, with different names. > And any top-level items, such as classes, will be instantiated twice as > well. is your script called foo.py by any chance? > > -- > > DaveA > -- http://mail.python.org/mailman/listinfo/python-list
Re: Screen Control Fullscreen ON/OFF
On Dec 15, 4:19 pm, Ulrich Eckhardt wrote: > Am 15.12.2011 12:12, schrieb yeet: > > > My LCD has 2ms respond time thus it can handle a maximum of 50Hz ON/ > > OFF (white/black) thus seems to fit my 1-40Hz range. > > You might want to ask Santa for a new calculator, as in my book a > response time of 2ms would be enough for 250Hz (period = 2 * 2ms). > > Reminds me of a hack that used a special pattern on a CRT to emit DCF77 > signals, reprogramming any suitable radio-controlled clock in range. > What are you trying to do, just out of curiosity? > > (c: > > Uli Yes that's correct, 50Hz limit is the limit of NVIDIA CUDA Linux drivers limit. Screen can go higher rates on sucky windows. I am trying to generate a visual stimulus that will be used for fNIR and EEG captures. On Dec 15, 2:18 pm, Nizamov Shawkat wrote: > > It depends on whether you want sync to vblank or not. If not, that is > > pretty easy - use sleep() or something similar. If you have to use > > sync (screen is always either black or white, never partly black and > > white) then it is much much more difficult. Actually I do not know of > > any way to sync to it. > > But you do not have to sync to vblank anyway. So you can turn on > vblank sync for the videocard and then you will have either completely > black or completely white screen at each single time point, but this > will be delayed in regard to what you set in python. > > Hope this helps, > S.Nizamov It's not easy to do this basing on time, I think doing per frames is a much better option. It's sounded like a very simple task at first but I realize it's not that easy.Maybe I should write the screen blinker in C or Assembly then call it from Python. -- http://mail.python.org/mailman/listinfo/python-list
How to generate "a, b, c, and d"?
I've got a list, ['a', 'b', 'c', 'd']. I want to generate the string, "a, b, c, and d" (I'll settle for no comma after 'c'). Is there some standard way to do this, handling all the special cases? [] ==> '' ['a'] ==> 'a' ['a', 'b'] ==> 'a and b' ['a', 'b', 'c', 'd'] ==> 'a, b, and c' It seems like the kind of thing django.contrib.humanize would handle, but alas, it doesn't. -- http://mail.python.org/mailman/listinfo/python-list
Re: What is this widget? -- again
On Thursday, December 15, 2011 11:53:55 PM UTC+8, Rick Johnson wrote: > On Dec 14, 8:17 pm, Muddy Coder wrote: > > Hi Folks, > > > > Sorry for the unclear question in last post. Well, I am using Tkinter > > to do GUI, and I just don't know what kind of widget can let me do > > annotation on an image being displayed. An example is the Paint of > > Windows: a dotted line box appearing on a image to hold a typed in > > text. I just can't figure out what widget in Tkinter is equivalent to > > that dotted line box. Please help, thanks again! > > > > Cosmo > > No such widget exists in Tkinter. As Dennis said the code must be > written. I can assure you that this functionality can be created with > Tkinter (because i've done it myself) however it requires an in-depth > knowledge of Tkinter -- which apparently you don't have since you are > asking the question. > > Waring: NEVER USE ANY MICROSOFT INTERFACE AS INSPIRATION!!! > > Whist you ponder the intricacies professional of image annotation, i > suggest you follow my advice in your OTHER post (of the same title) > and use the "canvas.create_text" method to draw text on top of images > THEN you need to learn how to move "canvas items" around the canvas > using the mouse THEN you need to intercept right clicks on the text > item and show a dialog with an entry widget stuffed inside so the user > can edit the text THEN update the canvas text from user input. When > solving a problem you need to follow a linear path. The first step in > this path is to draw text on a canvas. > > 1. Draw text to a canvas. > 2. Intercept right click events on a "canvas text". > 3. Build a custom dialog using tkSimpleDialog (or use a floating > "canvas window") to display a Tkinter Entry widget so the user can > edit the current value of the "canvas text". > 4. Fetch the value of Tkinter "canvas text" > 5. Load the value into the entry widget. > 6. Update the value of the canvas text item based on user input > returned from the dialog. > > Extra Credit: > * capture mouse drag events and allow user manipulation of "canvas > text" x-y position. > > http://infohost.nmt.edu/tcc/help/pubs/tkinter/ > http://effbot.org/tkinterbook/ > > ...may the source be with you. Check BOA and wxpython and work out the examples. It is kind of boring and not too easy to be accustomed to use. A simpler set of the toolkit pygame and pyimg to explore is another way to advance. Study the source of pyimg is very helpful. -- http://mail.python.org/mailman/listinfo/python-list
Ann: OpenOpt and FuncDesigner 0.37
Hi all, I'm glad to inform you about new release 0.37 (2011-Dec-15) of our free software: OpenOpt (numerical optimization): IPOPT initialization time gap (time till first iteration) for FuncDesigner models has been decreased Some improvements and bugfixes for interalg, especially for "search all SNLE solutions" mode (Systems of Non Linear Equations) Eigenvalue problems (EIG) (in both OpenOpt and FuncDesigner) Equality constraints for GLP (global) solver de Some changes for goldenSection ftol stop criterion GUI func "manage" - now button "Enough" works in Python3, but "Run/ Pause" not yet (probably something with threading and it will be fixed in Python instead) FuncDesigner: Major sparse Automatic differentiation improvements for badly- vectorized or unvectorized problems with lots of constraints (except of box bounds); some problems now work many times or orders faster (of course not faster than vectorized problems with insufficient number of variable arrays). It is recommended to retest your large-scale problems with useSparse = 'auto' | True| False Two new methods for splines to check their quality: plot and residual Solving ODE dy/dt = f(t) with specifiable accuracy by interalg Speedup for solving 1-dimensional IP by interalg SpaceFuncs and DerApproximator: Some code cleanup You may trace OpenOpt development information in our recently created entries in Twitter and Facebook, see http://openopt.org for details. For more information visit http://openopt.org Regards, D. -- http://mail.python.org/mailman/listinfo/python-list
Can't get Apache2 tp process py (Ubuntu 11.10)
Hello, Sorry if this is not exactly appropriate forum where to ask Apache question, but I though't here would some Apache-experienced people probably hang out. Well, I can't get my Apache2 to process Python *.py files. I checked numerous tutorials how to enable it, and did the install steps: - Installed the libapache2-mod-python package - Added the following lines to the section of /etc/apache2/sites-available/default file: AddHandler mod_python .py PythonHandler mod_python.publisher PythonDebug On I made this simple test.py file: def index(req): return "Test successful"; When I request the file, ie, [url]http://localhost/test.py[/url], I get the download prompt, and the Python script is just downloaded, not processed. The error log /var/log/apache2 shows these lines that kind of confirm that the module is loaded: [Thu Dec 15 15:12:38 2011] [notice] mod_python: Creating 8 session mutexes based on 150 max processes and 0 max threads. [Thu Dec 15 15:12:38 2011] [notice] mod_python: using mutex_directory /tmp [Thu Dec 15 15:12:38 2011] [notice] Apache/2.2.20 (Ubuntu) PHP/5.3.6-13ubuntu3.3 with Suhosin-Patch mod_python/3.3.1 Python/2.7.2+ configured -- resuming normal operations As one can see, there are no any errors that would tell there's something wrong happening. Any ideas what installation step did I do wrong or skipped? -- http://mail.python.org/mailman/listinfo/python-list
Re: What is this widget? -- again
On Dec 14, 8:17 pm, Muddy Coder wrote: > Hi Folks, > > Sorry for the unclear question in last post. Well, I am using Tkinter > to do GUI, and I just don't know what kind of widget can let me do > annotation on an image being displayed. An example is the Paint of > Windows: a dotted line box appearing on a image to hold a typed in > text. I just can't figure out what widget in Tkinter is equivalent to > that dotted line box. Please help, thanks again! > > Cosmo No such widget exists in Tkinter. As Dennis said the code must be written. I can assure you that this functionality can be created with Tkinter (because i've done it myself) however it requires an in-depth knowledge of Tkinter -- which apparently you don't have since you are asking the question. Waring: NEVER USE ANY MICROSOFT INTERFACE AS INSPIRATION!!! Whist you ponder the intricacies professional of image annotation, i suggest you follow my advice in your OTHER post (of the same title) and use the "canvas.create_text" method to draw text on top of images THEN you need to learn how to move "canvas items" around the canvas using the mouse THEN you need to intercept right clicks on the text item and show a dialog with an entry widget stuffed inside so the user can edit the text THEN update the canvas text from user input. When solving a problem you need to follow a linear path. The first step in this path is to draw text on a canvas. 1. Draw text to a canvas. 2. Intercept right click events on a "canvas text". 3. Build a custom dialog using tkSimpleDialog (or use a floating "canvas window") to display a Tkinter Entry widget so the user can edit the current value of the "canvas text". 4. Fetch the value of Tkinter "canvas text" 5. Load the value into the entry widget. 6. Update the value of the canvas text item based on user input returned from the dialog. Extra Credit: * capture mouse drag events and allow user manipulation of "canvas text" x-y position. http://infohost.nmt.edu/tcc/help/pubs/tkinter/ http://effbot.org/tkinterbook/ ...may the source be with you. -- http://mail.python.org/mailman/listinfo/python-list
Re: What is this widget?
On Dec 14, 12:47 pm, Muddy Coder wrote: > Hi Folks, > > I am trying to write letters on a photo that is opened in a canvas. So > I think I must need a widget to contain the letters I will type in. I > tried to use a Label, it worked. But, a Label covered part of the > photo underneath, so I can't use it. I saw some software did such a > thing nicely: a box popped on a photo, with dotted lines as borders, > expandable. When such a box was re-sized with a mouse, the font size > in the box also got changed. The box has no background color, so it > does not cover a rectangle area on the photo. I need such a widget, > but I don't know what is this one. I tried Text, Label, but they all > come with Window-like stuff, so they cover some photo content. Can > somebody points me a direction? Thanks! Listen Muddy, this is not first time that you've come here seeking advice with a cryptic and ambiguous post. People have been very patient and even asked you to be more explicit with your questions. I highly advise you to re-write your original post and include which GUI library you are using and any other pertinent info. My guess is that you are using Tkinter. If so, i believe the canvas has a method called "create_text" which will do what you want. To make the input easier to code, use a Tkinter Entry widget stuffed into a dialog -- tkSimpleDialog makes this, well, simple. PS: Clean up you act Muddy! -- http://mail.python.org/mailman/listinfo/python-list
Re: Screen Control Fullscreen ON/OFF
Am 15.12.2011 12:12, schrieb yeet: My LCD has 2ms respond time thus it can handle a maximum of 50Hz ON/ OFF (white/black) thus seems to fit my 1-40Hz range. You might want to ask Santa for a new calculator, as in my book a response time of 2ms would be enough for 250Hz (period = 2 * 2ms). Reminds me of a hack that used a special pattern on a CRT to emit DCF77 signals, reprogramming any suitable radio-controlled clock in range. What are you trying to do, just out of curiosity? (c: Uli -- http://mail.python.org/mailman/listinfo/python-list
Re: Odd behavior of object equality/identity in the context of relative vs fully qualified imports
On 12/15/2011 09:34 AM, Nathan Rice wrote: I just ran into this yesterday, and I am curious if there is a rational behind it... I have a class that uses a dictionary to dispatch from other classes (k) to functions for those classes (v). I recently ran into a bug where the dictionary would report that a class which was clearly in the dictionary's keys was giving a KeyError. id() produced two distinct values, which I found to be curious, and issubclass/isinstance tests also failed. When I inspected the two classes, I found that the only difference between the two was the __module__ variable, which in one case had a name relative to the current module (foo), and in another case had the fully qualified name (bar.foo). When I went ahead and changed the import statement for the module to import bar.foo rather than import foo, everything worked as expected. My first thought was that I had another foo module in an old version of the bar package somewhere on my pythonpath; After a thorough search this proved not to be the case. Has anyone else run into this? Is this intended behavior? If so, why? Nathan Hard to tell with such generic information. But I'm guessing you imported your script from some other module, creating a circular import sequence. The circular can be a problem in its own right. But even worse, if the script is part of the chain is that it's loaded twice, with different names. And any top-level items, such as classes, will be instantiated twice as well. is your script called foo.py by any chance? -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Screen Control Fullscreen ON/OFF
On Thursday, December 15, 2011 6:59:04 PM UTC+8, yeet wrote: > Hi all, > > I would like to make fullscreen white and fullscreen black using > Python on Linux. With in the specs of the LCD, I want to be able to > display fullscreen white and black approximately at 30Hz. Frequency > (on/off per second) will be input manually which is between 1-40Hz. > Any idea where to start ? Can Python perform such fast thing ? Check pygame, pyimg and sdllib and wxpython. Python is a high level language that was not bound to hardware. One of the major strengths of Python is very easy to be supported by programs in other languages, especially in C, Pascal and Fortran. Also programs in Python are easy to debug and maintain. -- http://mail.python.org/mailman/listinfo/python-list
Re: ERP with Supply chain management (incl. POS) and Customer relationship management — What's available?
On Thu, Dec 15, 2011 at 5:54 AM, Anurag Chourasia wrote: > Hi Alec, > > I am building a POS/CRM (Loyalty Management) system as well. > > So far, the best I could find to use as a base is this one > > https://github.com/rosarior/django-inventory > > In any case, I felt that even starting from scratch is not a bad > idea.Please let me know if you get more pointers. We can even work on > this one together. > > Regards, > Anurag > Thanks Anurag, I will look into it, however I'm thinking of writing my whole project as extensions to satchmo. (modularised though, so you'd be able to enable only a few features, and even disable ecommerce) Would be great to have you on board (if you're still interested, contact me off-list) -- http://mail.python.org/mailman/listinfo/python-list
Odd behavior of object equality/identity in the context of relative vs fully qualified imports
I just ran into this yesterday, and I am curious if there is a rational behind it... I have a class that uses a dictionary to dispatch from other classes (k) to functions for those classes (v). I recently ran into a bug where the dictionary would report that a class which was clearly in the dictionary's keys was giving a KeyError. id() produced two distinct values, which I found to be curious, and issubclass/isinstance tests also failed. When I inspected the two classes, I found that the only difference between the two was the __module__ variable, which in one case had a name relative to the current module (foo), and in another case had the fully qualified name (bar.foo). When I went ahead and changed the import statement for the module to import bar.foo rather than import foo, everything worked as expected. My first thought was that I had another foo module in an old version of the bar package somewhere on my pythonpath; After a thorough search this proved not to be the case. Has anyone else run into this? Is this intended behavior? If so, why? Nathan -- http://mail.python.org/mailman/listinfo/python-list
Re: AttributeError in "with" statement (3.2.2)
On Dec 14, 9:01 pm, Steven D'Aprano wrote: > [...] > So what are methods? In Python, methods are wrappers around functions > which automatically pass the instance to the inner function object. Under > normal circumstances, you create methods by declaring functions inside a > class, but that's not the only way to create methods, and it is not the > only place they can be found. > I've always understood methods as basically function wrappers that pass in the instance, so it's good to hear somebody else formulate it that way. For the special methods like __enter__ and __exit__, the tricky part isn't understanding what would happen once the methods were called; the tricky part is getting them to be called in the first place, if they were not declared inside the class or attached to the class. import types class Blank: pass foo = Blank() foo.name = "foo1" foo.__exit__ = types.MethodType(lambda self, *args: print(self.name), foo) foo.__exit__() # works like a method in python3, prints foo1 with foo: pass -- http://mail.python.org/mailman/listinfo/python-list
Re: % is not an operator [was Re: Verbose and flexible args and kwargs syntax]
rusi writes: > On Dec 15, 3:58 pm, Chris Angelico wrote: > > On Thu, Dec 15, 2011 at 9:47 PM, Robert Kern wrote: > > > 42 = 2 mod 5 > > > 2 = 42 mod 5 > > > > It might make more sense to programmers if you think of it as > > written: > > > > 42 = 2, mod 5 > > 2 = 42, mod 5 > > > > ChrisA > > For the record I should say that the guy who taught me abstract > algebra, said about as much: > He said that the notation > a == b mod n > should be written as > a ==n b > (read the == as 3 horizontal lines and the n as a subscript) I think the modulus is usually given in parentheses and preferably some whitespace: in text, a == b (mod n), using == for the triple -, and in a display: a == b(mod n). I think even a == b == c (mod n), without repeating the modulus every time. (A subscript sounds good if the modulus is simple. Perhaps it often is.) That way it does not even look like a binary operator. I think Graham, Knuth, and Patashnik play it nicely in their book Concrete Mathematics, where they have both mods: the congruence relation, and the binary operator. The book is targeted for computer scientists. As if mathematicians didn't use the exact same notations for different purposes, even in the same context, and often with no problems whatsoever as long as all parties happen to know what they are talking about. Often the uses are analogous, but at least the two main uses of (x,y) differ wildly. (So Knuth uses (x .. y) for the interval, but he is a programmer.) -- http://mail.python.org/mailman/listinfo/python-list
Re: Screen Control Fullscreen ON/OFF
> It depends on whether you want sync to vblank or not. If not, that is > pretty easy - use sleep() or something similar. If you have to use > sync (screen is always either black or white, never partly black and > white) then it is much much more difficult. Actually I do not know of > any way to sync to it. But you do not have to sync to vblank anyway. So you can turn on vblank sync for the videocard and then you will have either completely black or completely white screen at each single time point, but this will be delayed in regard to what you set in python. Hope this helps, S.Nizamov -- http://mail.python.org/mailman/listinfo/python-list
Re: % is not an operator [was Re: Verbose and flexible args and kwargs syntax]
On Dec 15, 11:56 am, rusi wrote: > On Dec 15, 2:44 pm, Eelco wrote: > > > In other words, what logic needs is a better exception-handling > > system, which completes the circle with programming languages quite > > nicely. :) > > Cute... but dangerously recursive (if taken literally) > Remember that logic is the foundation of programming language > semantics. > And your idea (suggests) that programming language semantics be made > (part of) the foundation of logic. > > Of course I assume you are not being very literal. > Still the dangers of unnoticed circularity are often... well > unnoticed :-) Well, logic as a language has semantics, one way or the other. This circularity is a general theme in epistemology, and one that fits well with the view of deduction-induction as a closed loop cycle. Knowledge does not flow from axioms to theorems; axioms without an encompassing context are meaningless symbols. Its a body of knowledge as a whole that should be put to the test; the language and the things we express in it are inseperable. (the not-quite-famous-enough Quine in a nutshell) The thing is that our semantics of logic are quite primitive; cooked up in a time where people spent far less time thinking about these things, and having a far narrower base of experience to draw ideas from. They didnt have the luxury of already having grown up studying a dozen formal languages before embarking on creating their own. It other words, the semantics of logic is a legacy piece of crap, but an insanely firmly entrenched one. I mean, there are many sensible ways of defining semantics of conflicting symbols, but you'll find on studying these things that the guys who (often implicitly) laid down these rules didnt even seemed to have consciously thought about them. Not because they were stupid; far from it, but for similar reasons as to why the x86 architecture wasnt concieved of the day after the invention of the transistor. -- http://mail.python.org/mailman/listinfo/python-list
Re: Screen Control Fullscreen ON/OFF
>> >> I would like to make fullscreen white and fullscreen black using >> Python on Linux. With in the specs of the LCD, I want to be able to >> display fullscreen white and black approximately at 30Hz. Frequency >> (on/off per second) will be input manually which is between 1-40Hz. >> Any idea where to start ? Can Python perform such fast thing ? > > Forgot to mention and sorry for the pollution ; > > My LCD has 2ms respond time thus it can handle a maximum of 50Hz ON/ > OFF (white/black) thus seems to fit my 1-40Hz range. I am not asking > or looking for a fully working code, I just need some directions. It depends on whether you want sync to vblank or not. If not, that is pretty easy - use sleep() or something similar. If you have to use sync (screen is always either black or white, never partly black and white) then it is much much more difficult. Actually I do not know of any way to sync to it. Once upon a time I had a P-3/500 linux box with homemade python program that would wait for RTC interrupts (which was set to 8192 Hz frequency) and performed different combinations of ADC/DAC/Digital-IO at required timesteps . It worked really very well and with submillisecond resolution. Hope it helps, S.Nizamov -- http://mail.python.org/mailman/listinfo/python-list
Re: Screen Control Fullscreen ON/OFF
On Dec 15, 12:59 pm, yeet wrote: > Hi all, > > I would like to make fullscreen white and fullscreen black using > Python on Linux. With in the specs of the LCD, I want to be able to > display fullscreen white and black approximately at 30Hz. Frequency > (on/off per second) will be input manually which is between 1-40Hz. > Any idea where to start ? Can Python perform such fast thing ? Forgot to mention and sorry for the pollution ; My LCD has 2ms respond time thus it can handle a maximum of 50Hz ON/ OFF (white/black) thus seems to fit my 1-40Hz range. I am not asking or looking for a fully working code, I just need some directions. -- http://mail.python.org/mailman/listinfo/python-list
Re: % is not an operator [was Re: Verbose and flexible args and kwargs syntax]
On Dec 15, 11:47 am, Robert Kern wrote: > On 12/14/11 12:32 PM, Steven D'Aprano wrote: > > > On Wed, 14 Dec 2011 10:56:02 +0200, Jussi Piitulainen wrote: > >> I'm not misunderstanding any argument. There was no argument. There was > >> a blanket pronouncement that _in mathematics_ mod is not a binary > >> operator. I should learn to challenge such pronouncements and ask what > >> the problem is. Maybe next time. > > > So this was *one* person making that claim? > > > I understand that, in general, mathematicians don't have much need for a > > remainder function in the same way programmers do -- modulo arithmetic is > > far more important. But there's a world of difference between saying "In > > mathematics, extracting the remainder is not important enough to be given > > a special symbol and treated as an operator" and saying "remainder is not > > a binary operator". The first is reasonable; the second is not. > > The professional mathematicians that I know personally don't say that > "remainder > is not a binary operator". They *do* say that "modulo is not an operator" in > mathematics just because they have reserved that word and the corresponding > notation to define the congruence relations. So for example, the following two > statements are equivalent: > > 42 = 2 mod 5 > 2 = 42 mod 5 > > The "mod 5" notation modifies the entire equation (or perhaps the = sign if > you > like to think about it like that), not the term it is immediately next to. > Python's % operator is a binary operator that binds to a particular term, not > the whole equation. The following two are not equivalent statements: > > 42 == 2 % 5 > 2 == 42 % 5 > > It's mostly kvetching on their part that programming language designers > misunderstood the notation and applied the name to something that is > confusingly > almost, but not quite, the same thing. They aren't saying that you couldn't > *define* such an operator; they would just prefer that we didn't abuse the > name. > But really, it's their fault for using notation that looks like an operator. > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco Thanks Robert, I think you cut right through the confusion there. To tie it back in with python language design; all the more reason not to opt for pseudo-backwards compatibility. If python wants a remainder function, call it 'remainder'. Not 'rem', not 'mod', and certainly not '%'. Its the more pythonic way; a self-describing name, rather than poorly defined or poorly understood cryptology. -- http://mail.python.org/mailman/listinfo/python-list
Screen Control Fullscreen ON/OFF
Hi all, I would like to make fullscreen white and fullscreen black using Python on Linux. With in the specs of the LCD, I want to be able to display fullscreen white and black approximately at 30Hz. Frequency (on/off per second) will be input manually which is between 1-40Hz. Any idea where to start ? Can Python perform such fast thing ? -- http://mail.python.org/mailman/listinfo/python-list
Re: % is not an operator [was Re: Verbose and flexible args and kwargs syntax]
On Dec 15, 3:58 pm, Chris Angelico wrote: > On Thu, Dec 15, 2011 at 9:47 PM, Robert Kern wrote: > > 42 = 2 mod 5 > > 2 = 42 mod 5 > > It might make more sense to programmers if you think of it as written: > > 42 = 2, mod 5 > 2 = 42, mod 5 > > ChrisA For the record I should say that the guy who taught me abstract algebra, said about as much: He said that the notation a == b mod n should be written as a ==n b (read the == as 3 horizontal lines and the n as a subscript) -- http://mail.python.org/mailman/listinfo/python-list
Re: % is not an operator [was Re: Verbose and flexible args and kwargs syntax]
On Dec 15, 2:44 pm, Eelco wrote: > In other words, what logic needs is a better exception-handling > system, which completes the circle with programming languages quite > nicely. :) Cute... but dangerously recursive (if taken literally) Remember that logic is the foundation of programming language semantics. And your idea (suggests) that programming language semantics be made (part of) the foundation of logic. Of course I assume you are not being very literal. Still the dangers of unnoticed circularity are often... well unnoticed :-) eg. McCarthy gave the semantics of lisp in lisp -- a lisp interpreter in lisp is about a page of code. It probably was a decade before someone realized that the same semantics would 'work' for lazy or applicative (eager) order evaluation. This then begs the question what exactly it means for that semantics to 'work'... -- http://mail.python.org/mailman/listinfo/python-list
Re: % is not an operator [was Re: Verbose and flexible args and kwargs syntax]
On Thu, Dec 15, 2011 at 9:47 PM, Robert Kern wrote: > 42 = 2 mod 5 > 2 = 42 mod 5 It might make more sense to programmers if you think of it as written: 42 = 2, mod 5 2 = 42, mod 5 ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: % is not an operator [was Re: Verbose and flexible args and kwargs syntax]
On 12/14/11 12:32 PM, Steven D'Aprano wrote: On Wed, 14 Dec 2011 10:56:02 +0200, Jussi Piitulainen wrote: I'm not misunderstanding any argument. There was no argument. There was a blanket pronouncement that _in mathematics_ mod is not a binary operator. I should learn to challenge such pronouncements and ask what the problem is. Maybe next time. So this was *one* person making that claim? I understand that, in general, mathematicians don't have much need for a remainder function in the same way programmers do -- modulo arithmetic is far more important. But there's a world of difference between saying "In mathematics, extracting the remainder is not important enough to be given a special symbol and treated as an operator" and saying "remainder is not a binary operator". The first is reasonable; the second is not. The professional mathematicians that I know personally don't say that "remainder is not a binary operator". They *do* say that "modulo is not an operator" in mathematics just because they have reserved that word and the corresponding notation to define the congruence relations. So for example, the following two statements are equivalent: 42 = 2 mod 5 2 = 42 mod 5 The "mod 5" notation modifies the entire equation (or perhaps the = sign if you like to think about it like that), not the term it is immediately next to. Python's % operator is a binary operator that binds to a particular term, not the whole equation. The following two are not equivalent statements: 42 == 2 % 5 2 == 42 % 5 It's mostly kvetching on their part that programming language designers misunderstood the notation and applied the name to something that is confusingly almost, but not quite, the same thing. They aren't saying that you couldn't *define* such an operator; they would just prefer that we didn't abuse the name. But really, it's their fault for using notation that looks like an operator. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: % is not an operator [was Re: Verbose and flexible args and kwargs syntax]
On Dec 15, 4:43 am, rusi wrote: > On Dec 14, 10:15 pm, Eelco wrote: > > > 'Kindof' off-topic, but what the hell :). > > > We keep having these debates -- so I wonder how off-topic it is... > And so do famous > CSists:http://research.microsoft.com/en-us/um/people/gurevich/opera/123.pdf > Well, you are right, there are some deep links here. My view of what is wrong with mainstream mathematics is its strange interpretation of the semantics of classical logic. (And I dont think any other schools get it quite right either; I think finitists may avoid the mistakes of others, but are rightfully accussed of being needlessly restrictive, for instance) This is best illustrated by means of the principle of explosion. It rests on assuming a contradiction, and then assigning rather peculiar semantics to them. What is typically left unstated are the semantics of symbol lookup, but apparently it is implicitly understood one can pick whatever value upon encountering a contradicting symbol. There is no well defined rule for the lookup of a twice-defined symbol. Of course the sane thing to do, to a mind grown up around computer languages, upon encountering a twice defined symbol, is not to continue to generate deductions from both branches, but to throw an exception and interrupt the specific line of reasoning that depends on this contradicting symbol right then and there. Conceptually, we can see something is wrong with these undefined semantics right away. A logical system that allows you to draw conclusions as to where the pope shits from assertions about natural numbers could not more obviously be broken. If you dont have this broken way of dealing with contradictions, one does not have to do one of many silly and arbitrary things to make infinity work, such as making a choice between one-to-one correspondence and subset-relations for determining the cardinality of a set; one can simply admit the concept of infinity, while useful, is not consistent, keep the contradiction well handled instead of having it explode in your face (or explode into the field of transfinite analysis; a consequece of 'dealing' with these issues by rejecting the intuitively obviously true relation between subset relations and cardinality), and continue reasoning with the branches of your argument that you are interested in. In other words, what logic needs is a better exception-handling system, which completes the circle with programming languages quite nicely. :) -- http://mail.python.org/mailman/listinfo/python-list
combuter is use full message
http;//123maza.com/48/moon670/ -- http://mail.python.org/mailman/listinfo/python-list