An open source AI research project
Hello! I have started an open source project to develop human-level Artificial Intelligence, using Python and Java as programming language, OpenCog and OpenWonderland as basement. If you are interested in this,or want to know more, please feel free to give me a reply. Thanks! David Zhang -- http://mail.python.org/mailman/listinfo/python-list
Re: Reactive programming in Python ?
On Apr 17, 8:09 am, Stefan Behnel wrote: > pca, 16.04.2010 22:02: > > > On Apr 16, 8:28 pm, Stefan Behnel wrote: > >> pca, 16.04.2010 17:18: > > >>> In fact, I have seeded an open-source project, Yoopf, that enables > >>> programming by formula within Python, with the goal of dramatically > >>> accelerating the development of the model view in the MVC model. > > >> Looks like the example on the main page would work better with the "any" > >> builtin than with the "sum" builtin. > > > I'm not sure what you mean. The example formula in the main page of > >http://www.yoopf.orgcalculates the total amount of an order as the > > sum of the amount of each order line: why the 'any' ? > > I guess I misinterpreted the phrase "only when one of its order line has > been added or deleted" as meaning that a change to any of the amounts would > trigger an event. It wasn't clear to me that the example actually presented > a calculation that would be evaluated based on that event. > > You might want to give potential users a better idea of what this tool > does. Neither your announcement nor the homepage made that clear to me. > > Stefan Thanks for the feedback, Stefan. I have rephrased the sentence as follows. Is that more clear ? "For example, this formula is fed to the library to define the total amount of each Order object as the sum of the amount of its order line: "Order.amount = sum(Order.order_lines.amount) "At the end of a transaction, the formula calculator is run : it will calculate the formula only for the Order objects that need recalculation (e.g because one of its order line has been added or deleted, or the amount of a line has been changed). Thanks. Pierre C. -- http://mail.python.org/mailman/listinfo/python-list
Re: extract substring by regex from a text file
On Apr 15, 3:25 pm, Neil Cerutti wrote: > On 2010-04-15, Alessio wrote: > > > Hi, > > > I'm facing the problem in the subject: > > - I have a text file that I need to parse for producing a specifical Thank you, I forgot to say that I already solved. I used readlines() to read my text file, then with a for cicle I extract line by line the substrings I need by regular expressions (re.findall()) ciao > > string (Json like) extracting some information (substring) in it; > > - I created regural expressions capable to locate these substrings in > > my txt file; > > > now I don't know how to continue. What is the best way to locate some > > string in a file and output them (with print command or in another > > file)? > > grep > > Or: show your work. > > -- > Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: extract substring by regex from a text file
Alessio, 17.04.2010 10:19: I used readlines() to read my text file, then with a for cicle I extract line by line the substrings I need by regular expressions (re.findall()) Note that it's usually more efficient to just run the for-loop over the file object, rather than using readlines() first. The latter will read all lines into a big list in memory before doing any further processing, whereas the plain for-loop will read line by line and let the loop body act on each line immediately. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: extract substring by regex from a text file
Alessio wrote: > I used readlines() to read my text file, then with a for cicle I > extract line by line the substrings I need by regular expressions Just in case you didn't know: for line in instream: ... looks better, uses less memory, and may be a tad faster than for line in instream.readlines(): ... Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Incorrect scope of list comprehension variables
Steven D'Aprano wrote: On Fri, 16 Apr 2010 08:48:03 -0700, Aahz wrote: In article <4bb92850$0$8827$c3e8...@news.astraweb.com>, Steven D'Aprano wrote: Nevertheless, it is a common intuition that the list comp variable should *not* be exposed outside of the list comp, and that the for-loop variable should. Perhaps it makes no sense, but it is very common -- I've never heard of anyone being surprised that the for-loop variable is exposed, but I've seen many people surprised by the fact that list-comps do expose their loop variable. I've definitely seen people surprised by the for-loop behavior. What programming languages were they used to (if any)? I don't know of any language that creates a new scope for loop variables, but perhaps that's just my ignorance... It's not clear whether a language like C or C++ has "loop variables." It just has variables with varying scope depending on where they're declared. And you can add extra braces with the sole purpose being to introduce new variable scoping. But two things that changed as C evolved were where you could introduce new variables, and the lifetime of variables introduced in the loop control structure, rather than inside the braces. The first change was in C++ from the start, but I think the second change was also an evolution in C++. 1) In original C, all declarations in a given scope had to occur before any executable code began. For example, the following was illegal: int a=12, b=42; myfunc(a, b); int c = 9; /* illegal */ 2) In original C, and I think in C++, the lifetime of i lasted long after the loop ended. for (int i=0; i< limit; ++i) { z += i; } i is still valid after this curly brace In C99, and at least in later C++, the scope of i ends with the curly, as though there were another invisible pair of braces: { for (int i=0; i< limit; ++i) { z += i; }} i is no longer valid here Because C and C++ have explicit declarations, people who need the loop variable after the loop is done can simply declare the loop variable before the for statement. DaveA -- http://mail.python.org/mailman/listinfo/python-list
class instance customization
Hi, list. I've some nontrivial class implementation MyClass and its instance my: my = MyClass(args) MyClass uses in internals some variable which is not defined in MyClass itself. I want to extend instance of MyClass at runtime defining this variable and making new instance. It is like a class inheritance in a static way class MyNewClass(MyClass): def __init__(s, a): s._variable = a but this doesn't give me ability to make inheritance at runtime of the single parent intance. Finaly this should look like this my = MyClass(args) a1 = my.new(1) a2 = my.new(2) and e.t.c. Is it possible to release this interface in python? -- http://mail.python.org/mailman/listinfo/python-list
Re: Incorrect scope of list comprehension variables
Steven D'Aprano writes: > On Fri, 16 Apr 2010 08:48:03 -0700, Aahz wrote: > >>>Nevertheless, it is a common intuition that the list comp variable >>>should *not* be exposed outside of the list comp, and that the for-loop >>>variable should. Perhaps it makes no sense, but it is very common -- >>>I've never heard of anyone being surprised that the for-loop variable is >>>exposed, but I've seen many people surprised by the fact that list-comps >>>do expose their loop variable. >> >> I've definitely seen people surprised by the for-loop behavior. > > What programming languages were they used to (if any)? > > I don't know of any language that creates a new scope for loop variables, > but perhaps that's just my ignorance... I think Pascal and Modula-2 do this, Fortran does this, as well as Ada. I'm sure derivatives of Ada like Oracle's PL/SQL also enforce this. And of course C/C++/Java if the programmer wants it that way. Actually I think C was the first to consider "for" as some kind of syntactic sugar for "while" (thus blurring the notion of a for-loop forever). Python's for is really a member of the for-each family. May I add that having strict for-loop iterators is a good thing, at least in languages like C/C++/Fortran/etc. Optimizing compilers usually spend some time detecting so-called "induction variables" when they're not given: it helps simplifying loop bodies, it reduces register pressure, and changes many array accesses into pointer increments, among other things. -- Alain. -- http://mail.python.org/mailman/listinfo/python-list
Re: cross-platform coloured text in terminal
On Apr 16, 5:59 pm, Lie Ryan wrote: > On 04/16/10 19:28, Jonathan Hartley wrote: > > > I'm playing with ideas of what API to expose. My favourite one is to > > simply embed ANSI codes in the stream to be printed. Then this will > > work as-is on Mac and *nix. To make it work on Windows, printing could > > be done to a file0-like object which wraps stdout: > > The problem with that is you're simply reinventing ANSI.SYS device driver. > > An alternative API is you could override .__add__(), like so (completely > untested): > > class Color(object): > def __init__(self, color): > self.color = map_the_color(color) > self.string = "" > def __add__(self, string): > self.string += string > return self > def __str__(self): > if terminal_can_do_ansi_color: > return ansicolorescape(self.string, self.color) > elif windows: > syscalltocolor(self.color) > print self.string > syscalltocolor(reset the color) > return "" > > GREEN = Color('green') > print GREEN + "Great" + "Good" > > you can even go a bit further and allow chained calls (again, completely > untested, but you get the idea): > > class Color(object): > def __init__(self, color): > self.color = map_the_color(color) > self.stack = [] > def __add__(self, string): > if isinstance(string, Color): > # not a string, chain the calls > self.stack.append((string.color, []])) > else: > # a string, > self.stack[-1][1].append(string) > return self > def __radd__(self, string): > self.stack.append([self.default, string]) > return self > > def __str__(self): > if ansi_capable: > return colorescape(format, string) > elif windows: > for format, string in self.stack: > syscalltocolor(color) > print string > return "" > > GREEN = Color('green') > RED = Color('red') > > print "Fairly" + GREEN + "Great" + RED + "Poor" > > or something like that, and you will have an API that works > transparently on all platforms. The downside is that you cannot call > str(GREEN + "foo") on windows. Hey Lie, Thanks heaps for the reply! >> The problem with that is you're simply reinventing ANSI.SYS device driver. I don't see that as a problem - in fact I think it's exactly my goal! :-) The difference is that the ANSI driver requires installation and a reboot on the end-user's computer, which is a fiddly and intrusive thing for a Python developer to achieve. Whereas doing the same job in a Python module is easy to use for the Python developer - they just import the module, maybe call an 'init()' function, and then the ANSI functionality works on all platforms. Your ideas about generating and chaining the ANSI code strings are great. I worry though, about intermingling the code that generates ANSI escape sequences with the code which makes them work on Windows. The problem is that then, only applications which use your ANSI- generation library will work on Windows. Whereas if these two things are kept separate, then applications which use any other ANSI- generation techniques, such as using 'termcolor', or manaully printing raw ANSI sequences, these can also all work on Windows too, simply by adding an import and an 'init()' call to the start of the application. Am I making sense? Many thanks for your thoughts. Jonathan -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating a standalone application
In message , Jonathan Hartley wrote: > On Apr 13, 10:42�pm, Lawrence D'Oliveiro > wrote: > >> In message , Luis Quesada wrote: >> >> > I am getting an "expected string without null bytes" error when using >> > cxfreeze for creating a standalone application (in Linux-Ubuntu). >> >> Why bother? Every decent Linux system will have Python available. Why not >> just distribute it as a script? > > Anything other than a trivial script will have dependencies. These > might be other Python packages, C-extensions, and other libraries. > What if your program runs on a version of Python other than the one > installed on the client's Linux system? Let the distro maintainers worry about that. They will package your code up in the appropriate form, so that the system package manager will automatically ensure that the right dependencies are present. Problem solved, no need to keep reinventing the wheel. -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating a standalone application
In message <4bc4ec17.3040...@4c.ucc.ie>, Luis Quesada wrote: > Lawrence D'Oliveiro wrote: > >> In message , Luis Quesada wrote: >> >>> I am getting an "expected string without null bytes" error when using >>> cxfreeze for creating a standalone application (in Linux-Ubuntu). >> >> Why bother? Every decent Linux system will have Python available. Why not >> just distribute it as a script? > > Well every decent Linux system will have Java available too ... Questionable. Java doesn’t seem to be of much importance in the mass market, it seems to be primarily for corporate use. -- http://mail.python.org/mailman/listinfo/python-list
Re: when should I explicitly close a file?
In message , gelonida wrote: > I've been told, that following code snippet is not good. > > open("myfile","w").write(astring) ... I do that for reads, but never for writes. For writes, you want to give a chance for write errors to raise an exception and alert the user, instead of failing silently, to avoid inadvertent data loss. Hence the explicit close. -- http://mail.python.org/mailman/listinfo/python-list
Re: Striving for PEP-8 compliance
On 04/17/10 16:20, Gregory Ewing wrote: > Steven D'Aprano wrote: >> On Wed, 14 Apr 2010 22:10:28 +0200, Hans Mulder wrote: >> >> Anybody who invents another brace-delimited language should be beaten. You always end up with a big problem trying to make sure the braces are consistent with the program logic. >>> >>> Anybody who invents another programming language should be beaten. You >>> always end up with a big problem trying to make sure the program logic >>> is consistent with the customers's needs :-( >> >> >> Anyone who invents another program should be beaten. You always end up >> with a big problem trying to make sure the program logic is consistent >> with what the customer thinks they need. > > Anyone who takes on new customers should be beaten. You always end up > with a big problem trying to make sure that what the customer thinks > they need is what they actually need. Anyone who makes another joke about anyone who need to be beaten needs to be beaten. You always end up with a big problem with angry bruised people wondering why they get beaten up. -- http://mail.python.org/mailman/listinfo/python-list
Re: when should I explicitly close a file?
On 04/17/10 21:23, Lawrence D'Oliveiro wrote: > In message > , gelonida > wrote: > >> I've been told, that following code snippet is not good. >> >> open("myfile","w").write(astring) ... > > I do that for reads, but never for writes. > > For writes, you want to give a chance for write errors to raise an exception > and alert the user, instead of failing silently, to avoid inadvertent data > loss. Hence the explicit close. In short, in case of doubt, just be explicit. Since in python nothing is guaranteed about implicit file close, you must always explicitly close it. -- http://mail.python.org/mailman/listinfo/python-list
My first project
This is my first large-scale (sort of) project in python. It is still under daily development, but the core is pretty stable (although, I'm still adding features). Here's the code: http://github.com/Poincare/PyEventLoop or http://code.google.com/p/pyeventloop/ Tell me what you guys think of it (I'll be adding more examples by the end of the day). -- http://mail.python.org/mailman/listinfo/python-list
Re: cross-platform coloured text in terminal
That sounds like a nice idea, try it out and see what you make of it. (It may have been done before but probably not as a standalone module as it doesn't require that much code) On Sat, Apr 17, 2010 at 6:52 AM, Jonathan Hartley wrote: > On Apr 16, 5:59 pm, Lie Ryan wrote: > > On 04/16/10 19:28, Jonathan Hartley wrote: > > > > > I'm playing with ideas of what API to expose. My favourite one is to > > > simply embed ANSI codes in the stream to be printed. Then this will > > > work as-is on Mac and *nix. To make it work on Windows, printing could > > > be done to a file0-like object which wraps stdout: > > > > The problem with that is you're simply reinventing ANSI.SYS device > driver. > > > > An alternative API is you could override .__add__(), like so (completely > > untested): > > > > class Color(object): > >def __init__(self, color): > >self.color = map_the_color(color) > >self.string = "" > >def __add__(self, string): > >self.string += string > >return self > >def __str__(self): > >if terminal_can_do_ansi_color: > >return ansicolorescape(self.string, self.color) > >elif windows: > >syscalltocolor(self.color) > >print self.string > >syscalltocolor(reset the color) > >return "" > > > > GREEN = Color('green') > > print GREEN + "Great" + "Good" > > > > you can even go a bit further and allow chained calls (again, completely > > untested, but you get the idea): > > > > class Color(object): > >def __init__(self, color): > >self.color = map_the_color(color) > >self.stack = [] > >def __add__(self, string): > >if isinstance(string, Color): > ># not a string, chain the calls > >self.stack.append((string.color, []])) > >else: > ># a string, > >self.stack[-1][1].append(string) > >return self > >def __radd__(self, string): > >self.stack.append([self.default, string]) > >return self > > > >def __str__(self): > >if ansi_capable: > >return colorescape(format, string) > >elif windows: > >for format, string in self.stack: > >syscalltocolor(color) > >print string > >return "" > > > > GREEN = Color('green') > > RED = Color('red') > > > > print "Fairly" + GREEN + "Great" + RED + "Poor" > > > > or something like that, and you will have an API that works > > transparently on all platforms. The downside is that you cannot call > > str(GREEN + "foo") on windows. > > > > Hey Lie, > > Thanks heaps for the reply! > > >> The problem with that is you're simply reinventing ANSI.SYS device > driver. > > I don't see that as a problem - in fact I think it's exactly my > goal! :-) > > The difference is that the ANSI driver requires installation and a > reboot on the end-user's computer, which is a fiddly and intrusive > thing for a Python developer to achieve. Whereas doing the same job in > a Python module is easy to use for the Python developer - they just > import the module, maybe call an 'init()' function, and then the ANSI > functionality works on all platforms. > > Your ideas about generating and chaining the ANSI code strings are > great. I worry though, about intermingling the code that generates > ANSI escape sequences with the code which makes them work on Windows. > The problem is that then, only applications which use your ANSI- > generation library will work on Windows. Whereas if these two things > are kept separate, then applications which use any other ANSI- > generation techniques, such as using 'termcolor', or manaully printing > raw ANSI sequences, these can also all work on Windows too, simply by > adding an import and an 'init()' call to the start of the application. > > Am I making sense? Many thanks for your thoughts. > > Jonathan > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Calling a class method
I have the following script: class TTT(object): def duplica(self): self.data *= 2 def __init__(self, data): self.data = data TTT.duplica(self.data) def __str__(self): return str(self.data) print obj=TTT(7) print obj And I want 14 printed (twice 7) I got the following error: TypeError: unbound method duplica() must be called with TTT instance as first argument (got int instance instead) What am I doing wrong? -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling a class method
On Sat, Apr 17, 2010 at 11:09 PM, vsoler wrote: > I have the following script: > > class TTT(object): >def duplica(self): >self.data *= 2 >def __init__(self, data): >self.data = data >TTT.duplica(self.data) > You're calling duplica with the class, and not by its object (self). self.duplica() will do what you want. Cheers, Xav > > And I want 14 printed (twice 7) > > I got the following error: > TypeError: unbound method duplica() must be called with TTT instance > as first argument (got int instance instead) > > What am I doing wrong? > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Can someone please make it more pythonic or better?
Greetings Python superstars, I've a directory structure like following tests / __init__.py testfile.py testfile.py contains following code import unittest class Calculator(unittest.TestCase): def test_add(self): print 'just add' def test_divide(self): print 'diviide' def test_multiply(self): print 'mul' class Car(unittest.TestCase): def test_start(self): print 'start' def test_move_right(self): print 'move right' def test_move_left(self): print 'move left' def test_stop(self): print 'stop' Now give the following user-input I want to get all test-names. user-input = tests.testfile (get all test-names from all unittest.TestCase derived classes in test.testfile) user-input = tests.testfile.Car (get all test-names from the Car class) user-input = tests.testfile.Cacr.test_stop and I'm doing it this the following way and I really think there has to be more readable, more pythonic and more possibly short way to do it import unittest import sys import inspect def get_test_names(full_name,module): name = full_name.split('.') loader = unittest.TestLoader() if len(name) == 4: return full_name elif len(name) == 3: exec "from %s.%s import %s" %(module,name[1],name[2]) return loader.getTestCaseNames(eval(name[2])) elif len(name) == 2: exec 'from %s import %s' % (module,name[1]) tests = [] for _name, obj in inspect.getmembers(sys.modules[full_name]): if inspect.isclass(obj) and issubclass(obj,unittest.TestCase): exec "from %s.%s import %s" % (module,name[1],obj.__name__) tests.append(loader.getTestCaseNames(obj)) return tests if __name__ == "__main__": input = "tests.testfile" module = input.split('.')[0] _tests = get_test_names(input,module) print _tests So guys, can you kindly point me to a more Pythonic, more readable and possible more short way to acheive this? I will really appreciate any help. Many thanks in advance. Best regards, Oltmans -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling a class method
On Sat, 17 Apr 2010 06:09:21 -0700 (PDT) vsoler wrote: > I got the following error: > TypeError: unbound method duplica() must be called with TTT instance > as first argument (got int instance instead) > > What am I doing wrong? Not reading the error message. You need to create a TTT instance and call your method from that: inst = TTT() inst.duplica(7) I notice you ask a lot of very basic beginner questions. While there is nothing wrong with being a beginner and asking questions, I think you should read more introductory material and tutorials. Concerning classes, pick one of the following that you like: http://www.google.com/search?ie=UTF-8&q=python%20classes%20introduction (Yes I am teasing you a bit ;) ) Also, maybe you'd like to post to the tutor list[1], which is (to my understanding) intended for just this kind of question. [1]: http://mail.python.org/mailman/listinfo/tutor best /W -- INVALID? DE! -- http://mail.python.org/mailman/listinfo/python-list
Re: How to run program in Linux
Dave Angel wrote: Jim Byrnes wrote: Dave Angel wrote: Jim Byrnes wrote: I am just learning Python and am new to Linux so I am probably doing something to trip myself up. I am trying to run an example GUI program that fetches a record from a database. All the files are in the same folder. The program runs but its results vary depending on how I started it. If I run it from the terminal or Idle, I enter a key and the program fetches the proper record. If I run it from Nautilis or a panel launcher, I enter the proper key and I get an error message saying the key does not exist. I am assuming that I am having path issues but don't know how to correct it. Thamks, Jim Presumably you're also new to mailing lists. Not really. At an absolute minimum when you describe an error, PASTE the error message, complete with traceback, into your message. As it stands, I'm left wondering which key on your keyboard can possibly "not exist." Perhaps it's a non-ASCII code, and you're getting some encoding error. That's a common discrepancy between running from a terminal and running from some GUI. The error was generated by the program, not Python. The 'key' I was referring to was a dictionary type key, not a physical one on the keyboard. Even better is to specify the version of Python this program is presumably written in, and what Linux distro. Then you say it's a GUI program, so you should specify which GUI library you're using. Python 2.6, Ubuntu 9.10, tkinter Now if I do a bunch of guessing, I might come up with the likelihood that your "Nautilus" is supplying a different current directory than the one the script is located in. You can find that out by looking at: os.path.abspath(os.curdir) OK, thanks. If that is the case how do I correct it? But of course how you print that depends on what GUI package you're running. DaveA Regards, Jim You forgot to include the list in your reply. Try using reply-all instead. If you determine that the current directory is your problem, and that Nautilus isn't setting it the way you'd like, then you may have to resort to other ways to identify the other files you mention. Easiest way might be to use the __file__ attribute of each module, which gives its complete path. So your code in the main script could do something like (untested): target = os.path.dirname(__file__) os.chdir(target) I added target = os.path.dirname(__file__) and printed the result. If I run the script in Idle it produces the correct result and shows the path as /usr/bin. Running it form the terminal produces the correct result but shows the path empty. Running it from Nautilus or a launcher does not produce the correct result and shows the full path to the directory that contains the script and its files. If I add os.chdir(target) to the script, Idle and the terminal stop producing the correct result and the launcher and Nautilius start producing the correct result. This is exactly the opposite of what I expected. Better is usually to ignore current directory, and passed the desired directory name into whatever function is going to use it. I'll keep this in mind for anything I write. Right now I'm trying to understand some examples that were produced in a Windows environment. Like I said at the top I am new to Linux (Ubuntu) and don't fully understand its requirements. HTH, DaveA Thanks, Jim -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling a class method
On Sat, 17 Apr 2010 06:09:21 -0700 (PDT) vsoler wrote: > [snip actual question] Oh and a note on vocabulary: A "class method" is a somewhat advanced topic and quite probably not what you want here. They are not used very often. What I proposed in the other post was an "instance method", which is usually what one means by the bare word "method". I think you should familiarize yourself with this concept (that is, just plain Python object oriented programming with classes and instances), before delving into more arcane stuff such as class methods. /W -- INVALID? DE! -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling a class method
On Sat, 17 Apr 2010 15:44:56 +0200 Andreas Waldenburger wrote: > On Sat, 17 Apr 2010 06:09:21 -0700 (PDT) vsoler > wrote: > > > I got the following error: > > TypeError: unbound method duplica() must be called with TTT instance > > as first argument (got int instance instead) > > > > What am I doing wrong? > > Not reading the error message. > > [snip rest of my response] > No wait. I misread your code. Sorry. There are two problems with this line: TTT.duplica(self.data) It should read self.duplica() Then it should work. It may be a nice exercise for you to work out why the code needs to be changed like that. On top of that, perhaps you'd like to think about why you thought it should be "TTT.duplica(self.data)". Comparing that to the correct way should be very beneficial to you understanding of the matter. If you like you can post your thoughts here to verify them. All my comments about reading tutorials and posting to python-tutor still apply, however. [Sidenote: What's that lone print statement above "obj=TTT(7)" supposed to do?] /W -- INVALID? DE! -- http://mail.python.org/mailman/listinfo/python-list
Re: An open source AI research project
On 17 April 2010 09:03, David Zhang wrote: > I have started an open source project to develop human-level > Artificial Intelligence... Have you people never seen Terminator? Sheesh. -- Cheers, Simon B. -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling a class method
On Sat, 17 Apr 2010 15:44:56 +0200, Andreas Waldenburger wrote: > On Sat, 17 Apr 2010 06:09:21 -0700 (PDT) vsoler > wrote: > >> I got the following error: >> TypeError: unbound method duplica() must be called with TTT instance as >> first argument (got int instance instead) >> >> What am I doing wrong? > > Not reading the error message. > > You need to create a TTT instance and call your method from that: > > inst = TTT() > inst.duplica(7) He already has a TTT instance. Since he's calling the TTT.duplica method from another TTT method, the easiest way (and the most Pythonic, and the most sensible, is to do this: self.duplica(7) Calling duplica from the class as TTT.duplica will work, if he does: TTT.duplica(self, 7) but why would you want to? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling a class method
vsoler wrote: I have the following script: class TTT(object): def duplica(self): self.data *= 2 def __init__(self, data): self.data = data TTT.duplica(self.data) def __str__(self): return str(self.data) print obj=TTT(7) print obj And I want 14 printed (twice 7) I got the following error: TypeError: unbound method duplica() must be called with TTT instance as first argument (got int instance instead) What am I doing wrong? duplica() takes a 'self' parameter (a TTT instance), but you're calling it with self.data (an int instance). Change this line: TTT.duplica(self.data) to this: TTT.duplica(self) and it will do what you want. -- http://mail.python.org/mailman/listinfo/python-list
Re: An open source AI research project
On 04/18/10 00:13, Simon Brunning wrote: > On 17 April 2010 09:03, David Zhang wrote: >> I have started an open source project to develop human-level >> Artificial Intelligence... > > Have you people never seen Terminator? Sheesh. Ssshhh, you're disclosing our top-secret plan... -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling a class method
vsoler wrote: I have the following script: class TTT(object): def duplica(self): self.data *= 2 def __init__(self, data): self.data = data TTT.duplica(self.data) def __str__(self): return str(self.data) print obj=TTT(7) print obj And I want 14 printed (twice 7) I got the following error: TypeError: unbound method duplica() must be called with TTT instance as first argument (got int instance instead) What am I doing wrong? duplica() takes a 'self' parameter (a TTT instance), but you're calling it with self.data (an int instance). Change this line: TTT.duplica(self.data) to this: TTT.duplica(self) and it will do what you want. -- http://mail.python.org/mailman/listinfo/python-list
Re: Incorrect scope of list comprehension variables
On Sat, 17 Apr 2010 12:05:03 +0200, Alain Ketterlin wrote: >> I don't know of any language that creates a new scope for loop >> variables, but perhaps that's just my ignorance... > > I think Pascal and Modula-2 do this, Fortran does this, as well as Ada. Pascal doesn't do this. [st...@sylar pascal]$ cat for_test.p program main(input, output); var i: integer; begin for i := 1 to 3 do begin writeln(i); end; writeln(i); end. [st...@sylar pascal]$ gpc for_test.p [st...@sylar pascal]$ ./a.out 1 2 3 3 However you can't assign to the loop variable inside the loop. Outside of the loop, it is treated as just an ordinary variable and you can assign to it as usual. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: class instance customization
On Sat, 17 Apr 2010 13:09:43 +0400, Alexander wrote: > Hi, list. > > I've some nontrivial class implementation MyClass and its instance my: > > my = MyClass(args) > > MyClass uses in internals some variable which is not defined in MyClass > itself. I want to extend instance of MyClass at runtime defining this > variable and making new instance. It is like a class inheritance in a > static way I'm afraid I don't understand what you are asking. MyClass uses a variable which is not defined in MyClass. Where is it defined? Is it a global variable? What do you mean, "like a class inheritance in a static way"? Perhaps you should give an example of what you want to happen. > class MyNewClass(MyClass): > def __init__(s, a): > s._variable = a > > but this doesn't give me ability to make inheritance at runtime of the > single parent intance. Why not? What is the single parent instance? > Finaly this should look like this > > my = MyClass(args) > > a1 = my.new(1) > a2 = my.new(2) > > and e.t.c. Is it possible to release this interface in python? I'm afraid none of this makes any sense to me. What does the new() method do? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: How to run program in Linux
Jim Byrnes wrote: Dave Angel wrote: Jim Byrnes wrote: Dave Angel wrote: Jim Byrnes wrote: I am just learning Python and am new to Linux so I am probably doing something to trip myself up. I am trying to run an example GUI program that fetches a record from a database. All the files are in the same folder. The program runs but its results vary depending on how I started it. If I run it from the terminal or Idle, I enter a key and the program fetches the proper record. If I run it from Nautilis or a panel launcher, I enter the proper key and I get an error message saying the key does not exist. I am assuming that I am having path issues but don't know how to correct it. Thamks, Jim Presumably you're also new to mailing lists. Not really. At an absolute minimum when you describe an error, PASTE the error message, complete with traceback, into your message. As it stands, I'm left wondering which key on your keyboard can possibly "not exist." Perhaps it's a non-ASCII code, and you're getting some encoding error. That's a common discrepancy between running from a terminal and running from some GUI. The error was generated by the program, not Python. The 'key' I was referring to was a dictionary type key, not a physical one on the keyboard. Even better is to specify the version of Python this program is presumably written in, and what Linux distro. Then you say it's a GUI program, so you should specify which GUI library you're using. Python 2.6, Ubuntu 9.10, tkinter Now if I do a bunch of guessing, I might come up with the likelihood that your "Nautilus" is supplying a different current directory than the one the script is located in. You can find that out by looking at: os.path.abspath(os.curdir) OK, thanks. If that is the case how do I correct it? But of course how you print that depends on what GUI package you're running. DaveA Regards, Jim You forgot to include the list in your reply. Try using reply-all instead. If you determine that the current directory is your problem, and that Nautilus isn't setting it the way you'd like, then you may have to resort to other ways to identify the other files you mention. Easiest way might be to use the __file__ attribute of each module, which gives its complete path. So your code in the main script could do something like (untested): target = os.path.dirname(__file__) os.chdir(target) I added target = os.path.dirname(__file__) and printed the result. If I run the script in Idle it produces the correct result and shows the path as /usr/bin. Running it form the terminal produces the correct result but shows the path empty. Running it from Nautilus or a launcher does not produce the correct result and shows the full path to the directory that contains the script and its files. If I add os.chdir(target) to the script, Idle and the terminal stop producing the correct result and the launcher and Nautilius start producing the correct result. This is exactly the opposite of what I expected. Better is usually to ignore current directory, and passed the desired directory name into whatever function is going to use it. I'll keep this in mind for anything I write. Right now I'm trying to understand some examples that were produced in a Windows environment. Like I said at the top I am new to Linux (Ubuntu) and don't fully understand its requirements. HTH, DaveA Thanks, Jim Apparently in Linux, the __file__ contains a relative path. So you should normalize it, the easiest way being target = os.path.abspath(os.path.dirname(__file__)) This should then be the same no matter how you launch the script. Any other guesses would need some sample code that shows the failure. But you probably need to simplify it substantially to convince a volunteer to look at it. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Incorrect scope of list comprehension variables
Steven D'Aprano writes: > On Sat, 17 Apr 2010 12:05:03 +0200, Alain Ketterlin wrote: > >>> I don't know of any language that creates a new scope for loop >>> variables, but perhaps that's just my ignorance... >> >> I think Pascal and Modula-2 do this, Fortran does this, as well as Ada. > > Pascal doesn't do this. [...] > for i := 1 to 3 do > begin > writeln(i); > end; > writeln(i); [...] At http://standardpascal.org/iso7185.html#6.8.3.9%20For-statements (sorry, I didn't find a more readable version), I read (second paragraph, fourth sentence) : "After a for-statement is executed, other than being left by a goto-statement, the control-variable shall be undefined." So, at least, the compiler should emit a warning. > However you can't assign to the loop variable inside the loop. Outside of > the loop, it is treated as just an ordinary variable and you can assign > to it as usual. I read the excerpt above as: you have to re-assign to it before using it. The corner-case is obvious: if the loop body is not executed at all, you cannot assume the "control-variable" will have the first value. I'm curious to know what gets printed if you swap 1 and 3 in the above code. -- Alain. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to run program in Linux
Dave Angel wrote: Jim Byrnes wrote: Dave Angel wrote: Jim Byrnes wrote: Dave Angel wrote: Jim Byrnes wrote: I am just learning Python and am new to Linux so I am probably doing something to trip myself up. I am trying to run an example GUI program that fetches a record from a database. All the files are in the same folder. The program runs but its results vary depending on how I started it. If I run it from the terminal or Idle, I enter a key and the program fetches the proper record. If I run it from Nautilis or a panel launcher, I enter the proper key and I get an error message saying the key does not exist. I am assuming that I am having path issues but don't know how to correct it. Thamks, Jim Presumably you're also new to mailing lists. Not really. At an absolute minimum when you describe an error, PASTE the error message, complete with traceback, into your message. As it stands, I'm left wondering which key on your keyboard can possibly "not exist." Perhaps it's a non-ASCII code, and you're getting some encoding error. That's a common discrepancy between running from a terminal and running from some GUI. The error was generated by the program, not Python. The 'key' I was referring to was a dictionary type key, not a physical one on the keyboard. Even better is to specify the version of Python this program is presumably written in, and what Linux distro. Then you say it's a GUI program, so you should specify which GUI library you're using. Python 2.6, Ubuntu 9.10, tkinter Now if I do a bunch of guessing, I might come up with the likelihood that your "Nautilus" is supplying a different current directory than the one the script is located in. You can find that out by looking at: os.path.abspath(os.curdir) OK, thanks. If that is the case how do I correct it? But of course how you print that depends on what GUI package you're running. DaveA Regards, Jim You forgot to include the list in your reply. Try using reply-all instead. If you determine that the current directory is your problem, and that Nautilus isn't setting it the way you'd like, then you may have to resort to other ways to identify the other files you mention. Easiest way might be to use the __file__ attribute of each module, which gives its complete path. So your code in the main script could do something like (untested): target = os.path.dirname(__file__) os.chdir(target) I added target = os.path.dirname(__file__) and printed the result. If I run the script in Idle it produces the correct result and shows the path as /usr/bin. Running it form the terminal produces the correct result but shows the path empty. Running it from Nautilus or a launcher does not produce the correct result and shows the full path to the directory that contains the script and its files. If I add os.chdir(target) to the script, Idle and the terminal stop producing the correct result and the launcher and Nautilius start producing the correct result. This is exactly the opposite of what I expected. Better is usually to ignore current directory, and passed the desired directory name into whatever function is going to use it. I'll keep this in mind for anything I write. Right now I'm trying to understand some examples that were produced in a Windows environment. Like I said at the top I am new to Linux (Ubuntu) and don't fully understand its requirements. HTH, DaveA Thanks, Jim Apparently in Linux, the __file__ contains a relative path. So you should normalize it, the easiest way being target = os.path.abspath(os.path.dirname(__file__)) This should then be the same no matter how you launch the script. Any other guesses would need some sample code that shows the failure. But you probably need to simplify it substantially to convince a volunteer to look at it. DaveA Using your suggestion now allows me to run the program from anywhere except Idle, which gives file permission and database errors. I didn't paste the error here because my intent was to figure out how to run python programs outside of Idle and you have shown me how to do it. If someone is interested in seeing the error message I will certainly post it. Just want to say thanks for furthering my python understanding. Regards Jim -- http://mail.python.org/mailman/listinfo/python-list
Re: class instance customization
On 17.04.2010 18:32, Steven D'Aprano wrote: > On Sat, 17 Apr 2010 13:09:43 +0400, Alexander wrote: > > >> Hi, list. >> >> I've some nontrivial class implementation MyClass and its instance my: >> >> my = MyClass(args) >> >> MyClass uses in internals some variable which is not defined in MyClass >> itself. I want to extend instance of MyClass at runtime defining this >> variable and making new instance. It is like a class inheritance in a >> static way >> > I'm afraid I don't understand what you are asking. MyClass uses a > variable which is not defined in MyClass. Where is it defined? Is it a > global variable? > > What do you mean, "like a class inheritance in a static way"? > > Perhaps you should give an example of what you want to happen. > Ok, I'll try to explain on the following example. Let's consider class MyClass that holds one string and concatenate it with other not defined in this class: class MyClass(object): def __init__(s): pass def set(s, key): s.__key = key def __str__(s): return s.__key + ' ' + s.__other def new(s, value): return SubClass(s, value) The problem is how to implement class SubClass which inherits MyClass, define new variable __other accessible from MyClass intance and with working application: a = MyClass() a.set('key1') b1 = a.new('value1') b2 = a.new('value2') print b1, "," ,b2 # give 'key1 value1 , key1 value2' a.set('key2') print b1, ",", b2 # give 'key2 value1 , key2 value2' -- http://mail.python.org/mailman/listinfo/python-list
Re: extract substring by regex from a text file
On Apr 17, 11:05 am, Peter Otten <__pete...@web.de> wrote: > > Just in case you didn't know: > > for line in instream: > ... > > looks better, uses less memory, and may be a tad faster than > > for line in instream.readlines(): > ... > > Peter Thanks for your suggestions, they are welcome... I'm at the beginning with python. I just changed my script to parse the file without readlines() -- http://mail.python.org/mailman/listinfo/python-list
Re: getting a string as the return value from a system command
On 2010-04-17 01:49 , CHEN Guang wrote: > Catherine Moroney wrote: >> Hello, >> >> I want to call a system command (such as uname) that returns a string, >> and then store that output in a string variable in my python program. >> >> What is the recommended/most-concise way of doing this? >> >> I could always create a temporary file, call the "subprocess.Popen" >> module with the temporary file as the stdout argument, and then >> re-open that temporary file and read in its contents. This seems >> to be awfully long way of doing this, and I was wondering about >> alternate ways of accomplishing this task. >> >> In pseudocode, I would like to be able to do something like: >> hosti nfo = subprocess.Popen("uname -srvi") and have hostinfo >> be a string containing the result of issuing the uname command. >> >> Thanks for any tips, >> >> Catherine > > import os > txt = os.popen("uname -srvi") > hostinfo = txt.readline() > > Or if the command outputs a number of lines (such as 'ls'), > use txt.readlines() to put the result into a list of strings. > > -=- Larry -=- > os.popen3() gives not only result but also error prompt (in case an error or warning happens) stdin,stdout,stderr = os.popen3('uname -srvi') resultText = stdout.read() errorText = stderr.read() For more examples of os.popen3() please look at source code of PythoidC (http://pythoidc.googlecode.com or http://pythoidc.sf.net ) The subprocess module is the preferred choice over either of those functions. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Python Learning Environment
Hi, My Linux box is ubuntu system. I want to create a development environment on my system for python programing language. I got to see there are two versions of python language 1. python 2.5.6 2. python 3.1.2 To find out what version i look in to my "/usr/bin" folder. There are many entries for python command - python - python2 - python2.5 - python2.6 - python3 - python3.1 what does this mean? I am able to run run my first program with all these command. should i remove all these and have the latest one? I am confused about these finding. Is this okay to have these all? Regards, Vijay Shanker Dubey -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Learning Environment
On Sat, Apr 17, 2010 at 6:32 PM, Vijay Shanker Dubey wrote: > Hi, > My Linux box is ubuntu system. I want to create a development environment on > my system for python programing language. I got to see there are two > versions of python language > 1. python 2.5.6 > 2. python 3.1.2 > To find out what version i look in to my "/usr/bin" folder. There are many > entries for python command > - python > - python2 > - python2.5 > - python2.6 > - python3 > - python3.1 > what does this mean? I am able to run run my first program with all these > command. should i remove all these and have the latest one? I am confused > about these finding. Is this okay to have these all? > > Regards, > Vijay Shanker Dubey > python is symlinked to one of the 2.5, 2.6 or 3.1... most probably 2.6. The python2 is symlink to one of 2.5 or 2.6 and python3 is symlinked to python3.1. It's a clever way to be able to specify what version is needed for a script. -- http://mail.python.org/mailman/listinfo/python-list
Re: An open source AI research project
I would like to know more please. Does it have a website? On Sat, Apr 17, 2010 at 4:03 AM, David Zhang wrote: > Hello! > > I have started an open source project to develop human-level > Artificial Intelligence, using Python and Java as programming > language, OpenCog and OpenWonderland as basement. If you are > interested in this,or want to know more, please feel free to give me a > reply. > > Thanks! > > David Zhang > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Learning Environment
On Sat, Apr 17, 2010 at 7:06 PM, Vijay Shanker Dubey wrote: > Yes you are right about symlink thing. > So what should I do for a clever developer environment? > Should I change that python link to python3 or python3.1? > > Regards, > Vijay Shanker Dubey > It all depends on what you want to do. I would say that you shouldn't change your python link at all, if you want to run a python script using 3.1 just call the script using python3 as an interpreter. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Learning Environment
Thanks friend, Got the point. Regards, Vijay Shanker Dubey On Sat, Apr 17, 2010 at 11:31 PM, Krister Svanlund < krister.svanl...@gmail.com> wrote: > On Sat, Apr 17, 2010 at 7:06 PM, Vijay Shanker Dubey > wrote: > > Yes you are right about symlink thing. > > So what should I do for a clever developer environment? > > Should I change that python link to python3 or python3.1? > > > > Regards, > > Vijay Shanker Dubey > > > > It all depends on what you want to do. I would say that you shouldn't > change your python link at all, if you want to run a python script > using 3.1 just call the script using python3 as an interpreter. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: My first project
no one cares? :( On Sat, Apr 17, 2010 at 8:41 AM, Someone Something wrote: > This is my first large-scale (sort of) project in python. It is still under > daily development, but the core is pretty stable (although, I'm still adding > features). Here's the code: http://github.com/Poincare/PyEventLoop or > http://code.google.com/p/pyeventloop/ > Tell me what you guys think of it (I'll be adding more examples by the end > of the day). > -- http://mail.python.org/mailman/listinfo/python-list
Usable street address parser in Python?
Is there a usable street address parser available? There are some bad ones out there, but nothing good that I've found other than commercial products with large databases. I don't need 100% accuracy, but I'd like to be able to extract street name and street number for at least 98% of US mailing addresses. There's pyparsing, of course. There's a street address parser as an example at "http://pyparsing.wikispaces.com/file/view/streetAddressParser.py";. It's not very good. It gets all of the following wrong: 1500 Deer Creek Lane(Parses "Creek" as a street type") 186 Avenue A(NYC street) 2081 N Webb Rd (Parses N Webb as a street name) 2081 N. Webb Rd (Parses N as street name) 1515 West 22nd Street (Parses "West" as name) 2029 Stierlin Court (Street names starting with "St" misparse.) Some special cases that don't work, unsurprisingly. P.O. Box 33170 The Landmark @ One Market, Suite 200 One Market, Suite 200 One Market Much of the problem is that this parser starts at the beginning of the string. US street addresses are best parsed from the end, says the USPS. That's why things like "Deer Creek Lane" are mis-parsed. It's not clear that regular expressions are the right tool for this job. There must be something out there a little better than this. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Incorrect scope of list comprehension variables
There's no RightAnswer(tm), just our best guess as to what is the most useful behavior for the most number of people. +1 QOTW -- http://mail.python.org/mailman/listinfo/python-list
Nested list problem - please...
Dear list I have this code, it builds up a data structure of nested lists, and filling data in them. My problem is that it seems that one of the lists SA[1] is not a list of unique instances but rather individual links to the same variable. In the example below I assign 'X' to what I intended to be the first Compounds Name. But rather the 'X' goes into all the Compounds Name. I thought that the [:] in SAdata.extend([CP[:]]) would ensure copies rather than links to. What is going wrong? I include sample code, and I include the output it produces, and I manually inserted some line breaks and some indents, for readability. :-) Martin --- Code Start --- LV = list() # LV for Lable Value pair LV.extend(['lable','0']) CP = list() # CP for ComPund for i in range(0,5): CP.extend([LV[:]]) # incl. 5 _copies_ of LV CP[0][0] = 'Compound name' CP[1][0] = 'Tgt' CP[2][0] = 'Q1' CP[3][0] = 'Q2' CP[4][0] = 'Q3' SA = list() # SA for SAmple SAheader = list() for i in range(0,3): SAheader.extend([LV[:]]) SAheader[0][0] = 'fileinfo.txt' SAheader[1][0] = 'Data file' SAheader[2][0] = 'Sample name' SA.extend([SAheader]) SAdata = list() for i in range(0,2): SAdata.extend([CP[:]]) SA.extend([SAdata]) print SA SA[1][0][0][1] = 'X' print SA --- Code End --- [ [ ['fileinfo.txt', '0'], ['Data file', '0'], ['Sample name', '0'] ], [ [ ['Compound name', 'X'], ['Tgt', '0'], ['Q1', '0'], ['Q2', '0'], ['Q3', '0'] ], [ ['Compound name', 'X'], ['Tgt', '0'], ['Q1', '0'], ['Q2', '0'], ['Q3', '0'] ] ] ] -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested list problem - please...
On Sat, Apr 17, 2010 at 12:40 PM, Martin Hvidberg wrote: > I have this code, it builds up a data structure of nested lists, and filling > data in them. > My problem is that it seems that one of the lists SA[1] is not a list of > unique instances but rather individual links to the same variable. > In the example below I assign 'X' to what I intended to be the first > Compounds Name. But rather the 'X' goes into all the Compounds Name. > I thought that the [:] in SAdata.extend([CP[:]]) would ensure copies rather > than links to. > What is going wrong? someList[:] only copies 1-level deep. If you have a list of lists, none of the inner lists will be copied; you'll get a new list of references to the same lists instead. I think your code assumes [:] copies lists recursively. Also, a.extend([b[:]]) is more efficiently and idiomatically written as a.append(b[:]) Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Incorrect scope of list comprehension variables
On Sat, 17 Apr 2010 17:23:45 +0200, Alain Ketterlin wrote: > Steven D'Aprano writes: > >> On Sat, 17 Apr 2010 12:05:03 +0200, Alain Ketterlin wrote: >> I don't know of any language that creates a new scope for loop variables, but perhaps that's just my ignorance... >>> >>> I think Pascal and Modula-2 do this, Fortran does this, as well as >>> Ada. >> >> Pascal doesn't do this. > [...] >> for i := 1 to 3 do >> begin >> writeln(i); >> end; >> writeln(i); > [...] > > At http://standardpascal.org/iso7185.html#6.8.3.9%20For-statements > (sorry, I didn't find a more readable version), I read (second > paragraph, fourth sentence) : > > "After a for-statement is executed, other than being left by a > goto-statement, the control-variable shall be undefined." > > So, at least, the compiler should emit a warning. None of my Pascal text books mention this behaviour, and gpc doesn't emit a warning by default. Possibly there is some option to do so. Stardard Pascal isn't as useful as non-standard Pascal. This was one of the reasons for the (in)famous article "Pascal Considered Harmful" back in the 1980s(?). >> However you can't assign to the loop variable inside the loop. Outside >> of the loop, it is treated as just an ordinary variable and you can >> assign to it as usual. > > I read the excerpt above as: you have to re-assign to it before using > it. > > The corner-case is obvious: if the loop body is not executed at all, you > cannot assume the "control-variable" will have the first value. I'm > curious to know what gets printed if you swap 1 and 3 in the above code. When I try it, i is initialised to 0. That either means that gpc zeroes integers when they're declared, or the value it just randomly happened to pick up was 0 by some fluke. I'm guessing the first is more likely. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Python 2.7b1 and argparse's version action
Hi, all, I notice that Python 2.7 beta 1 now contains the argparse module, which might be a good thing. The code has been cleaned up, too. But there is still one issue with argparse: Completely unnecessarily, the 'version' constructor argument is now deprecated. This fact doesn't solve any problem I can think of; the only effect is to make programming more cumbersome, and it is /one more/ difference to optparse. The 'version' argument is a perfectly reasonable way to provide a script with a simple version information feature. Of course, it should only define the '--version' argument; it *must not* define '-v' for this purpose, since this is commonly used for verbosity. I have lots of scripts which use optparse, and every single one uses the version argument. I consider this a matter of good style. Of course, if a more fancy version information is needed, it is perfectly possible to just omit the version argument during creation and build a special 'version' action, e.g. reporting the versions of all imported modules. No deprecation warnings are needed for this. *Before Python 2.7 getting a production release*, IMNSHO the following changes should be applied to argparse.py: - removal of the deprecation warnings - removal of the default usage of '-v' with the version information facility This is a very simple thing to do; I'd happily provide a patch. Just for the records, this is what optparse does: - it defines -h and --help for the help (unless suppressed) - it defines --version for the version (if version argument given) This is how it should be. This is how the vast majority of *x tools looks like. (well, some use '-h' for something like "host" or "human readable"; but just a few strange misfits use -v instead of -V for the version.) No reason to change this behaviour. What do you think? -- Cheers, Tobias -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.7b1 and argparse's version action
On Sat, Apr 17, 2010 at 6:53 PM, Tobias Herp wrote: > Hi, all, > > I notice that Python 2.7 beta 1 now contains the argparse module, which > might be a good thing. The code has been cleaned up, too. > > But there is still one issue with argparse: > Completely unnecessarily, the 'version' constructor argument is now > deprecated. This fact doesn't solve any problem I can think of; the > only effect is to make programming more cumbersome, and it is /one more/ > difference to optparse. > *Before Python 2.7 getting a production release*, IMNSHO the following > changes should be applied to argparse.py: > > - removal of the deprecation warnings > - removal of the default usage of '-v' > with the version information facility > > This is a very simple thing to do; I'd happily provide a patch. > > Just for the records, this is what optparse does: > - it defines -h and --help for the help (unless suppressed) > - it defines --version for the version (if version argument given) > This is how it should be. > This is how the vast majority of *x tools looks like. > (well, some use '-h' for something like "host" or "human readable"; > but just a few strange misfits use -v instead of -V for the version.) > No reason to change this behaviour. > > What do you think? You'd probably ought to just complain upstream to the argparse project itself. The change doesn't seem to have been made specifically for std lib inclusion (though I didn't read the bug in depth). This looks like the relevant issue: http://code.google.com/p/argparse/issues/detail?id=43 Relevant revision: http://code.google.com/p/argparse/source/detail?r=83 Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.7b1 and argparse's version action
Am 18.04.2010 04:09, schrieb Chris Rebert: > On Sat, Apr 17, 2010 at 6:53 PM, Tobias Herp > wrote: >> Hi, all, >> >> I notice that Python 2.7 beta 1 now contains the argparse module, which >> might be a good thing. The code has been cleaned up, too. >> >> But there is still one issue with argparse: >> Completely unnecessarily, the 'version' constructor argument is now >> deprecated. This fact doesn't solve any problem I can think of; the >> only effect is to make programming more cumbersome, and it is /one more/ >> difference to optparse. > >> *Before Python 2.7 getting a production release*, IMNSHO the following >> changes should be applied to argparse.py: >> >> - removal of the deprecation warnings >> - removal of the default usage of '-v' >> with the version information facility >> >> This is a very simple thing to do; I'd happily provide a patch. >> >> Just for the records, this is what optparse does: >> - it defines -h and --help for the help (unless suppressed) >> - it defines --version for the version (if version argument given) >> This is how it should be. >> This is how the vast majority of *x tools looks like. >> (well, some use '-h' for something like "host" or "human readable"; >> but just a few strange misfits use -v instead of -V for the version.) >> No reason to change this behaviour. >> >> What do you think? > > You'd probably ought to just complain upstream to the argparse project > itself. The change doesn't seem to have been made specifically for std > lib inclusion (though I didn't read the bug in depth). > > This looks like the relevant issue: > http://code.google.com/p/argparse/issues/detail?id=43 Yes, this is the issue I once submitted. I had a very hard time discussing, since Steven insisted (and apparently still insists) in -v as a reasonable default short option for the version feature. Then I had some password database problems, and during the time I fell silent, he decided to deprecate the version argument. Since the code has been cleaned up and differs in many details from the current argparse v1.1, I hoped for somebody with a Python hat on to say, "This module is nice, but to make it in a production release of Python these simple issues must be fixed." To plagiarise Galahad (Monty Python and the Holy Grail): "Is there someone else up there we could talk to?" -- Tobias -- http://mail.python.org/mailman/listinfo/python-list
Python at BerkeleyTIP-Global meeting on Sunday April 18 12N-3P, & April 27
Come discuss python. :) Join via VOIP or come to Berkeley http://sites.google.com/site/berkeleytip/voice-voip-conferencing FSCafe at Moffitt at UCBerkeley, opens 1pm, but can connect from outside at 12N. Hot topics: Ubuntu 10.04, Free Culuture, VOIP, Set up the web server & mail list & asterisk/freeswitch on the BTIP box with Ubuntu 10.04? Tues April 27 5-6P VOIP online meeting also. http://sites.google.com/site/berkeleytip/ Join the mail list, tell us what you're interested in. http://sites.google.com/site/berkeleytip/mailing-lists -- http://mail.python.org/mailman/listinfo/python-list
Cheap Wholesale Adidas Shoes (paypal payment)
Cheap Wholesale UGG Shoes (paypal payment) (http://www.jordanonline06.com/) Cheap Wholesale Ugg Boots (paypal payment) Cheap Wholesale Gucci Shoes (paypal payment) (http://www.jordanonline06.com/) Cheap Wholesale GUCCI Boots Cheap Wholesale Lacoste Shoes Cheap Wholesale LV Shoes(paypal payment) (http://www.jordanonline06.com/ ) Cheap Wholesale LV Boots Cheap Wholesale Prada Shoes (paypal payment) (http://www.jordanonline06.com/) Cheap Wholesale Timberland Shoes Cheap Wholesale D&G Shoes (paypal payment) (http://www.jordanonline06.com/) Cheap Wholesale D&G Boots Cheap Wholesale Puma Shoes Cheap Wholesale Puma AAA(paypal payment) (http://www.jordanonline06.com/) Cheap Wholesale UGG Boots Shoes Cheap Wholesale Bikkem Bergs Shoes (free shipping) Cheap Wholesale Mauri Shoes Man Cheap Wholesale Versace Shoes (paypal payment) (http://www.jordanonline06.com/) Cheap Wholesale Versace Boots Cheap Wholesale Paul Smith Shoes(free shipping) Cheap Wholesale BOSS Shoes Cheap Wholesale Burberry Shoes (paypal payment) (http://www.jordanonline06.com/ ) Cheap Wholesale Dsquared shoes Cheap Wholesale Dior Shoes (free shipping) Cheap Wholesale Dior Boots Cheap Wholesale ED Hardy Shoes (paypal payment) (http://www.jordanonline06.com/ ) Cheap Wholesale ED Hardy Boots Cheap Wholesale ED Hardy Shoes Man (paypal payment) (http://www.jordanonline06.com/ ) Cheap Wholesale Fendi Shoes (paypal payment) (http://www.jordanonline06.com/ ) Cheap Wholesale Fendi Boots Cheap Wholesale AFF Shoes (paypal payment) (http://www.jordanonline06.com/ ) Cheap Wholesale Evisu Shoes (free shipping) Cheap Wholesale 4US Shoes Cheap Wholesale Sebago Shoes(paypal payment) (http://www.jordanonline06.com/ ) Cheap Wholesale Supra Shoes Cheap Wholesale Hight Converse Shoes (paypal payment) (http://www.jordanonline06.com/ ) Cheap Wholesale Coach Boots Cheap Wholesale Coach Shoes Women Christian Louboutin (paypal payment) (http://www.jordanonline06.com/ ) Cheap Wholesale Chanel Shoes Cheap Wholesale Chanel Boots(free shipping) Cheap Wholesale Bape Shoes Cheap Wholesale Adidas Shoes(paypal payment) (http://www.jordanonline06.com/ ) Cheap Wholesale Adicolor(free shipping) Cheap Wholesale Adidas 35TH (paypal payment) (http://www.jordanonline06.com/ ) Cheap Wholesale Adidas NBA Cheap Wholesale Adidas Running (paypal payment) (http://www.jordanonline06.com/ ) Cheap Wholesale Adidas Y3 Cheap Wholesale Soccer Shoes(paypal payment) (http://www.jordanonline06.com/ ) -- http://mail.python.org/mailman/listinfo/python-list