Re: Implicit conversion to boolean in if and while statements
On Mon, 16 Jul 2012 11:13:33 -0700, Ethan Furman wrote: Steven D'Aprano wrote: On Sun, 15 Jul 2012 10:19:16 -0600, Ian Kelly wrote: On Sun, Jul 15, 2012 at 4:56 AM, Steven D'Aprano wrote: (For the record, I can only think of one trap for the unwary: time objects are false at *exactly* midnight.) Ugh, that's irritating. I can't think of any scenario where I would ever want the semantics if timeval (is not midnight):. Yes, it is a genuine gotcha. Time values are numbers, and zero is falsey, so midnight is falsey even though it shouldn't be. There's no good solution here, since we have a conflict between treating time values as time values (midnight is nothing special) and as numbers (midnight == 0 which is falsey). -- import datetime -- mn = datetime.time(0) -- mn datetime.time(0, 0) -- mn == 0 False Apparently, midnight does not equal zero. My mistake. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Implicit conversion to boolean in if and while statements
On Tue, 17 Jul 2012 00:18:28 -0400, Devin Jeanpierre wrote: On Mon, Jul 16, 2012 at 12:03 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sun, 15 Jul 2012 22:15:13 -0400, Devin Jeanpierre wrote: For example, instead of if stack: or if bool(stack):, we could use if stack.isempty():. This line tells us explicitly that stack is a container. isempty is not a container method. Your entire reply is predicated on this idea that I was talking about writing classes with this extra isempty method. No. I was talking about having isempty be part of the collection interface, and eliminating polymorphic bool conversion. It already is part of the collection interface: it is spelled __nonzero__ (Python 2) or __bool__ (Python 3), and like all dunder methods, it is called automatically for you when you use the right syntax: # do this x = n - len(y) if x and y: ... # don't do this x = n.__sub__(y.__len__()) if x.__nonzero__() and y.__nonzero__(): ... -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Implicit conversion to boolean in if and while statements
On Tue, 17 Jul 2012 00:19:48 -0500, Andrew Berg wrote: To put it in duck-typing terms, why should everything have to quack like True or False? Sure, I can see why 1 quacks like True or [] quacks like False, but I don't see why say, a Logger or function should quack like either. The default behaviour is that every object is something, hence true-like, unless explicitly coded to be treated as false-like. Since both loggers and functions are objects, they are true-like unless the default is overridden. If you don't like that simple, consistent model for truthiness, feel free to design your own language with a different model. Or you can use any one of the dozens of other existing languages which do what you want. Should a Thread object be True if it's been started and False otherwise? If you, the Thread class author, want it to be, you can make it so. If it truly is about something vs. nothing, why is a NameError (or AttributeError) raised when testing with an undefined variable? Being undefined quacks like nothing, doesn't it? Not really. It doesn't quack like anything. Are you suggesting that if x doesn't exist, you want this behaviour? del x # make sure x doesn't exist if x: print('cheese') ... else: ... print('x is falsy') ... print(x) ... x is falsy Traceback (most recent call last): File stdin, line 1, in module NameError: name 'x' is not defined OH MAN, that would be SO AWESOME, we should like so do it!!! (I'm being sarcastic, in case it's not obvious.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Implicit conversion to boolean in if and while statements
On 7/15/2012 1:34 AM, Andrew Berg wrote: This has probably been discussed before, but why is there an implicit conversion to a boolean in if and while statements? if not None: print('hi') prints 'hi' since bool(None) is False. If this was discussed in a PEP, I would like a link to it. There are so many PEPs, and I wouldn't know which ones to look through. Converting 0 and 1 to False and True seems reasonable, but I don't see the point in converting other arbitrary values. Because Boolean types were an afterthought in Python. See PEP 285. If a language starts out with a Boolean type, it tends towards Pascal/Ada/Java semantics in this area. If a language backs into needing a Boolean type, as Python and C did, it tends to have the somewhat weird semantics of a language which can't quite decide what's a Boolean. C and C++ have the same problem, for exactly the same reason - boolean types were an afterthought there, too. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: No more Python support in NetBeans 7.0
On Thursday, March 24, 2011 7:32:44 AM UTC-7, Kees Bakker wrote: Sad news (for me, at least), in the upcoming version 7.0 of NetBeans there will be no Python plugin anymore. FWIW on the Windows platform the Zeus IDE has support for python: http://www.zeusedit.com/python.html Zeus is a lightweight IDE but it does have limited Python debugger support: http://youtu.be/aXNep2fcSsk Jussi Jumppanen Author: Zeus Editor -- http://mail.python.org/mailman/listinfo/python-list
Re: PyXML 0.8.2 is released
在 2003年1月26日星期日UTC+8下午10时01分02秒,quot;Martin v. Löwisquot;写道: Tim C wrote: gt; I#39;ve been trying pyxml from jython and fell into the problem when trying to gt; create executables that pyxml#39;s mechanisms for importing modules confound gt; the compiler. What do you mean by quot;executablequot;, and which compiler are you talking about? How was it confound? Regards, Martin Hi ,I just read your talks,I have a small question which needs your help. I am doing one project by Jython and want to use PyXML,but I am not sure if I can use the PyXML in Jython ,because it seems the PyXML is not supported by Jython ,is that right? Is there other way to resolve this? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Implicit conversion to boolean in if and while statements
On 7/17/2012 2:08 AM, Steven D'Aprano wrote: The default behaviour is that every object is something, hence true-like, unless explicitly coded to be treated as false-like. Since both loggers and functions are objects, they are true-like unless the default is overridden. I am aware of the default behavior, but the reason for it still eludes me. Are you suggesting that if x doesn't exist, you want this behaviour? I don't want that, but I am suggesting that it would be consistent with the idea of something or nothing. -- CPython 3.3.0b1 | Windows NT 6.1.7601.17803 -- http://mail.python.org/mailman/listinfo/python-list
Re: Simulation Results Managment
On Sunday, July 15, 2012 6:20:34 PM UTC+2, rusi wrote: On Jul 15, 11:35 am, Dieter Maurer lt;die...@handshake.degt; wrote: gt; moo...@yahoo.co.uk writes: gt; gt; ... gt; gt; Does pickle have any advantages over json/yaml? gt; gt; It can store and retrieve almost any Python object with almost no effort. gt; gt; Up to you whether you see it as an advantage to be able to store gt; objects rather than (almost) pure data with a rather limited type set. gt; gt; Of course, quot;picklequot; is a proprietary Python format. Not so easy to gt; decode it with something else than Python. In addition, when gt; you store objects, the retrieving application must know the classes gt; of those objects -- and its knowledge should not be too different gt; from how those classes looked when the objects have been stored. gt; gt; I like very much to work with objects (rather than with pure data). gt; Therefore, I use quot;picklequot; when I know that the storing and retrieving gt; applications all use Python. I use pure (and restricted) data formats gt; when non Python applications come into play. Pickle -gt; JSON -gt; Yaml are roughly in increasing order of human-friendliness and decreasing order of machine friendliness (where machine means python #39;machine#39;) This means that - Pickle is most efficient, Yaml least - Pickle comes with python from as far back as I know Json started coming somewhere round 2.5 (I think) (py)yaml needs to be installed separately - reading pickled data will spoil your eyes whereas yaml is pleasant to read (just like python) Hi Everyone, Thanks for the feedback. For now, I store the data using Pickle. Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Implicit conversion to boolean in if and while statements
On Tue, Jul 17, 2012 at 6:23 PM, Andrew Berg bahamutzero8...@gmail.com wrote: On 7/17/2012 2:08 AM, Steven D'Aprano wrote: The default behaviour is that every object is something, hence true-like, unless explicitly coded to be treated as false-like. Since both loggers and functions are objects, they are true-like unless the default is overridden. I am aware of the default behavior, but the reason for it still eludes me. There has to be something. This way, you can use None in place of any object, in the same way that a null pointer would be used in C; any object is true, None isn't. What other default makes more sense? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: jython lacks working xml processing modules?
在 2003年11月24日星期一UTC+8下午7时42分31秒,Paul Boddie写道: janeaustin...@hotmail.com (Jane Austine) wrote in message news:lt;ba1e306f.0311201805.9df...@posting.google.comgt;... gt; I#39;m trying to parse an xml file with jython (not through java parsers gt; like xerces). gt; gt; I tried minidom in jython 2.1 and 2.2a but all failed. gt; gt; What can I do? The last resort would be using java parsers. Then how gt; can I use them like python xml parsers? It seems like javadom and gt; javasax has something to do, but I don#39;t know how. The Java parsers seem to work quite well with the xml.dom.javadom package. First, update your CLASSPATH with references to the necessary .jar files - this can be a frustrating process, but I found that xercesImpl-2.5.0.jar and xml-apis.jar were a good combination: export CLASSPATH=.../xercesImpl-2.5.0.jar:.../xml-apis.jar Then, start jython and try the following: import xml.dom.javadom impl = xml.dom.javadom.XercesDomImplementation() # Use your own filename below! doc = impl.buildDocumentFile(quot;example.xmlquot;) # Now, try some PyXML-style DOM properties and methods. doc.childNodes doc.childNodes[0].getAttribute(quot;some-attrquot;) I#39;d seen javadom lurking in PyXML before now, but it#39;s a nice surprise to see that it works rather well, especially since I#39;ve never seen any evidence of anyone using it (as far as I remember). Paul hi,do you know the PyXML whether can be supported by Jython ? Looking forward to your reply! Thanks -- http://mail.python.org/mailman/listinfo/python-list
Encapsulation, inheritance and polymorphism
Pythoners Python 2.7.3 Ubuntu Linux 12.04 LTS I've been taking a brief look at Python. From the tutorial documentation I get the following 'Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming'. I was expecting (hoping) to see in depth documentation relating to Class construction, extension mechanisms and runtime polymorphism. What I actually get is a confusion of Classes, modules, scripts and whatever else. Is Python truly OO or is it just one way to use the language. I see some documentation relating to classes but nothing on instantiation .. in fact the documentation appears to say that classes are used in a static way e.g ClassName.method(), and command line scripting is really outside the scope of other OO languages I have experienced. Is there a previous discussion in the group that I could read. Many thanks Lipska -- Lipska the Kat: Troll hunter, Sandbox destroyer and Farscape dreamer. -- http://mail.python.org/mailman/listinfo/python-list
OpenHatch - Chicago Python Workshop
Hi, I'm not sure if it's ok to post regarding a small local workshop (based on Railsbridge and the Boston Python Workshop) here so please direct me elsewhere if I am mistaken: OpenHatch's first Chicago Python workshop is heading our way, on August 17th - 18th. These events are tailored for women and their friends who have none or limited programming experience. They are also welcoming and respectful of trans women. Men are welcome as guests of women who are attending (please RSVP as well). Register here: http://www.meetup.com/Chicago-Python-Workshop/events/72904002/ More information: https://openhatch.org/wiki/Chicago_Python_Workshop_1 Super cool video on OpenHatch, their motivation, results: http://pyvideo.org/video/719/diversity-in-practice-how-the-boston-python-user We'd like more exposure in local women groups (ladies of all ages are welcome) and if you think we missed out on any other channels, please let us know, or pass this on. Also if anyone is interested in helping or would like to give some input, please join the cpw list (http://lists.openhatch.org/mailman/listinfo/cpw-staff) Thanks! -Aisha -- http://mail.python.org/mailman/listinfo/python-list
Re: assertraises behaviour
2012/7/16 Peter Otten __pete...@web.de: No, I don't see how the code you gave above can fail with an OSError. Can you give an example that produces the desired behaviour with nose? Maybe we can help you translate it to basic unittest. -- http://mail.python.org/mailman/listinfo/python-list Well this is what I meant: import unittest class TestWithRaises(unittest.TestCase): def test_first(self): assert False def test_second(self): print(also called) assert True if __name__ == '__main__': unittest.main() in this case also the second test is run even if the first fails.. But that's probably easy because we just need to catch exceptions for every method call, so it's not exactly the same thing.. -- http://mail.python.org/mailman/listinfo/python-list
Re: jython lacks working xml processing modules?
gaodexiaozh...@gmail.com, 17.07.2012 10:35: hi,do you know the PyXML whether can be supported by Jython ? PyXML is a dead project, don't use it. You can use ElementTree in Jython, just as in Python. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Implicit conversion to boolean in if and while statements
On Tue, Jul 17, 2012 at 2:25 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: It already is part of the collection interface: it is spelled __nonzero__ (Python 2) or __bool__ (Python 3), and like all dunder methods, it is called automatically for you when you use the right syntax: You're still ignoring what I actually said. -- Devin -- http://mail.python.org/mailman/listinfo/python-list
Re: PyQt QCalendarWidget events question
John Posner jjpos...@optimum.net wrote: On 7/16/2012 12:28 PM, tinn...@isbd.co.uk wrote: tinn...@isbd.co.uk wrote: I am trying to use the PyQt4 calendar widget to perform some different actions on specific dates. There are three events available:- selectionChanged() activated(QDate) clicked(QDate) On trying all these out it would appear that the event handlers get called as follows:- The clicked(QDate) event gets called if you click on an already selected date. The selectionChanged() and then the clicked(QDate) events are called when you click on a new date. The selectionChanged(), then the clicked(QDate) and then the activated(QDate) events are called if you double-click on a new date. The clicked(QDate) and then the activated(QDate) events are called if you double-click on an already selected date. How can I get a single-click on a date to get 'Action1' and double-click on a date to get 'Action2'? I'm sorry, this got sent a bit before I'd completed it. The trouble is that I want to run Action1 if I single-click on a date whether or not it's a changed date and I want to run Action2 if I double-click on a date whether or not it's a changed date. However I don't see how I can do this because of the order in which the event handlers are called. Is there any way to manipulate this so I can get the result I want? At the moment the only way I can see to do it is to wait a while after a click and then look at what actions occurred but this seems a real bodge. I suspect that the consensus would be don't do that -- having single-click and double click perform unrelated actions. They're not actually unrelated, one will edit an existing entry in a file for the given date, the other will add a new entry in the file for that date. I.e. single-click means open file at specified date, double-click means open file at specified date and insert a new entry for that date. But here's an implementation based on the advice at http://www.qtcentre.org/threads/7858-Double-Click-Capturing (use Ctrl-Break to break out of the event loop) import PyQt4.QtCore as C import PyQt4.QtGui as G class Button(G.QPushButton): def __init__(self, text): G.QPushButton.__init__(self, text) # flag to suppress second mouseReleaseEvent # in this double-click event sequence: # 1. mousePressEvent # 2. mouseReleaseEvent # 3. mouseDoubleClickEvent # 4. mouseReleaseEvent self.double_clicked = False def mouseReleaseEvent(self, evt): # executed for first mouseReleaseEvent if not self.double_clicked: self.first_click_timer = C.QTimer() self.first_click_timer.setSingleShot(True) # double-click must occur within 1/4 second of first-click release self.first_click_timer.setInterval(250) self.first_click_timer.timeout.connect(self.single_click_action) self.first_click_timer.start() # executed for second mouseReleaseEvent else: # reset the flag self.double_clicked = False def single_click_action(self): print Performing single-click action def mouseDoubleClickEvent(self, evt): # suppress the single-click action; perform double-click action instead self.first_click_timer.stop() print Performing double-click action # prepare for second mouseReleaseEvent self.double_clicked = True # main program app = G.QApplication([]) button = Button(Click or double-click me) button.show() app.exec_() Yes, thanks, though it is basically the bodge using timing that I was trying to avoid. It's so fundamental to most GUIs that single-click and double-click allow one to do different things with the same object I'm surprised that pyqt makes it so difficult to implement. -- Chris Green -- http://mail.python.org/mailman/listinfo/python-list
Re: jython lacks working xml processing modules?
On 17/07/12 10:35, gaodexiaozh...@gmail.com wrote: gt; I#39;m trying to parse an xml file with jython (not through java parsers gt; like xerces). https://code.google.com/p/jython-elementtree/ ??? -- http://mail.python.org/mailman/listinfo/python-list
Re: jython lacks working xml processing modules?
Matej Cepl, 17.07.2012 11:39: On 17/07/12 10:35, gaodexiaozh...@gmail.com wrote: gt; I#39;m trying to parse an xml file with jython (not through java parsers gt; like xerces). https://code.google.com/p/jython-elementtree/ ??? Note that this ships with Jython 2.5. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On Tue, Jul 17, 2012 at 4:45 AM, Lipska the Kat lip...@lipskathekat.com wrote: Is Python truly OO or is it just one way to use the language. I see some documentation relating to classes but nothing on instantiation .. in fact the documentation appears to say that classes are used in a static way e.g ClassName.method(), and command line scripting is really outside the scope of other OO languages I have experienced. It doesn't look like you're reading the section on classes: http://docs.python.org/tutorial/classes.html You create a class like this: class MyClass(MySuperclass1, MySuperclass2): # class attributes and methods attr = 3 def method(self): print self.attr You can instantiate it by calling the class, as if it were a function: myinstance = MyClass() You call a method getting the method (myinstance.method), and then calling that as if it were a function. myinstance.method() Polymorphism is duck typed -- that is, it's based on the presence/absence of attributes and methods, not on declared interfaces (Python has no interfaces). So, for example, foo.read() works on any object bound to the name foo, as long as it has a read method that takes no parameters. This could be a file-like object, but it could also be something completely different that just happens to have a method by the same name. Is there a previous discussion in the group that I could read. Man, I dunno, the list archives are impossible to navigate. -- Devin -- http://mail.python.org/mailman/listinfo/python-list
Re: code review
In article XnsA0927750022F4duncanbooth@127.0.0.1, Duncan Booth duncan.bo...@suttoncourtenay.org.uk wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Fri, 13 Jul 2012 12:30:47 +, Albert van der Horst wrote: The worst of is, of course, = for assignment instead of := . This is a convention that Python follows, to my dismay. *shrug* The worst is to use = for both equality and assignment, like some BASICs. At least Python does not allow assignment as an expression, so you can't make the typical C error of: if x = y: do_something() # oops meant x == y Technically of course Python doesn't have assignment, it just binds names. Albert raised the subject of Algol 68 which if I remember correctly used := for assignment and = to bind names (although unlike Python you couldn't then re-bind the name to another object in the same scope). Algol 68 is very particular about this indeed. For instance they have a whole theory behind real x; x := 17.; This is considered an abbreviation of ref real x = loc real; x:= 17; So x is a reference bound to a freshly generated local real. You see = and that means you can't ever break that relationship. On the left side of a := it is required to have a ref something. Because that generates a pretty clear context, you have considerable leeway on the right side, that is cast into the something. real x= 18.; x := 15.; is right out. If you want to rebind something you need a ref which is really a ref ref. Then you can only switch bindings between different types. So it is totally different from Python. I never thought about = in python to mean binding to set it apart from the Pascal := , instead of being a c-ism. Still my mathematical mind is bothered about the sequence ( legal in FORTRAN , C Python ) X = 1 separator X = 2 Groetjes Albert -- Duncan Booth http://kupuguy.blogspot.com Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
Welcome! Am 17.07.2012 10:45, schrieb Lipska the Kat: I was expecting (hoping) to see in depth documentation relating to Class construction, extension mechanisms and runtime polymorphism. In addition to this forum for direct help and discussion, two suggestions: Firstly, it could help if you mentioned what programming languages you are fluent in, in order to help traditional misconceptions and to draw parallels. Secondly, http://docs.python.org is the central hub to tutorials and documentation. What I actually get is a confusion of Classes, modules, scripts and whatever else. Due to the very dynamic nature of Python, types (classes), modules and functions are themselves objects that can be manipulated. Is Python truly OO or is it just one way to use the language. Python supports OOP, but it doesn't enforce it. You can use other paradigms, too. I see some documentation relating to classes but nothing on instantiation .. in fact the documentation appears to say that classes are used in a static way e.g ClassName.method(), and command line scripting is really outside the scope of other OO languages I have experienced. I think you are confused. For the documentation, it would help to know which documentation exactly seems to make such claims. For the thing about commandline scripting, I'm afraid you will have to adjust your expectations. BTW: In general, you instantiate a class by just calling the class' name like a function. If e.g. ClassName is a class, ClassName() instantiates this class. Good luck! Uli -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 17/07/12 10:30, Ulrich Eckhardt wrote: Welcome! Am 17.07.2012 10:45, schrieb Lipska the Kat: I was expecting (hoping) to see in depth documentation relating to Class construction, extension mechanisms and runtime polymorphism. In addition to this forum for direct help and discussion, two suggestions: Firstly, it could help if you mentioned what programming languages you are fluent in For the past 9 years I have been developing in Java, everything from device drivers (well firmware interfaces would be a better description) to serverside business logic implemented using POJOs and database interfaces along with some in depth work with earlier versions of J2EE including EJBs and of course the obligatory frameworks. There's more but you get the idea. My speciality if you like is the design of high availability real time business systems right from high level natural language specifications to detailed use cases and associated models in UML. I also do some implementation work although not so much these days. phew! my resume in a nutshell I suppose Earlier on in my career I did some fairly low level stuff in C and C++ although the mists of time and all that ... Anyway, I'm looking at Python as a rapid prototyping language. I have an idea and just want to get it down in basic outline code as quickly as possible before it departs my aging brain... I'm not used to using variables without declaring their type ... (well I used to do Visual Basic many years ago) It just seems so weird, and what's this obsession with 'correct' indentation of code ??? in order to help traditional misconceptions and to draw parallels. Secondly, http://docs.python.org is the central hub to tutorials and documentation. What I actually get is a confusion of Classes, modules, scripts and whatever else. Due to the very dynamic nature of Python, types (classes), modules and functions are themselves objects that can be manipulated. snip I see some documentation relating to classes but nothing on instantiation .. in fact the documentation appears to say that classes are used in a static way e.g ClassName.method(), and command line scripting is really outside the scope of other OO languages I have experienced. I think you are confused. Highly likely For the documentation, it would help to know which documentation exactly seems to make such claims. For the thing about commandline scripting, I'm afraid you will have to adjust your expectations. I'll try to find it again BTW: In general, you instantiate a class by just calling the class' name like a function. If e.g. ClassName is a class, ClassName() instantiates this class. Good luck! Thank you, and thank you for your kind response Lipska -- Lipska the Kat: Troll hunter, Sandbox destroyer and Farscape dreamer of Aeryn Sun. -- http://mail.python.org/mailman/listinfo/python-list
Re: assertraises behaviour
Am 17.07.2012 11:06, schrieb andrea crotti: import unittest class TestWithRaises(unittest.TestCase): def test_first(self): assert False def test_second(self): print(also called) assert True if __name__ == '__main__': unittest.main() in this case also the second test is run even if the first fails.. The reason for that is that the unit testing framework catches and handles the error. It calls both test functions in some unspecified order and logs the result. Calls to two separate test functions are thereby separated from each other. This is intentionally so, but I think you can also give the unit testing framework a flag that makes it abort after the first error. In no way will the exception escape from the unittest.main() call though, it is all caught and handled inside, also by intention. But that's probably easy because we just need to catch exceptions for every method call, so it's not exactly the same thing.. I don't understand what you want to say here. I also don't understand what your problem in general is. I guess there are some expectations which are not satisfied, but you haven't explained those explicitly yet. Uli -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 07/17/2012 07:01 AM, Lipska the Kat wrote: SNIP Anyway, I'm looking at Python as a rapid prototyping language. I have an idea and just want to get it down in basic outline code as quickly as possible before it departs my aging brain... I'm not used to using variables without declaring their type ... (well I used to do Visual Basic many years ago) It just seems so weird, and what's this obsession with 'correct' indentation of code ??? Welcome to comp.lang.python. I hope you enjoy learning and using Python. Indentation isn't just custom in Python. It's part of the syntax. Other languages use braces, or keywords, to indicate scope, but Python uses indentation. Other than the occasional tab to confuse things, the rules are pretty simple. You must indent the body of a function, the scope of an if or else clause, or other similar language pieces (class, try, except, ...) Within such a scope, you cannot change indentation, except of course for a nested scope. At the end of such scope you must outdent to the previous state. The convention is to use 4 spaces per indentation, but the language will accept any amount, as long as it's consistent within any single scope. And although mixing tabs and space worked in Python 2.x, sort of, it's disallowed in Python 3. An expression may span multiple lines, but only if it's unambiguous to the compiler (eg. a pending left paren with no matching right paren yet). In that case. indentation of the subsequent lines is unrestricted. HTH -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 17/07/12 11:03, Devin Jeanpierre wrote: On Tue, Jul 17, 2012 at 4:45 AM, Lipska the Katlip...@lipskathekat.com wrote: Is Python truly OO or is it just one way to use the language. I see some documentation relating to classes but nothing on instantiation .. in fact the documentation appears to say that classes are used in a static way e.g ClassName.method(), and command line scripting is really outside the scope of other OO languages I have experienced. It doesn't look like you're reading the section on classes: http://docs.python.org/tutorial/classes.html Thanks, I wasn't, there is too much to do and not enough time to do it. So now I just need to chill out a bit and get into 'documentation reading mode' again Polymorphism is duck typed -- Yes, I've been reading the wikipedia entry on this ... this type of polymorphism is not familiar to me ... I come from a Java background. more reading I guess. snip -- Devin Thanks for your time and I'll try to do a bit better with the reading thing before asking more questions... not sure about this obsession with code indentation though :-| -- Lipska the Kat: Troll hunter, Sandbox destroyer and Farscape dreamer of Aeryn Sun. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 7/17/2012 6:01 AM, Lipska the Kat wrote: Anyway, I'm looking at Python as a rapid prototyping language. I have an idea and just want to get it down in basic outline code as quickly as possible before it departs my aging brain... I'm not used to using variables without declaring their type ... (well I used to do Visual Basic many years ago) It just seems so weird, and what's this obsession with 'correct' indentation of code ??? Pythonic is (or at least should be) a word you encounter frequently in discussions of Python code. Learn what is considered Pythonic and then write Python code that way if you want to work with the language rather than fight it. Duck-typing is very Pythonic and so is readable code. As Dave mentioned, indentation is part of the syntax - blocks must be indented with either tabs or spaces (choose one - if you mix them ambiguously, an IndentationError will be raised). Try from __future__ import braces and import this for some insight. ;) The official tutorial gives a great overview of the language and has links to reference material that goes into greater detail: http://docs.python.org/tutorial/ (Python 2.7) http://docs.python.org/py3k/tutorial/ (Python 3.2) On a side note, I would highly recommend learning Python 3 (3.2 is the latest stable version) unless you have an explicit need for Python 2 (some major 3rd-party libraries have not been ported yet). Python 2 won't get any new features; it will simply get bug fixes until its EOL in 2014 (15?). -- CPython 3.3.0b1 | Windows NT 6.1.7601.17803 -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 17/07/12 12:37, Andrew Berg wrote: On 7/17/2012 6:01 AM, Lipska the Kat wrote: Anyway, I'm looking at Python as a rapid prototyping language. snip Pythonic is (or at least should be) a word you encounter frequently in discussions of Python code. Learn what is considered Pythonic and then write Python code that way if you want to work with the language rather than fight it. Duck-typing is very Pythonic You're not kidding, the 'duck' example at http://en.wikipedia.org/wiki/Duck_typing made me check I hadn't overdone the medication this morning. That is just plain ...weird. It will take me a while to form non knee jerk opinions of this for sure. snip On a side note, I would highly recommend learning Python 3 (3.2 is the latest stable version) unless you have an explicit need for Python 2 (some major 3rd-party libraries have not been ported yet). Python 2 won't get any new features; it will simply get bug fixes until its EOL in 2014 (15?). I'll check it out, thanks. Lipska -- Lipska the Kat: Troll hunter, Sandbox destroyer and Farscape dreamer of Aeryn Sun. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 7/17/2012 6:44 AM, Lipska the Kat wrote: I'll check it out, thanks. I forgot to add this: http://wiki.python.org/moin/Python2orPython3 It's a little outdated (there is more progress toward py3k by 3rd-party libraries every day), but still quite helpful. -- CPython 3.3.0b1 | Windows NT 6.1.7601.17803 -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 17/07/12 09:45, Lipska the Kat wrote: Pythoners Python 2.7.3 Ubuntu Linux 12.04 LTS I've been taking a brief look at Python. snip Well I've set myself a task. I have a text file containing a list of stock items each line contains the number in stock followed by a tab followed by the name of the item. I need to implement something that reads in the text file and outputs the stock list in ascending or descending order of quantity. Please note I am NOT asking for solutions. In bash this is laughably trivial sort -nr $1 | head -${2:-10} Java is easy but long winded and takes a while to set up C is ... well it's been a while but I'll get there Python, well that's my current task. It will be interesting to compare the solutions for speed and ease of development and more importantly re-usability. Lipska -- Lipska the Kat: Troll hunter, Sandbox destroyer and Farscape dreamer of Aeryn Sun. -- http://mail.python.org/mailman/listinfo/python-list
Re: Style question: metaclass self vs cls?
The standard is to use `cls`. In the __new__ method you can use `mcl` or `meta`. -- http://mail.python.org/mailman/listinfo/python-list
Re: Implicit conversion to boolean in if and while statements
Andrew Berg wrote: To put it in duck-typing terms, why should everything have to quack like True or False? Sure, I can see why 1 quacks like True or [] quacks like False, but I don't see why say, a Logger or function should quack like either. Should a Thread object be True if it's been started and False otherwise? True and False are red herrings. It is more appropriate to think that True quacks like something and False like nothing than the other way 'round. Maybe some examples from my own code will help: DbfTable-- True if any records in table, False otherwise DbfIndex-- True if any records in index, False otherwise DbfList -- True if any records in list, False otherwise DbfDate -- True if a date, False otherwise (could be eight spaces instead of a real date) DbfDateTime -- True if a datetime, False otherwise DbfRecord -- True always DbfRecordTemplate -- True always DbfRecordVaporware -- False always While I could have DbfRecord be False if, for example, it had no data stored in it, I have no use case for that scenario so haven't bothered. Also, at this point I am using the distinction of True/False with regards to records to determine if I have a real record (True means a record/template I can read/write, False means I don't). If it truly is about something vs. nothing, why is a NameError (or AttributeError) raised when testing with an undefined variable? Being undefined quacks like nothing, doesn't it? It's about /representing/ something vs. nothing. An undefined name isn't representing anything (except a bug, of course ;). ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Implicit conversion to boolean in if and while statements
On 2012-07-17 10:23, Andrew Berg wrote: I don't want that, but I am suggesting that it would be consistent with the idea of something or nothing. Don't confuse names and objects. You can only test the truth value of objects. If you don't have a name in a namespace, then it means you don't have a tool to have a reference to anything (including the False object). Using the same logic you could also say that not giving any condition to the if statement should be evaluated as False: if: print This never gets executed But it makes no sense. -- http://mail.python.org/mailman/listinfo/python-list
Re: Implicit conversion to boolean in if and while statements
Not really. It doesn't quack like anything. Actually, there is no it. So we cannot talk about how it quacks. :-D -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
Am 17.07.2012 13:01, schrieb Lipska the Kat: On 17/07/12 10:30, Ulrich Eckhardt wrote: Am 17.07.2012 10:45, schrieb Lipska the Kat: I was expecting (hoping) to see in depth documentation relating to Class construction, extension mechanisms and runtime polymorphism. In addition to this forum for direct help and discussion, two suggestions: Firstly, it could help if you mentioned what programming languages you are fluent in For the past 9 years I have been developing in Java [...] Java is usually called an OOP language, because everything you do there is put into a class. Free functions don't exist, the closest you get is class-static functions (correct me if I'm wrong, I'm not really fluent in that language). In Python, you have the choice to use OOP, but you can also use free functions or mix those. I'm not used to using variables without declaring their type As a C++ programmer (roughly 80%C++, 15%Python, 5%C) I know that feeling. Having types declared in advance just helps by having the compiler check if the passed arguments are correct. Not having this gives both freedom but also bears dangers. what's this obsession with 'correct' indentation of code ??? You'll get used to it and then start loving it. ;) Uli -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 17/07/2012 12:01, Lipska the Kat wrote: Anyway, I'm looking at Python as a rapid prototyping language. Lipska One of the huge advantages of Python here is that you can simply blast stuff into the interactive prompt and see what happens, no need to write a script. -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 17/07/2012 12:44, Lipska the Kat wrote: You're not kidding, the 'duck' example at http://en.wikipedia.org/wiki/Duck_typing made me check I hadn't overdone the medication this morning. That is just plain ...weird. It will take me a while to form non knee jerk opinions of this for sure. Lipska It's difficult to get junkies off of their addictive substances but I'm sure that the qualities of Python will eventually overcome your Java habit :) -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Python 2.6 on Mac 10.7 doesn't work
Hi, I am trying to install Python 2.6 on Mac OS Lion. Here is what I did: 1- Download Mac Installer disk image (2.6) (sig) from http://www.python.org/getit/releases/2.6/ 2- Install it 3- Run Python Luncher, go to Python Luncher preferences, and change the interpreter to Library/Frameworks/Python.framework/Versions/2.6/bin/pythonw Now that I want to open IDLE and open my old projects, it doesn't run! Is there anything that I am missing? oh btw, I used to use Python 2.6.7 that comes preinstalled on Mac OS. I really appreciate your help. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
In article -8sdnvrxgqie25jnnz2dnuvz7qkdn...@bt.com, Lipska the Kat lip...@lipskathekat.com wrote: I'm not used to using variables without declaring their type If you truly wanted to recreate this type-bondage style of programming in Python, it's easy enough to do. Where you would write in C++: // Type matching will get checked at compile-time void my_function(MassivelyParallelFrobinator mpf, OtherThing ot) { blah, blah, blah } you could write in Python: # Type matching will get checked at run-time def my_function(mpf, ot): assert isinstance(mpf, MassivelyParallelFrobinator) assert isinstance(ot, OtherThing) but that's just not the way people write code in Python. -- http://mail.python.org/mailman/listinfo/python-list
How to configure Tkinter Listbox to disable state keeping selected item highlighted
I am having a problem configuring a listbox widget such that the selection remains highlighted even while it is set (programmatically) to the DISABLED state. Below code shows the problem: from Tkinter import * master = Tk() listbox = Listbox(master) listbox.pack() listbox.insert(END, Text1) listbox.insert(END, Text2) listbox.insert(END, Text3) listbox.selection_set(first=0, last=None) listbox.configure(exportselection=False) listbox.configure(state=DISABLED) Now when I change state to NORMAL, selected item is being highlighted. Is there a way I could disable widget (i.e. No response on mouse clicks) but keep the selected object remain highlighted? Intent: I want to utilise this widget on wizard App that I am creating. I would like this widget to indicate the current page / wizard number which the user selected. Is there any other widget I could use instead of it? (Labels possibly?) -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 17/07/12 12:37, Andrew Berg wrote: On 7/17/2012 6:01 AM, Lipska the Kat wrote: snip On a side note, I would highly recommend learning Python 3 (3.2 is the latest stable version) unless you have an explicit need for Python 2 (some major 3rd-party libraries have not been ported yet). Python 2 won't get any new features; it will simply get bug fixes until its EOL in 2014 (15?). Wow, that was a blast from the past Just downloaded, unzipped, untarred, configured, made and installed python 3.2.3 ... it's YEARS since I've done this, makes me feel young again. Lispka -- Lipska the Kat: Troll hunter, Sandbox destroyer and Farscape dreamer of Aeryn Sun. -- http://mail.python.org/mailman/listinfo/python-list
Re: Diagramming code
Chris Rebert於 2012年7月16日星期一UTC+8上午9時38分53秒寫道: On Sun, Jul 15, 2012 at 6:26 PM, hamilton lt;hamil...@nothere.comgt; wrote: gt; Subject: Diagramming code gt; gt; Is there any software to help understand python code ? What sort of diagrams? Control flow diagrams? Class diagrams? Sequence diagrams? Module dependency diagrams? There are many different types you could be referring to. Here#39;s a relatively comprehensive list: http://en.wikipedia.org/wiki/Unified_Modeling_Language#Diagrams_overview Regards, Chris -- UML: Kill it with fire! OK, I'll classify OOP by (1) properties of instances of declared classes must be fixed such as those in C++ (2) An interpreter could be embedded in the run time for an object to evolve through time to accquire properties. If the robot age was to be comming, what can we do now? I think learning python is the high school does help a lot for the United States in the future. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 7/17/2012 9:01 AM, Lipska the Kat wrote: Wow, that was a blast from the past Just downloaded, unzipped, untarred, configured, made and installed python 3.2.3 ... it's YEARS since I've done this, makes me feel young again. Most Linux distributions should have a premade package for stable Python versions - apt-get install python3 or something like that. Python 2 is generally the default Python because of all the system scripts that haven't been ported to py3k. -- CPython 3.3.0b1 | Windows NT 6.1.7601.17803 -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 17/07/12 14:52, Roy Smith wrote: In article-8sdnvrxgqie25jnnz2dnuvz7qkdn...@bt.com, Lipska the Katlip...@lipskathekat.com wrote: I'm not used to using variables without declaring their type If you truly wanted to recreate this type-bondage style of programming in Python, it's easy enough to do. snip Well 'type-bondage' is a strange way of thinking about compile time type checking and making code easier to read (and therefor debug) but I'm not about to get into some religious war about declaring a variables type. I'll just say that I prefer to devote testing efforts to the real danger area which in my experience is 'user' input. Clients look dimly on runtime errors however they occur and if I can leave it to the compiler to check as much as possible then I'll take that. I do understand however that compiling an intepreted language doesn't really make sense however i'm sure there are interpreted languages that allow pre-execution type checking ... aren't there ? Oh yes, there's one called Java :-) Still, I'm sure you're only kidding around with me :-) Lipska -- Lipska the Kat: Troll hunter, Sandbox destroyer and Farscape dreamer of Aeryn Sun. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 17/07/12 15:16, Andrew Berg wrote: On 7/17/2012 9:01 AM, Lipska the Kat wrote: Wow, that was a blast from the past Just downloaded, unzipped, untarred, configured, made and installed python 3.2.3 ... it's YEARS since I've done this, makes me feel young again. Most Linux distributions should have a premade package for stable Python versions - apt-get install python3 or something like that. Not as much fun though is it :-) Lipska -- Lipska the Kat: Troll hunter, Sandbox destroyer and Farscape dreamer of Aeryn Sun. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to configure Tkinter Listbox to disable state keeping selected item highlighted
On Tuesday, July 17, 2012 06:55:21 AM Sarbjit singh wrote: I am having a problem configuring a listbox widget such that the selection remains highlighted even while it is set (programmatically) to the DISABLED state. Below code shows the problem: from Tkinter import * master = Tk() listbox = Listbox(master) listbox.pack() listbox.insert(END, Text1) listbox.insert(END, Text2) listbox.insert(END, Text3) listbox.selection_set(first=0, last=None) listbox.configure(exportselection=False) listbox.configure(state=DISABLED) Now when I change state to NORMAL, selected item is being highlighted. Is there a way I could disable widget (i.e. No response on mouse clicks) but keep the selected object remain highlighted? Learn how to use radiobuttons. I think this is what you want. jd Intent: I want to utilise this widget on wizard App that I am creating. I would like this widget to indicate the current page / wizard number which the user selected. Is there any other widget I could use instead of it? (Labels possibly?)-- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 17/07/2012 15:23, Lipska the Kat wrote: On 17/07/12 14:52, Roy Smith wrote: In article-8sdnvrxgqie25jnnz2dnuvz7qkdn...@bt.com, Lipska the Katlip...@lipskathekat.com wrote: I'm not used to using variables without declaring their type If you truly wanted to recreate this type-bondage style of programming in Python, it's easy enough to do. snip Well 'type-bondage' is a strange way of thinking about compile time type checking and making code easier to read (and therefor debug) but I'm not about to get into some religious war about declaring a variables type. I'll just say that I prefer to devote testing efforts to the real danger area which in my experience is 'user' input. Why waste time testing, I thought that the compiler looked after everything? :) But seriously you might want to look at the unittest module in the standard library. There's also a separate mailing list for Python testing and I'm sure there's a wiki that compares the available tesing tools. Google and ye shall find!!! Clients look dimly on runtime errors however they occur and if I can leave it to the compiler to check as much as possible then I'll take that. I do understand however that compiling an intepreted language doesn't really make sense however i'm sure there are interpreted languages that allow pre-execution type checking ... aren't there ? Oh yes, there's one called Java :-) There are tools available to help here such as pylint, pychecker and pyflakes. For other modules check out pypi at http://pypi.python.org/pypi Still, I'm sure you're only kidding around with me :-) Kidding around on a Python mailing list, never, how dare you Sir, simply wouldn't be cricket :-) Lipska -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.6 on Mac 10.7 doesn't work
On 17/07/12 15:47:05, Naser Nikandish wrote: Hi, I am trying to install Python 2.6 on Mac OS Lion. Here is what I did: 1- Download Mac Installer disk image (2.6) (sig) from http://www.python.org/getit/releases/2.6/ 2- Install it 3- Run Python Luncher, go to Python Luncher preferences, and change the interpreter to Library/Frameworks/Python.framework/Versions/2.6/bin/pythonw Now that I want to open IDLE and open my old projects, it doesn't run! Is there anything that I am missing? You may be missing a leading slash. The path to pythonw is /Library/Frameworks/Python.framework/Versions/2.6/bin/pythonw oh btw, I used to use Python 2.6.7 that comes preinstalled on Mac OS. That could also be the problem. You could try using the Python you've downloaded in step 1. I really appreciate your help. You could try opening /Applications/Utilities/Terminal.app and running: /Library/Frameworks/Python.framework/Versions/2.6/bin/pyt\ hon /Applications/Python\ 2.6/IDLE.app/Contents/MacOS/IDLE (you can type it one two lines, as shown, or as a single rather long line, leaving out the backslash-newline). That should run Idle, or, if it doesn't, it should give you a useful error message. Hope this helps, -- HansM -- http://mail.python.org/mailman/listinfo/python-list
Re: Style question: metaclass self vs cls?
On Tue, Jul 17, 2012 at 6:23 AM, Michele Simionato michele.simion...@gmail.com wrote: The standard is to use `cls`. In the __new__ method you can use `mcl` or `meta`. I've also seen `mcs` a fair amount. -- http://mail.python.org/mailman/listinfo/python-list
Re: Style question: metaclass self vs cls?
On Tue, Jul 17, 2012 at 12:10 AM, alex23 wuwe...@gmail.com wrote: On Jul 17, 1:29 am, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: Here's a style question for you: in a metaclass, what should I call the instance parameter of methods, cls or self? Maybe portmanteu it as clasself? :) What is this, 1st edition DD? Elf is a race, not a class. -- http://mail.python.org/mailman/listinfo/python-list
Blank TK Window
Hi, Any reason why a blank Tk() window opens up when I run my code: Code: for run in range(RUNS): waittime = Monitor2() checkouttime = Monitor2() totaltimeinshop = Monitor2() checkout_aisle = Simulation.Resource(AISLES) Simulation.initialize() cf = Customer_Market() Simulation.activate(cf, cf.run(), 0.0) Simulation.simulate(until=CLOSING) Histo = waittime.histogram(low=0.0, high=80, nbins=40) plt = SimPlot() plt.plotLine(Histo, xlab='Time (min)',ylab='Qty Customers', title=Wait Time, color=red, width=2, smooth='True') plt.mainloop() -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 17/07/12 17:26, Mark Lawrence wrote: On 17/07/2012 15:23, Lipska the Kat wrote: On 17/07/12 14:52, Roy Smith wrote: snip Still, I'm sure you're only kidding around with me :-) Kidding around on a Python mailing list, never, how dare you Sir, simply wouldn't be cricket :-) As in The batsman of the Kalahari no doubt :-) -- Lipska the Kat: Troll hunter, Sandbox destroyer and Farscape dreamer of Aeryn Sun. -- http://mail.python.org/mailman/listinfo/python-list
Re: Blank TK Window
On Jul 17, 9:32 am, Shamefaced manengstud...@gmail.com wrote: Hi, Any reason why a blank Tk() window opens up when I run my code: Code: for run in range(RUNS): waittime = Monitor2() checkouttime = Monitor2() totaltimeinshop = Monitor2() checkout_aisle = Simulation.Resource(AISLES) Simulation.initialize() cf = Customer_Market() Simulation.activate(cf, cf.run(), 0.0) Simulation.simulate(until=CLOSING) Histo = waittime.histogram(low=0.0, high=80, nbins=40) plt = SimPlot() plt.plotLine(Histo, xlab='Time (min)',ylab='Qty Customers', title=Wait Time, color=red, width=2, smooth='True') plt.mainloop() 1. you no longer have a toplevel/root plt once you replace plt with plt = SimPlot() 2. the SimPlot widget in never placed in Tkinter. This is usually done with pack() or grid() So start out with a Tkinter tutorial so you understand the basics. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 7/17/2012 10:23 AM, Lipska the Kat wrote: Well 'type-bondage' is a strange way of thinking about compile time type checking and making code easier to read (and therefor debug 'type-bondage' is the requirement to restrict function inputs and output to one declared type, where the type declaration mechanisms are usually quite limited. def max(a, b): if a = b: return a return b max(1,3) 1 max(3.3, 3.1) 3.1 max('ab', 'aa') 'aa' max([1,1], [1,0]) [1, 0] and so on, indefinitely. How easy is it to write the same in Java? Similarly, list.sort sorts any list as long as a b works for all pairs of items in the list. Function max works for any two objects as long as 'a = b' works. So the 'type' of a and b is 'mutually comparable with ='. How do you declare that in Java? How do you declare the type 'non-negative number'? In python, putting 'if input = 0:' as the top effectively 'declares' that input must be a number and greater than 0. but I'm not about to get into some religious war about declaring a variables type. In Python, *all* data items have a class (type). Names in code do not have a type. When they become data items, they are strings. 'Variable' is a somewhat fuzzy term or concept in Python. Since every object is an instance of some class, every class is a subclass of class 'object', and an instance of a class is an instance of all its classess superclasses; every object is an instance of 'object'. So 'object' is the type of all inputs until further restricted. id(ob) produces an integer for all objects. str(ob) is intented to produce a string representation for all objects. The print functions calls str on all its inputs. I'll just say that I prefer to devote testing efforts to the real danger area which in my experience is 'user' input. Clients look dimly on runtime errors however they occur and if I can leave it to the compiler to check as much as possible then I'll take that. import ast a = ast.literal_eval(input('enter a value: ')) b = ast.literal_eval(input('enter a comparable value: ') try: print('the max of those two is ', max(a,b)) except TypeError: print(a, ' and ', b, ' are not comparable') I suppose Still, I'm sure you're only kidding around with me :-) How easy was it to write max, or a universal sort in Java? -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 7/17/2012 8:01 AM, Lipska the Kat wrote: On 17/07/12 09:45, Lipska the Kat wrote: Pythoners Python 2.7.3 Ubuntu Linux 12.04 LTS I've been taking a brief look at Python. snip Well I've set myself a task. I have a text file containing a list of stock items each line contains the number in stock followed by a tab followed by the name of the item. I need to implement something that reads in the text file and outputs the stock list in ascending or descending order of quantity. Nice problem. Easy but non-trivial. Please note I am NOT asking for solutions. Ok. With some inefficient redundancy, I believe it could be done in one line in Python. Better code would take a few more. In bash this is laughably trivial sort -nr $1 | head -${2:-10} Won't sort work alphabetically and leave the following as is? 1\talpha 11\tbeta 2\tgamma -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 7/17/2012 10:16 AM, Andrew Berg wrote: On 7/17/2012 9:01 AM, Lipska the Kat wrote: Wow, that was a blast from the past Just downloaded, unzipped, untarred, configured, made and installed python 3.2.3 ... it's YEARS since I've done this, makes me feel young again. Most Linux distributions should have a premade package for stable Python versions - apt-get install python3 or something like that. I am just curious: how long will it take 'most Linux distributions' to premake the even better 3.3.0 (after it comes out) and change the default python3 to that? Do any of them have a premade 3.3.0b0 available? (In some ways, it is already better than 3.2.3.) -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
Terry Reedy wrote: On 7/17/2012 10:23 AM, Lipska the Kat wrote: Well 'type-bondage' is a strange way of thinking about compile time type checking and making code easier to read (and therefor debug 'type-bondage' is the requirement to restrict function inputs and output to one declared type, where the type declaration mechanisms are usually quite limited. def max(a, b): if a = b: return a return b Surely you meant 'if a = b: . . .' No worries, I'm sure your unittests would have caught it. ;) ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: PyQt QCalendarWidget events question
On Tue, Jul 17, 2012 at 7:34 PM, tinn...@isbd.co.uk wrote: It's so fundamental to most GUIs that single-click and double-click allow one to do different things with the same object Kinda yes, kinda no. Most GUIs and GUI recommendations would either enforce or strongly suggest that the double-click action incorporate the click action; for instance, click to select, double-click to open. The series of events usually goes: Mouse down Mouse up Click Mouse down Mouse up Double-click They're fired as things happen and in that order. (Some systems insert another Click just before the Double-click, but that's generally unhelpful.) Please code your application so that this isn't a problem to it, because anything else causes untold confusion to the users. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 17/07/2012 18:24, Terry Reedy wrote: On 7/17/2012 8:01 AM, Lipska the Kat wrote: On 17/07/12 09:45, Lipska the Kat wrote: Pythoners Python 2.7.3 Ubuntu Linux 12.04 LTS I've been taking a brief look at Python. snip Well I've set myself a task. I have a text file containing a list of stock items each line contains the number in stock followed by a tab followed by the name of the item. I need to implement something that reads in the text file and outputs the stock list in ascending or descending order of quantity. Nice problem. Easy but non-trivial. Please note I am NOT asking for solutions. Ok. With some inefficient redundancy, I believe it could be done in one line in Python. Better code would take a few more. In bash this is laughably trivial sort -nr $1 | head -${2:-10} Won't sort work alphabetically and leave the following as is? 1\talpha 11\tbeta 2\tgamma The commandline options are -nr. n means compare numerically and r means reverse order. -- http://mail.python.org/mailman/listinfo/python-list
RE: assertraises behaviour
import unittest class TestWithRaises(unittest.TestCase): def test_first(self): assert False def test_second(self): print(also called) assert True if __name__ == '__main__': unittest.main() in this case also the second test is run even if the first fails.. The reason for that is that the unit testing framework catches and handles the error. It calls both test functions in some unspecified order and logs the result. Calls to two separate test functions are thereby separated from each other. This is intentionally so, but I think you can also give the unit testing framework a flag that makes it abort after the first error. In no way will the exception escape from the unittest.main() call though, it is all caught and handled inside, also by intention. But that's probably easy because we just need to catch exceptions for every method call, so it's not exactly the same thing.. I don't understand what you want to say here. I also don't understand what your problem in general is. I guess there are some expectations which are not satisfied, but you haven't explained those explicitly yet. I think Andrea wants to do the same thing but with nose and not unittest. Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 07/17/12 12:24, Terry Reedy wrote: On 7/17/2012 8:01 AM, Lipska the Kat wrote: In bash this is laughably trivial sort -nr $1 | head -${2:-10} Won't sort work alphabetically and leave the following as is? 1\talpha 11\tbeta 2\tgamma Only if Lipska had omitted the -n which tells sort to treat numbers like numbers. For Lipska, you'd want to look into the csv module for parsing the file easily (specifying '\t' as the delimiter). You can then sort and crop as-is, or you can use heapq.nsmallest() -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Implicit conversion to boolean in if and while statements
On 7/17/2012 4:23 AM, Andrew Berg wrote: On 7/17/2012 2:08 AM, Steven D'Aprano wrote: The default behaviour is that every object is something, hence true-like, unless explicitly coded to be treated as false-like. Since both loggers and functions are objects, they are true-like unless the default is overridden. I am aware of the default behavior, but the reason for it still eludes me. Ultimately, because Guido's intuition said that the current behavior is the best. I happen to agree on this one. Quoting from elsewhere: If it truly is about something vs. nothing, why is a NameError (or AttributeError) raised when testing with an undefined variable? Python does not have 'undefined variable' objects in the way that some other languages do. There is nothing to test 'with'. 'if undefined_name:' raises NameError because all uses of undefined_names other that assignments do. The actually execution order is expression first, then if. You can explicitly test 'some_name' in namespace or hasattr(obj, 'somename') by turning the possibly undefined name into a string object. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 7/17/2012 12:30 PM, Terry Reedy wrote: (In some ways, it is already better than 3.2.3.) I certainly make heavy use of some of the new features. I'm not sure we can have enough separate exceptions for OS errors without exhausting every possibility and I might start looking for excuses to use the lzma module. :P -- CPython 3.3.0b1 | Windows NT 6.1.7601.17803 -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On Wed, Jul 18, 2012 at 12:23 AM, Lipska the Kat lip...@lipskathekat.com wrote: Well 'type-bondage' is a strange way of thinking about compile time type checking and making code easier to read (and therefor debug) but I'm not about to get into some religious war about declaring a variables type. There are options for that, but they aren't Python. (I'd like to see a from __future__ import variable_declarations, but it doesn't seem to work. Yet.) If you're interested, I could tell you about a language that has a lot of what you're looking for (including polymorphism and even the ability to declare a variable that can contain non-negative integer as a type), but it's off-topic for the forum. However, I can't email you, as lipskathekat.com doesn't seem to exist... Email me privately if you're interested, we can continue the discussion off-list. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 07/17/12 12:29, Ethan Furman wrote: Terry Reedy wrote: On 7/17/2012 10:23 AM, Lipska the Kat wrote: Well 'type-bondage' is a strange way of thinking about compile time type checking and making code easier to read (and therefor debug 'type-bondage' is the requirement to restrict function inputs and output to one declared type, where the type declaration mechanisms are usually quite limited. def max(a, b): if a = b: return a return b Surely you meant 'if a = b: . . .' No worries, I'm sure your unittests would have caught it. ;) Or he could have meant min instead of max. Or he could have returned the wrong values: def max(a, b): if a = b: return b return a :-) -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: assertraises behaviour
On 17/07/2012 18:49, Prasad, Ramit wrote: import unittest class TestWithRaises(unittest.TestCase): def test_first(self): assert False def test_second(self): print(also called) assert True if __name__ == '__main__': unittest.main() in this case also the second test is run even if the first fails.. The reason for that is that the unit testing framework catches and handles the error. It calls both test functions in some unspecified order and logs the result. Calls to two separate test functions are thereby separated from each other. This is intentionally so, but I think you can also give the unit testing framework a flag that makes it abort after the first error. In no way will the exception escape from the unittest.main() call though, it is all caught and handled inside, also by intention. But that's probably easy because we just need to catch exceptions for every method call, so it's not exactly the same thing.. I don't understand what you want to say here. I also don't understand what your problem in general is. I guess there are some expectations which are not satisfied, but you haven't explained those explicitly yet. I think Andrea wants to do the same thing but with nose and not unittest. Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. Do what? Like Ulrich Eckhart I simply don't understand what she's getting at. Perhaps it's a problem with Englsh being a second language issue rather than Python itself. Thankfully I'm sure that everything will come out in the wash. -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 17/07/2012 18:29, Ethan Furman wrote: Terry Reedy wrote: On 7/17/2012 10:23 AM, Lipska the Kat wrote: Well 'type-bondage' is a strange way of thinking about compile time type checking and making code easier to read (and therefor debug 'type-bondage' is the requirement to restrict function inputs and output to one declared type, where the type declaration mechanisms are usually quite limited. def max(a, b): if a = b: return a return b Surely you meant 'if a = b: . . .' No worries, I'm sure your unittests would have caught it. ;) ~Ethan~ Wouldn't the compiler have caught it before the unittests? :-) -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 17/07/12 18:24, Terry Reedy wrote: On 7/17/2012 8:01 AM, Lipska the Kat wrote: On 17/07/12 09:45, Lipska the Kat wrote: Pythoners Python 2.7.3 Ubuntu Linux 12.04 LTS I've been taking a brief look at Python. snip Well I've set myself a task. I have a text file containing a list of stock items each line contains the number in stock followed by a tab followed by the name of the item. I need to implement something that reads in the text file and outputs the stock list in ascending or descending order of quantity. snip In bash this is laughably trivial sort -nr $1 | head -${2:-10} Won't sort work alphabetically and leave the following as is? 1\talpha 11\tbeta 2\tgamma The -n option tells sort to interpret the first word on a line as a number r means sort in descending order. It works fine. I also added another feature not in the specification that allows the input of a number of lines to print ... well on the way to being bloatware I guess ;-) Lipska -- Lipska the Kat: Troll hunter, Sandbox destroyer and Farscape dreamer of Aeryn Sun. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
Mark Lawrence wrote: On 17/07/2012 18:29, Ethan Furman wrote: Terry Reedy wrote: On 7/17/2012 10:23 AM, Lipska the Kat wrote: Well 'type-bondage' is a strange way of thinking about compile time type checking and making code easier to read (and therefor debug 'type-bondage' is the requirement to restrict function inputs and output to one declared type, where the type declaration mechanisms are usually quite limited. def max(a, b): if a = b: return a return b Surely you meant 'if a = b: . . .' No worries, I'm sure your unittests would have caught it. ;) ~Ethan~ Wouldn't the compiler have caught it before the unittests? :-) Silly me, the word processor would have caught it! ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: assertraises behaviour
On 7/17/2012 5:06 AM, andrea crotti wrote: Well this is what I meant: import unittest class TestWithRaises(unittest.TestCase): def test_first(self): assert False def test_second(self): print(also called) assert True if __name__ == '__main__': unittest.main() in this case also the second test is run even if the first fails. Or test_first is run even if test_second fails. The point is that unittest runs separate test methods independently. They could theoretically be run simultaneously. Tests within a method are dependent unless you take steps to make them independent by not having them raise exceptions or by catching exception as you go until you are done. If you make a error_list of problems as you go, you could end the method with assertFalse(error_list). -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 17/07/12 19:18, Mark Lawrence wrote: On 17/07/2012 18:29, Ethan Furman wrote: Terry Reedy wrote: On 7/17/2012 10:23 AM, Lipska the Kat wrote: Well 'type-bondage' is a strange way of thinking about compile time type checking and making code easier to read (and therefor debug 'type-bondage' is the requirement to restrict function inputs and output to one declared type, where the type declaration mechanisms are usually quite limited. def max(a, b): if a = b: return a return b Surely you meant 'if a = b: . . .' No worries, I'm sure your unittests would have caught it. ;) ~Ethan~ Wouldn't the compiler have caught it before the unittests? :-) Not unless the compiler could read your mind! The syntax looks fine it's the semantics that are suspect. Wrong is a word that I try not to use as it tends to upset people, let's call them differently right ;-) BTW having more than one return statement in a block is a little thing I know but it drives me nuts ... another Pythonic thing I'll have to get used to I suppose. -- Lipska the Kat: Troll hunter, Sandbox destroyer and Farscape dreamer of Aeryn Sun. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On Tue, Jul 17, 2012 at 1:07 PM, Terry Reedy tjre...@udel.edu wrote: 'type-bondage' is the requirement to restrict function inputs and output to one declared type, where the type declaration mechanisms are usually quite limited. This is interesting, I hadn't expected that sort of definition. So Haskell is not a type-bondage language? (i.e. it lets you write functions that accept any type via parametric polymorphism, or any type that supports an interface via type classes). How easy was it to write max, or a universal sort in Java? You write obj.compareTo(other) 0 instead of using obj other, and your methods only work on objects (that support the comparable interface). Otherwise, no different than Python, I guess. Would Java not be a type-bondage language if everything was an object? -- Devin -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 17/07/12 18:07, Terry Reedy wrote: On 7/17/2012 10:23 AM, Lipska the Kat wrote: Well 'type-bondage' is a strange way of thinking about compile time type checking and making code easier to read (and therefor debug snip How easy was it to write max, or a universal sort in Java? Well java.lang.Math.max() (or min() depending on what you want) might do it and as for sorting ... java.utils.Collections.sort will sort anything that implements the java.util.Comparable interface. All the standard numerical classes implement Comparable by default so there is nothing to do really. Lipska -- Lipska the Kat: Troll hunter, Sandbox destroyer and Farscape dreamer of Aeryn Sun. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 17/07/2012 19:43, Ethan Furman wrote: Mark Lawrence wrote: On 17/07/2012 18:29, Ethan Furman wrote: Terry Reedy wrote: On 7/17/2012 10:23 AM, Lipska the Kat wrote: Well 'type-bondage' is a strange way of thinking about compile time type checking and making code easier to read (and therefor debug 'type-bondage' is the requirement to restrict function inputs and output to one declared type, where the type declaration mechanisms are usually quite limited. def max(a, b): if a = b: return a return b Surely you meant 'if a = b: . . .' No worries, I'm sure your unittests would have caught it. ;) ~Ethan~ Wouldn't the compiler have caught it before the unittests? :-) Silly me, the word processor would have caught it! ~Ethan~ +1 laugh of the week -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 17/07/2012 20:29, Lipska the Kat wrote: On 17/07/12 18:07, Terry Reedy wrote: On 7/17/2012 10:23 AM, Lipska the Kat wrote: Well 'type-bondage' is a strange way of thinking about compile time type checking and making code easier to read (and therefor debug snip How easy was it to write max, or a universal sort in Java? Well java.lang.Math.max() (or min() depending on what you want) might do it and as for sorting ... java.utils.Collections.sort will sort anything that implements the java.util.Comparable interface. All the standard numerical classes implement Comparable by default so there is nothing to do really. Lipska I would like to spend more time on this thread, but unfortunately the 44 ton artic carrying Java in a Nutshell Volume 1 Part 1 Chapter 1 Paragraph 1 Sentence 1 has just arrived outside my abode and needs unloading :-) -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 17/07/2012 19:43, Ethan Furman wrote: Mark Lawrence wrote: On 17/07/2012 18:29, Ethan Furman wrote: Terry Reedy wrote: On 7/17/2012 10:23 AM, Lipska the Kat wrote: Well 'type-bondage' is a strange way of thinking about compile time type checking and making code easier to read (and therefor debug 'type-bondage' is the requirement to restrict function inputs and output to one declared type, where the type declaration mechanisms are usually quite limited. def max(a, b): if a = b: return a return b Surely you meant 'if a = b: . . .' No worries, I'm sure your unittests would have caught it. ;) ~Ethan~ Wouldn't the compiler have caught it before the unittests? :-) Silly me, the word processor would have caught it! ~Ethan~ No compiler can find as many faults as publishing your code on a mailing list!!! :) Ian -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 17/07/12 20:39, Mark Lawrence wrote: On 17/07/2012 20:29, Lipska the Kat wrote: On 17/07/12 18:07, Terry Reedy wrote: On 7/17/2012 10:23 AM, Lipska the Kat wrote: snip How easy was it to write max, or a universal sort in Java? Well java.lang.Math.max() (or min() depending on what you want) might do it and as for sorting ... java.utils.Collections.sort will sort anything that implements the java.util.Comparable interface. All the standard numerical classes implement Comparable by default so there is nothing to do really. Lipska I would like to spend more time on this thread, but unfortunately the 44 ton artic carrying Java in a Nutshell Volume 1 Part 1 Chapter 1 Paragraph 1 Sentence 1 has just arrived outside my abode and needs unloading :-) :-))) LOL (and I did) but the pay is FANTASTIC, particularly if you 'get' OO. -- Lipska the Kat: Troll hunter, Sandbox destroyer and Farscape dreamer of Aeryn Sun. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.6 on Mac 10.7 doesn't work
In article 5005927a$0$6949$e4fe5...@news2.news.xs4all.nl, Hans Mulder han...@xs4all.nl wrote: On 17/07/12 15:47:05, Naser Nikandish wrote: I am trying to install Python 2.6 on Mac OS Lion. Here is what I did: 1- Download Mac Installer disk image (2.6) (sig) from http://www.python.org/getit/releases/2.6/ 2- Install it 3- Run Python Luncher, go to Python Luncher preferences, and change the interpreter to Library/Frameworks/Python.framework/Versions/2.6/bin/pythonw Now that I want to open IDLE and open my old projects, it doesn't run! Is there anything that I am missing? You may be missing a leading slash. The path to pythonw is /Library/Frameworks/Python.framework/Versions/2.6/bin/pythonw Also keep in mind that Python 2.6 has been moved to security-fix-only mode which, among other things, means that new binary installers for OS X are not being made. The most recent OS X binary installer was 2.6.6. The system Python in OS X 10.7 Lion is 2.6.7. There has been one additional security fix release for 2.6 (2.6.8) since then. If you need Python 2, you really should consider moving to Python 2.7, which is already at 2.7.3 and is fully maintained. (The most recent Python 3 release is 3.2.3, also fully maintained.) -- Ned Deily, n...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
RE: assertraises behaviour
On 17/07/2012 18:49, Prasad, Ramit wrote: import unittest class TestWithRaises(unittest.TestCase): def test_first(self): assert False def test_second(self): print(also called) assert True if __name__ == '__main__': unittest.main() in this case also the second test is run even if the first fails.. The reason for that is that the unit testing framework catches and handles the error. It calls both test functions in some unspecified order and logs the result. Calls to two separate test functions are thereby separated from each other. This is intentionally so, but I think you can also give the unit testing framework a flag that makes it abort after the first error. In no way will the exception escape from the unittest.main() call though, it is all caught and handled inside, also by intention. But that's probably easy because we just need to catch exceptions for every method call, so it's not exactly the same thing.. I don't understand what you want to say here. I also don't understand what your problem in general is. I guess there are some expectations which are not satisfied, but you haven't explained those explicitly yet. I think Andrea wants to do the same thing but with nose and not unittest. Ramit Do what? Like Ulrich Eckhart I simply don't understand what she's getting at. Perhaps it's a problem with Englsh being a second language issue rather than Python itself. Thankfully I'm sure that everything will come out in the wash. -- Cheers. Mark Lawrence. I get the impression that nose stops running tests once any test fails instead of running all tests and listing all the tests and their pass/fail status (like unittest). Granted that is just what I get from the context as I read it as I have no knowledge of nose. Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
multiprocessing: apply_async with different callbacks
Hi all, I'm having a strange behavior when executing the following script: --- import multiprocessing def f(i): return i p = multiprocessing.Pool() for i in range(20): def c(r): print r, i p.apply_async(f, (i,) , callback=c) p.close() p.join() --- Result: 0 6 1 11 2 13 3 15 4 15 5 19 etc It seems that the callbacks of all submitted tasks are being overridden with the last callback submitted by apply_async. Is this the right behaviour or I am stumbling in some issue? I'm using Python 2.7.3 @ Ubuntu 12.04 Regards, André smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: help needed with subprocess, pipes and parameters
nuffi, Have you tried running your piped commands c:\Programs\bob\bob.exe -x -y C:\text\path\to some\file.txt | c:\Programs\kate\kate.exe -A 2 --dc Print Media Is Dead --da Author --dt Title --hf Times --bb 14 --aa --font Ariel - C:\rtf\path\to some\file.rtf in a single instance of subprocess? Start it up and use the poll method to wait until the subprocess has terminated. Then open the output file to get the results. My recent (and single, hence limited, experience) of using subprocess indicated that the spawned process may take a little time to start up. Try bob = subprocess.Popen([bobPath, '-x', '-y', docpath], stdout = subprocess.PIPE,) time.sleep( 0.5 ) #experiment with the delay kate = subprocess.Popen([katePath, A, dc, da, dt, hf, fn, bb, path], stdin = bob.stdout, stdout = subprocess.PIPE,) Never looked under the subprocess hood but maybe there's a race condition with the kate subprocess starting before the bob subprocess has set up its stdout. It's unlikely but so easy to check with a sleep between the subprocesses it has to be worth a go. John On 13/07/2012 08:34, nuffi wrote: If I copy and paste the following command into a command window, it does what I need. c:\Programs\bob\bob.exe -x -y C:\text\path\to some\file.txt | c:\Programs\kate\kate.exe -A 2 --dc Print Media Is Dead --da Author --dt Title --hf Times --bb 14 --aa --font Ariel - C:\rtf\path\to some\file.rtf My mission is to recreate this command within a python script, so that I can pass a bunch of different parameters into it, and use it as a batch over a bunch of different papers. http://docs.python.org/library/subprocess.html seems to be the thing to use in python 2.7.3. I also checked out http://www.doughellmann.com/PyMOTW/subprocess/. My attempts run fine, create destination folders ok and prints done but don't actually seem to process the file. Is there some way to get subprocess to output the command it's generating so I can see what I'm doing wrong, rather than just the output of the command? How can I chekc that kate's opening the pipe left from bob?Bob may take some time to execute, will that matter? The code I came up with looks like this: import os, glob, subprocess sourceDir = c:\\text\\ destDir = c:\\rtf\\ bobPath = C:\\Programs\\bob\\bob.exe katePath = C:\\Programs\\kate\\kate.exe def get_new_path(doc): blah = doc.replace(sourceDir, destDir) if not os.path.isdir(blah): os.makedirs(blah) rtf = blah.replace('.txt', '.rtf') pathString = '- ' + (os.path.join(rtf)) + '' return(pathString) def convert_doc(doc): dc = '--dc Print Media Is Dead' da = '--da Author' dt = '--dt Title' hf = '--hf Times' fn = '--font Ariel' bb = '--bb 14' docpath = '' + (os.path.join(doc)) + '' path = get_new_path(doc) A = '-A 2' bob = subprocess.Popen([bobPath, '-x', '-y', docpath], stdout = subprocess.PIPE,) kate = subprocess.Popen([katePath, A, dc, da, dt, hf, fn, bb, path], stdin = bob.stdout, stdout = subprocess.PIPE,) end_of_pipe = kate.stdout #print kate #subprocess.call(['echo', Test peice of text, '', 'D:\\output.txt']) for line in end_of_pipe: print '\t', blah.strip() #raw_input() return('done') test = convert_doc(c:\\text\\path to\\some\\specific text file.txt) print(blah) == Thanks for looking :-) --- Posted via news://freenews.netfront.net/ - Complaints to n...@netfront.net --- -- http://mail.python.org/mailman/listinfo/python-list
Re: multiprocessing: apply_async with different callbacks
On 07/17/2012 11:44 PM, André Panisson wrote: Hi all, I'm having a strange behavior when executing the following script: --- import multiprocessing def f(i): return i p = multiprocessing.Pool() for i in range(20): def c(r): print r, i p.apply_async(f, (i,) , callback=c) p.close() p.join() --- Result: 0 6 1 11 2 13 3 15 4 15 5 19 etc It seems that the callbacks of all submitted tasks are being overridden with the last callback submitted by apply_async. Is this the right behaviour or I am stumbling in some issue? I'm using Python 2.7.3 @ Ubuntu 12.04 Regards, Sorry for taking the time, I just found the solution: --- import multiprocessing def f(i): return i def cfactory(i): def c(r): print r, i return c p = multiprocessing.Pool() for i in range(20): p.apply_async(f, (i,) , callback=cfactory(i)) p.close() p.join() -- Regards, André smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: assertraises behaviour
To clarify my problem, I just thought that assertRaises if used as context manager should behave as following: - keep going if the exception declared is raised - re-raise an error even if catched after the declared exception was catched I was also confused by the doc a bit: Test that an exception is raised when /callable/ is called with any positional or keyword arguments that are also passed to assertRaises() http://docs.python.org/library/unittest.html#unittest.TestCase.assertRaises. The test passes if /exception/ is raised, is an error if another exception is raised, or fails if no exception is raised which speaks about when it's not used as a context manager.. I understand why it's not possible and it's not a big issue though.. -- http://mail.python.org/mailman/listinfo/python-list
Foxpro goto command and deleted records
In Foxpro if you do a GOTO 7 with deleted off and record 7 is deleted, the record pointer doesn't move (at least in version 6). I don't like that. I see four other options: 0) don't move the pointer (listed for completeness) 1) go to that record anyway 2) go to the next undeleted record 3) go to the seventh undeleted record (possibly the least practical) 4) raise an exception Any opinions? ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Foxpro goto command and deleted records
On Tue, Jul 17, 2012 at 4:57 PM, Ethan Furman et...@stoneleaf.us wrote: In Foxpro if you do a GOTO 7 with deleted off and record 7 is deleted, the record pointer doesn't move (at least in version 6). I don't like that. I see four other options: 0) don't move the pointer (listed for completeness) 1) go to that record anyway 2) go to the next undeleted record 3) go to the seventh undeleted record (possibly the least practical) 4) raise an exception Any opinions? Relevance to Python? -- http://mail.python.org/mailman/listinfo/python-list
Re: Foxpro goto command and deleted records
On 17/07/2012 23:57, Ethan Furman wrote: In Foxpro if you do a GOTO 7 with deleted off and record 7 is deleted, the record pointer doesn't move (at least in version 6). I don't like that. I see four other options: 0) don't move the pointer (listed for completeness) 1) go to that record anyway 2) go to the next undeleted record 3) go to the seventh undeleted record (possibly the least practical) 4) raise an exception Any opinions? What happens when you 'delete' a record? Does it disappear immediately, or is it merely marked for deletion? If it is marked for deletion, can it be unmarked? Will a marked record be removed when the file is closed, or does the file need to be explicitly purged/compacted? If it is merely marked, then I think the best option is 1, or possibly 4 if the file is compacted when closed. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 17/07/2012 19:36, Lipska the Kat wrote: On 17/07/12 19:18, Mark Lawrence wrote: On 17/07/2012 18:29, Ethan Furman wrote: Terry Reedy wrote: On 7/17/2012 10:23 AM, Lipska the Kat wrote: Well 'type-bondage' is a strange way of thinking about compile time type checking and making code easier to read (and therefor debug 'type-bondage' is the requirement to restrict function inputs and output to one declared type, where the type declaration mechanisms are usually quite limited. def max(a, b): if a = b: return a return b Surely you meant 'if a = b: . . .' No worries, I'm sure your unittests would have caught it. ;) ~Ethan~ Wouldn't the compiler have caught it before the unittests? :-) Not unless the compiler could read your mind! The syntax looks fine it's the semantics that are suspect. Wrong is a word that I try not to use as it tends to upset people, let's call them differently right ;-) BTW having more than one return statement in a block is a little thing I know but it drives me nuts ... another Pythonic thing I'll have to get used to I suppose. Its not a pythonic thing. Its a common and very acceptable paradigm. Mainly, it avoids complicated breaks from nested control structures, and especially the 'style' of maintaining one boolean value called should_continue or something equally silly. My daily work involves C, x86 assembly, reading x86/PCI/ACPI/etc specifications and cursing violently at some of the stupidity, Python, Bash and C++, and this is one of the few styles which remains fairly constant throughout. Take for example a Linux system call handler. The general form looks a little like (substituting C for python style pseudocode) if not (you are permitted to do this): return -EPERM if not (you've given me some valid data): return -EFAULT if not (you've given me some sensible data): return -EINVAL return actually_try_to_do_something_with(data) How would you program this sort of logic with a single return statement? This is very common logic for all routines for which there is even the remotest possibility that some data has come from an untrusted source. ~Andrew P.S. like the sig. -- http://mail.python.org/mailman/listinfo/python-list
Re: Implicit conversion to boolean in if and while statements
On Jul 17, 6:23 pm, Andrew Berg bahamutzero8...@gmail.com wrote: On 7/17/2012 2:08 AM, Steven D'Aprano wrote: The default behaviour is that every object is something, hence true-like, unless explicitly coded to be treated as false-like. Since both loggers and functions are objects, they are true-like unless the default is overridden. I am aware of the default behavior, but the reason for it still eludes me. Because it makes it simple to distinguish between having an object and not having one without having to explicitly test for it each time. db = connect(my:db) # or None if the connection failed if db: do something I find that usage to be incredibly intuitive. -- http://mail.python.org/mailman/listinfo/python-list
my email
mmdionisio1...@yahoo.com.ph Just a newbhie here : From: python-list-requ...@python.org python-list-requ...@python.org To: mmdionisio1...@yahoo.com.ph Sent: Saturday, July 7, 2012 7:41 PM Subject: Welcome to the Python-list mailing list Welcome to the Python-list@python.org mailing list! The purpose of this mailing list is to support general discussions about the Python programming language. Please remember that this list is mirrored to the Usenet newsgroup comp.lang.python. For more information on the Python programming language see lt;http://www.python.org/ To post to this list, send your email to: python-list@python.org General information about the mailing list is at: http://mail.python.org/mailman/listinfo/python-list If you ever want to unsubscribe or change your options (eg, switch to or from digest mode, change your password, etc.), visit your subscription page at: http://mail.python.org/mailman/options/python-list/mmdionisio1993%40yahoo.com.ph You can also make such adjustments via email by sending a message to: python-list-requ...@python.org with the word `help' in the subject or body (don't include the quotes), and you will get back a message with instructions. You must know your password to change your options (including changing the password, itself) or to unsubscribe. It is: sweet103093 Normally, Mailman will remind you of your python.org mailing list passwords once every month, although you can disable this if you prefer. This reminder will also include instructions on how to unsubscribe or change your account options. There is also a button on your options page that will email your current password to you.-- http://mail.python.org/mailman/listinfo/python-list
Re: Foxpro goto command and deleted records
Ian Kelly wrote: On Tue, Jul 17, 2012 at 4:57 PM, Ethan Furman et...@stoneleaf.us wrote: In Foxpro if you do a GOTO 7 with deleted off and record 7 is deleted, the record pointer doesn't move (at least in version 6). I don't like that. I see four other options: 0) don't move the pointer (listed for completeness) 1) go to that record anyway 2) go to the next undeleted record 3) go to the seventh undeleted record (possibly the least practical) 4) raise an exception Any opinions? Relevance to Python? I'm deciding how my python dbf module will handle this situation. http://python.org/pypi/dbf for the curious. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Foxpro goto command and deleted records
MRAB wrote: On 17/07/2012 23:57, Ethan Furman wrote: In Foxpro if you do a GOTO 7 with deleted off and record 7 is deleted, the record pointer doesn't move (at least in version 6). I don't like that. I see four other options: 0) don't move the pointer (listed for completeness) 1) go to that record anyway 2) go to the next undeleted record 3) go to the seventh undeleted record (possibly the least practical) 4) raise an exception Any opinions? What happens when you 'delete' a record? Does it disappear immediately, or is it merely marked for deletion? Marked for deletion. If it is marked for deletion, can it be unmarked? Will a marked record be removed when the file is closed, or does the file need to be explicitly purged/compacted? Yes, it can be unmarked. No, the table must be explicitly packed. If it is merely marked, then I think the best option is 1, or possibly 4 if the file is compacted when closed. There is a use_deleted setting that controls whether deleted records are accessed or skipped. Skipping is fine when looping, not so fine when going directly to a particular record. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: my email
On 18/07/12 11:44, Maria Hanna Carmela Dionisio wrote: mmdionisio1...@yahoo.com.ph Just a newbhie here : [snip] You must know your password to change your options (including changing the password, itself) or to unsubscribe. It is: sweet103093 I suggest you change you password now that you have told the world what it is. -- Cheers Simon Simon Cropper - Open Content Creator Free and Open Source Software Workflow Guides Introduction http://www.fossworkflowguides.com GIS Packages http://www.fossworkflowguides.com/gis bash / Pythonhttp://www.fossworkflowguides.com/scripting -- http://mail.python.org/mailman/listinfo/python-list
Re: Style question: metaclass self vs cls?
On Tue, 17 Jul 2012 05:23:22 -0700, Michele Simionato wrote: The standard is to use `cls`. In the __new__ method you can use `mcl` or `meta`. Thanks to everyone who answered. I think I will stick with meta and cls. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Foxpro goto command and deleted records
On 18/07/2012 03:19, Ethan Furman wrote: MRAB wrote: On 17/07/2012 23:57, Ethan Furman wrote: In Foxpro if you do a GOTO 7 with deleted off and record 7 is deleted, the record pointer doesn't move (at least in version 6). I don't like that. I see four other options: 0) don't move the pointer (listed for completeness) 1) go to that record anyway 2) go to the next undeleted record 3) go to the seventh undeleted record (possibly the least practical) 4) raise an exception Any opinions? What happens when you 'delete' a record? Does it disappear immediately, or is it merely marked for deletion? Marked for deletion. If it is marked for deletion, can it be unmarked? Will a marked record be removed when the file is closed, or does the file need to be explicitly purged/compacted? Yes, it can be unmarked. No, the table must be explicitly packed. If it is merely marked, then I think the best option is 1, or possibly 4 if the file is compacted when closed. There is a use_deleted setting that controls whether deleted records are accessed or skipped. Skipping is fine when looping, not so fine when going directly to a particular record. If use_deleted is false, does that mean that deleted records are hidden, or just that when iterating through the records the deleted ones aren't yielded? -- http://mail.python.org/mailman/listinfo/python-list
Re: jython lacks working xml processing modules?
在 2012年7月17日星期二UTC+8下午6时02分31秒,Stefan Behnel写道: Matej Cepl, 17.07.2012 11:39: gt; On 17/07/12 10:35, gaodexiaozh...@gmail.com wrote: gt;gt;gt; amp;gt; Iamp;#39;m trying to parse an xml file with jython (not through java gt;gt;gt; parsers gt;gt;gt; amp;gt; like xerces). gt; gt; https://code.google.com/p/jython-elementtree/ ??? Note that this ships with Jython 2.5. Stefan Got that,thanks! However,there is one project implemented by Python used PyXML and now my Jython project has to depend on it ,so I am afraid that if Jython doesn't support PyXML,then my jython project can not depend on the original Python project ,then my jython project maybe can not move on unless I find another project to take place of the original Python project. -- http://mail.python.org/mailman/listinfo/python-list
Re: Foxpro goto command and deleted records
MRAB wrote: On 18/07/2012 03:19, Ethan Furman wrote: MRAB wrote: On 17/07/2012 23:57, Ethan Furman wrote: In Foxpro if you do a GOTO 7 with deleted off and record 7 is deleted, the record pointer doesn't move (at least in version 6). I don't like that. I see four other options: 0) don't move the pointer (listed for completeness) 1) go to that record anyway 2) go to the next undeleted record 3) go to the seventh undeleted record (possibly the least practical) 4) raise an exception Any opinions? What happens when you 'delete' a record? Does it disappear immediately, or is it merely marked for deletion? Marked for deletion. If it is marked for deletion, can it be unmarked? Will a marked record be removed when the file is closed, or does the file need to be explicitly purged/compacted? Yes, it can be unmarked. No, the table must be explicitly packed. If it is merely marked, then I think the best option is 1, or possibly 4 if the file is compacted when closed. There is a use_deleted setting that controls whether deleted records are accessed or skipped. Skipping is fine when looping, not so fine when going directly to a particular record. If use_deleted is false, does that mean that deleted records are hidden, or just that when iterating through the records the deleted ones aren't yielded? Definitely the latter, but I'm starting to wonder if the former should also be the case. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On Jul 18, 5:46 am, Andrew Cooper am...@cam.ac.uk wrote: On 17/07/2012 19:36, Lipska the Kat wrote: On 17/07/12 19:18, Mark Lawrence wrote: On 17/07/2012 18:29, Ethan Furman wrote: Terry Reedy wrote: On 7/17/2012 10:23 AM, Lipska the Kat wrote: Well 'type-bondage' is a strange way of thinking about compile time type checking and making code easier to read (and therefor debug 'type-bondage' is the requirement to restrict function inputs and output to one declared type, where the type declaration mechanisms are usually quite limited. def max(a, b): if a = b: return a return b Surely you meant 'if a = b: . . .' No worries, I'm sure your unittests would have caught it. ;) ~Ethan~ Wouldn't the compiler have caught it before the unittests? :-) Not unless the compiler could read your mind! The syntax looks fine it's the semantics that are suspect. Wrong is a word that I try not to use as it tends to upset people, let's call them differently right ;-) BTW having more than one return statement in a block is a little thing I know but it drives me nuts ... another Pythonic thing I'll have to get used to I suppose. Its not a pythonic thing. Its a common and very acceptable paradigm. Mainly, it avoids complicated breaks from nested control structures, and especially the 'style' of maintaining one boolean value called should_continue or something equally silly. My daily work involves C, x86 assembly, reading x86/PCI/ACPI/etc specifications and cursing violently at some of the stupidity, Python, Bash and C++, and this is one of the few styles which remains fairly constant throughout. Take for example a Linux system call handler. The general form looks a little like (substituting C for python style pseudocode) if not (you are permitted to do this): return -EPERM if not (you've given me some valid data): return -EFAULT if not (you've given me some sensible data): return -EINVAL return actually_try_to_do_something_with(data) How would you program this sort of logic with a single return statement? This is very common logic for all routines for which there is even the remotest possibility that some data has come from an untrusted source. return (-EPERM if not_permitted else -EFAULT if non_valid else -EINVAL if non_sensible else do_something) Not that I recommend *doing* this :-) [I recommend knowing about it] -- http://mail.python.org/mailman/listinfo/python-list
[issue15358] Test pkgutil.walk_packages in test_pkgutil instead of test_runpy
Chris Jerdonek chris.jerdo...@gmail.com added the comment: I'd like to work on this if that's okay. I've already written test cases for issue 7559 and issue 15299 that required creating temporary packages, so I understand the need. And I'd also like to create test cases for issue 14787, which should really be done after this. I think this should be split into two parts though: (1) refactor the create-package code in test_runpy into a separate helper module, and (2) move the refactored walk_package tests from test_runpy into test_pkgutil (so it's easier to see what has changed). I can create a new issue for (1). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15358 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue15376] Refactor the create-package code in test_runpy into a helper module
New submission from Chris Jerdonek chris.jerdo...@gmail.com: This issue is to refactor the create-package code in test_runpy into a helper module, as suggested in issue 15358. This is a prerequisite to moving the pkgutil.walk_package() tests from test_runpy into test_pkgutil. -- components: Tests keywords: easy messages: 165683 nosy: cjerdonek, ncoghlan priority: normal severity: normal status: open title: Refactor the create-package code in test_runpy into a helper module versions: Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue15358] Test pkgutil.walk_packages in test_pkgutil instead of test_runpy
Changes by Chris Jerdonek chris.jerdo...@gmail.com: -- dependencies: +Refactor the create-package code in test_runpy into a helper module ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15358 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue15374] venv environment variable should follow the conventions
Antoine Pitrou pit...@free.fr added the comment: Yes, there are a number of third-party utility packages (and many, many e.g. personal custom bash prompts) that check the value of the $VIRTUAL_ENV variable to detect whether one is currently active, and display its name. Unless there's an overriding reason, it would be nice to not require changing all of this code. Ok, it sounds reasonable enough. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15374 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com