[issue24736] argparse add_mutually_exclusive_group do not print help
Alexandre Badez added the comment: @paul: thanks, I'm very surprised because the parsing work well. It's just the display that do not. Moreover it's not said in the documentation that you cannot nest groups. So maybe we should update the documentation and/or improve the module ? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24736 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24736] argparse add_mutually_exclusive_group do not print help
New submission from Alexandre Badez: Hi, Here is a sample of what I do: import argparse main_parser = argparse.ArgumentParser() group_ex = main_parser.add_mutually_exclusive_group() group_ex1 = group_ex.add_argument_group() group_ex1.add_argument('-a', '--atest', help=help about -a) and None group_ex1.add_argument('-b', '--btest', help=help about -b) and None group_ex.add_argument('-c', '--ctest', help=help about -c) and None main_parser.print_help() usage: [-h] [-a ATEST] [-b BTEST] [-c CTEST] optional arguments: -h, --helpshow this help message and exit -c CTEST, --ctest CTEST help about -c Here is what I would except as help message: main_parser.print_help() usage: [-h] [[-a ATEST] [-b BTEST]] | [-c CTEST] optional arguments: -h, --helpshow this help message and exit -c CTEST, --ctest CTEST help about -c -a ATEST, --atest ATEST help about -a -b BTEST, --btest BTEST help about -b Options '-a' and '-b' are not displayed in the help message due to the add_mutually_exclusive_group. -- components: Library (Lib) files: test_arg.py messages: 247465 nosy: Alexandre.Badez priority: normal severity: normal status: open title: argparse add_mutually_exclusive_group do not print help type: behavior versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4 Added file: http://bugs.python.org/file40038/test_arg.py ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24736 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11374] pkgutil.extend_path do not recognize py{c,o} file
New submission from Alexandre Badez alexandre.ba...@gmail.com: extend_path only test if init.py files exist, but it should also test init.pyc and/or init.pyo. -- components: Library (Lib) messages: 129896 nosy: Alexandre.Badez priority: normal severity: normal status: open title: pkgutil.extend_path do not recognize py{c,o} file versions: Python 2.5, Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11374 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11374] pkgutil.extend_path do not recognize py{c,o} file
Changes by Alexandre Badez alexandre.ba...@gmail.com: -- type: - behavior ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11374 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11374] pkgutil.extend_path do not recognize py{c,o} file
Alexandre Badez alexandre.ba...@gmail.com added the comment: I've made a simple patch. -- keywords: +patch Added file: http://bugs.python.org/file20977/patch.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11374 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11374] pkgutil.extend_path do not recognize py{c,o} file
Changes by Alexandre Badez alexandre.ba...@gmail.com: Removed file: http://bugs.python.org/file20977/patch.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11374 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11374] pkgutil.extend_path do not recognize py{c,o} file
Alexandre Badez alexandre.ba...@gmail.com added the comment: A little change in the patch -- Added file: http://bugs.python.org/file20978/patch.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11374 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Better writing in python
I'm just wondering, if I could write a in a better way this code lMandatory = [] lOptional = [] for arg in cls.dArguments: if arg is True: lMandatory.append(arg) else: lOptional.append(arg) return (lMandatory, lOptional) I think there is a better way, but I can't see how... -- http://mail.python.org/mailman/listinfo/python-list
Re: Better writing in python
On 10/24/07, J. Clifford Dyer [EMAIL PROTECTED] wrote: On Wed, Oct 24, 2007 at 12:09:40PM -, Alexandre Badez wrote regarding Better writing in python: lMandatory = [] lOptional = [] for arg in cls.dArguments: if arg is True: lMandatory.append(arg) else: lOptional.append(arg) return (lMandatory, lOptional) I think there is a better way, but I can't see how... I assume cls.dArguments is a dict, correct? `for arg in cls.dArguments` takes each *key* for cls.dArguments and assigns it to arg, so the line 'if arg is True' will test the truth value of each key. I assume (you haven't shown the details here) that your dict looks like this: cls.dArguments = { 'a': True, 'b': False, 'c': True, 'd': False, '': True, 0: False } and you want your for loop to do this: lMandatory == [ 'a', 'c', '' ] lOptional == [ 'b', 'd', 0 ] in fact, since it's testing the truth value of the keys, not the values, you will get this: lMandatory == [ 'a', 'b', 'c', 'd' ] lOptional == [ '', 0 ] In no particular order, of course. Also, `if x is True:` should be written as `if x:` Actually, come to think of it, what I said above is false, because the string 'a' *is not* the boolean value True, per se: it is *equal to* True. So if you change `if x is True:` to `if x == True:` then everything I said above holds true, including that you should change `if x == True:` to `if x:` As it stands, the only key in your dict that has a snowball's chance in key largo of being marked as mandatory is the boolean value True itself. Cheers, Cliff Thanks for your try Cliff, I was very confused :P More over I made some mistake when I post (to make it easiest). Here is my real code: with dArguments = { 'argName' : { 'mandatory' : bool, # True or False [...], # other field we do not care here } } lMandatory = [] lOptional = [] for arg in cls.dArguments: if cls.dArguments[arg]['mandatory']: lMandatory.append(arg) else: lOptional.append(arg) return (lMandatory, lOptional) So, as you see, we agree each other about if bool or if bool is True ;) So, my question was how to give it a better 'python like' look ? Any idea ? -- Alex http://alexandre.badez.googlepages.com/ [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Better writing in python
Thanks for your try Cliff, I was very confused :P More over I made some mistake when I post (to make it easiest). Here is my real code: with dArguments = { 'argName' : { 'mandatory' : bool, # True or False [...], # other field we do not care here } } lMandatory = [] lOptional = [] for arg in cls.dArguments: if cls.dArguments[arg]['mandatory']: lMandatory.append(arg) else: lOptional.append(arg) return (lMandatory, lOptional) So, as you see, we agree each other about if bool or if bool is True ;) So, my question was how to give it a better 'python like' look ? Any idea ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Better writing in python
On Oct 24, 3:46 pm, Duncan Booth [EMAIL PROTECTED] wrote: For a 'python like' look lose the Hungarian notation (even Microsoft have largely stopped using it) I wish I could. But my corporation do not want to apply python.org coding rules increase the indentation to 4 spaces, Well, it is in my python file. I do not do it here, because I'm a bit lazy. and also get rid of the spurious parentheses around the result. Thanks Otherwise it is fine: clear and to the point. Thanks If you really wanted you could write something like: m, o = [], [] for arg in cls.dArguments: (m if cls.dArguments[arg]['mandatory'] else o).append(arg) return m, o Or even: m, o = [], [] action = [o.append, m.append] for arg in cls.dArguments: action[bool(cls.dArguments[arg]['mandatory'])](arg) return m, o but it just makes the code less clear, so why bother? And finally thanks again ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic and lazy import
Thanks for all your advices, but it's not really what I would like to do. I'm going to be more clearer for what I really want to do. Here we have got many library for different applications. All those library have a version and between a version and an other, there isn't always a very good backward compatibility (I know, it's very ugly, but it's like that...). Moreover some library use the version 1.1 and some the version 1.2 of lib A and version 2.1 and version 2.0 of lib B ... you know what: it's very ugly. My idea was to be able to use lib quiet like that. import A (- If I want to use the very last version) # or import A.1_1 (- If I want to use the version 1.1 of the A lib) Something else ? Yes :) I do not want to add all those path in PYTHONPATH (would be too ugly, and complicated). I want it lazy (do not import every version of every lib every time) I want it scalable: if a user or the admin add a new lib or a version of lib it would be very very great if he had nothing else (than copy his directory) to do. So what I wanted to do, was to be able to control what the user really wanted to import, and act he excepted and put the intelligence in a __init__ script -- http://mail.python.org/mailman/listinfo/python-list
Re: Write by logging.FileHandler to one file by many processess
On Oct 17, 3:33 pm, Rafa Zawadzki [EMAIL PROTECTED] wrote: Hello. As I saw in logging source - there is no lock per file during making emit() (only lock per thread). So, my question is - is it safe to log into one file using many processess uses logging logger? Cheers, -- bluszczhttp://vegan-planet.net Well, there a dummy response: there is no true thread in Python (I mean CPython). So there is no problems in this case (cf global interpreter lock or GIL). -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic and lazy import
On Oct 17, 3:56 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: Alexandre Badez wrote: Thanks for all your advices, but it's not really what I would like to do. I'm going to be more clearer for what I really want to do. Here we have got many library for different applications. All those library have a version and between a version and an other, there isn't always a very good backward compatibility (I know, it's very ugly, but it's like that...). Moreover some library use the version 1.1 and some the version 1.2 of lib A and version 2.1 and version 2.0 of lib B ... you know what: it's very ugly. My idea was to be able to use lib quiet like that. import A (- If I want to use the very last version) # or import A.1_1 (- If I want to use the version 1.1 of the A lib) Something else ? Yes :) I do not want to add all those path in PYTHONPATH (would be too ugly, and complicated). I want it lazy (do not import every version of every lib every time) I want it scalable: if a user or the admin add a new lib or a version of lib it would be very very great if he had nothing else (than copy his directory) to do. So what I wanted to do, was to be able to control what the user really wanted to import, and act he excepted and put the intelligence in a __init__ script Use setuptools + pkg_resources to install sereval versions of your libraries together and then you can require a certain version of your lib. HOWEVER: this WON'T work for several versions of a library in ONE running python process Because the import will then either fail silently (after all, import foo is ignored if foo is already present) or pkg_resources is so clever that it keeps tracks of requirements and if they are conflicting will puke on you. Diez Well, I would like to be able to use setuptools, but the problem is that I can't. Cause the administrator do not want us to be able to add lib in python dir. So we have to create our own library directory... Moreover, I haven't seen in distutils how it manage different version of the same library; as far as I know, It just replace the old one by the newest one... and that's not really what I want. -- http://mail.python.org/mailman/listinfo/python-list
Re: PyQt ProgressBar
On Oct 16, 8:03 am, luca72 [EMAIL PROTECTED] wrote: No one can help pls Regards Luca I've written a little app for testing this: import sys import time from PyQt4 import QtGui app = QtGui.QApplication(sys.argv) barra = QtGui.QProgressBar() barra.show() barra.setMinimum(0) barra.setMaximum(10) for a in range(10): time.sleep(1) barra.setValue(a) app.exec_() For me, it work great (on windows, with python 2.4.4 and Qt 4.1 and PyQt 4.0). Could you tell us a bit more about your problems ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Automatically organize module imports
On Oct 16, 8:52 am, Thomas Wittek [EMAIL PROTECTED] wrote: Jean-Paul Calderone: On Mon, 15 Oct 2007 20:52:11 +0200, Thomas Wittek [EMAIL PROTECTED] wrote: Is there a tool that can organize my import section? Pyflakes will tell you which imports aren't being used (among other things). I don't know if an existing tool which will automatically rewrite your source, though. As Python itself complains about missing imports Pyflakes + Python should be a good team in cleaning up my imports. I'll give it a try. Thank you! -- Thomas Wittek Web:http://gedankenkonstrukt.de/ Jabber: [EMAIL PROTECTED] GPG: 0xF534E231 Hye, If you're using Eclipse + PyDev, I strongly recommend you to give a try to PyLint (http://www.logilab.org/857;). It reintegrate quiet well with PyDev and Eclipse, and do as much as Pyflakes (as far as I know) -- http://mail.python.org/mailman/listinfo/python-list
Re: Automatically organize module imports
On Oct 16, 12:08 pm, Thomas Wittek [EMAIL PROTECTED] wrote: Great. It has a warning about unused imports. Perfect. (Though, it was a bit tricky to install as easy_install didn't get the dependencies right on Win XP) Thank you! -- Thomas Wittek Web:http://gedankenkonstrukt.de/ Jabber: [EMAIL PROTECTED] GPG: 0xF534E231 Actually, I'm using it on W2K, and I haven't got any problem during install... :/ -- http://mail.python.org/mailman/listinfo/python-list
Dynamic and lazy import
Hye everyone, I'm would like to do something a bit tricky. I would like when I do something like to create a __init__ package's (here calle my_package) file witch make an action when we try to import something in this package... Quiet like __getattribute__ work for a class, I would like this kind of behaviour for a whole module or a package be a bit clearer: I've got a normal package/module/class (whathever) where I do something like: from my_package import my_module (but in the my_package I've got only: my_package / __init__.py And in the __init__ of my my_package something like __getattribute__ (but for a module) that would return something for my_module I know, that I can do something like charging everything before in __init__ like: my_module = the_thing_I_want But I need it to be lazy (because I may have many module witch could be very awful...). Any idea ? Is it possible ? -- http://mail.python.org/mailman/listinfo/python-list
Re: pydev code completion problem
On Oct 14, 9:45 pm, Lukasz Mierzejewski [EMAIL PROTECTED] wrote: Hi, I need help with pydev code completion... Let's assume that we have something like this: class One: def fun(self): return 1 class Two: li = [] li.append(One()) one = li[0] print one.fun() one2 = li.pop() print one2.fun() one3 = One() print one3.fun() Only for 'one3' variable code completion is working fine (as expected it show fun()). For 'one' code completion shows something (but not fun()). For 'one2' code completion shows nothing :-( I use Eclipse 3.3.1 with PyDev 1.3.9 on Ubuntu 7.04. Can anyone confirm or deny this behavior of PyDev? It would be very great if a solution like this could exist, but it can't at all, because python is very dynamic. Not like in other languages like C, C++ or Java, in python if you use a list, you do not have to declare what the list hold, it can contains everything. Moreover, it can contains different sort of object that may have nothing in common. Has you have seen, this imply a problem: python or an IDE can't predict until runtime what it have to manipulate. NOTA: this is true for everything in python, even for functions You could easily do something like this: class my_empty_object(object): pass # We create an empty object (without any method) meo = my_empty_object() # We create something like a method def f(string): print string #We add it to the object meo.func = f #Now we call it meo.func('it works!') it works! -- http://mail.python.org/mailman/listinfo/python-list
Re: Cross-platform GUI development
On Oct 12, 10:13 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I've been programming in Python for 5 or more years now and whenever I want a quick-n-dirty GUI, I use Tkinter. This is partly because it's the first toolkit I learnt, but also because it's part of the standard Python distribution and therefore easy to get Python apps to work cross platform - it usually requires almost no porting effort. However, when I need a little bit more grunt, I tend to turn to Tix, which I thought was also fairly standard. However, this week, I wrote a Tix application under Linux which I'd really like to work on Mac OS and it's proving fairly painful to get it going. There is no Tix in the standard fink or apt repositories and when I download a tar-ball, it wouldn't build because it had a lot of unmet dependencies. I then read a post which said that only Tkinter/Python people really use Tix anymore and people in tcl/tk moved onto better toolkits long ago. My question is if Tix is old hat, what is the GUI toolkit I *should* be using for quick-n-dirty cross platform GUI development? I guess this is tangentially related to: http://groups.google.com/group/comp.lang.python/browse_thread/thread/... I hope this isn't a stupid question. I'm wearing flame retardant underwear. Peter Personnaly, I use PyQt simply because I prefere Qt to Gtk, witch is much more integrated with all desktop than Gtk. In fact, your application in Qt on Mac, Win or Linux look like a native app. Just a question of feeling I think; because most of those GUI framework, offer quiet the same functionality. -- http://mail.python.org/mailman/listinfo/python-list
Launching command on windows
Hy, I'm working on windows and I try to do something like: import os APP = os.path.abspath(C:\\Program Files\\Notepad++\\notepad++.exe) FILE1 = os.path.abspath(D:\\Documents and settings\\test1.py) FILE2 = os.path.abspath(D:\\Documents and settings\\test2.py) command = '%(app)s %(file1)s %(file2)s' % { 'app' : APP, 'file1' : FILE1, 'file2' : FILE2} # === FOR 'DEBUG' === print APP print FILE1 print FILE2 print command print repr(command) # === END FOR 'DEBUG' === os.system(command) This code give in output: C:\Program Files\Notepad++\notepad++.exe D:\Documents and settings\test1.py D:\Documents and settings\test2.py C:\Program Files\Notepad++\notepad++.exe D:\Documents and settings \test1.py D:\Documents and settings\test2.py 'C:\\Program Files\\Notepad++\\notepad++.exe D:\\Documents and settings\\test1.py D:\\Documents and settings\\test2.py' 'C:\Program' n'est pas reconnu en tant que commande interne ou externe, un programme ex,cutable ou un fichier de commandes. # = My windows is a french one # This error message could be translated as: # 'c:\Program' is not an internal nor external command, an executable program nor a command file But if I copy the command in the output, an paste it in a console, it work very well. Does any of you know what I can do ? PS: I think I'm oblige to add neer every path for spaces in path, but if you know an other way, it could be cool :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Launching command on windows
On Sep 27, 4:20 pm, [EMAIL PROTECTED] wrote: I got it to work using subprocess.Popen Not sure why it doesn't work with os.system though. Mike Thanks Mike and Mauro, Mauro, your solution do not seems to work (or I made a mistake..) Mike your solution work great, thanks. But, I steel think it's a bug (python or window ??). I will try to take a look about it, when I have time. Alex -- http://mail.python.org/mailman/listinfo/python-list
Raw string printing
Hy ! I would like to do something like: s = ra\tb\n print s # result with a\tb\n print unraw(s) # = this is the magic function I'm searching for # result with ab n Does any of you know how to do it properly ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Raw string printing
On Sep 25, 2:24 pm, Peter Otten [EMAIL PROTECTED] wrote: Alexandre Badez wrote: I would like to do something like: s = ra\tb\n print unraw(s) # = this is the magic function I'm searching for # result with ab n Does any of you know how to do it properly ? print ra\tb\nx.decode(string-escape) a b x Peter THANKS :D -- http://mail.python.org/mailman/listinfo/python-list
Multi Heritage with slots
Hye, I'm developing a little app, and I want to make multi heritage. My problem is that my both parent do have __slots__ define. So I've got something like: class foo(object): __slots__ = ['a', 'b'] pass class foo2(object): __slots__ = ['c', 'd'] pass class crash(foo, foo2): pass If you write only that in a sample file or in python console (as I did), python refuse to load the module and report something like: Traceback (most recent call last): File stdin, line 1, in ? TypeError: Error when calling the metaclass bases multiple bases have instance lay-out conflict Do you know why it append? And how could I make this work? -- http://mail.python.org/mailman/listinfo/python-list
Re: Multi Heritage with slots
On Sep 5, 12:42 pm, Eric Brunel [EMAIL PROTECTED] wrote: Seehttp://mail.python.org/pipermail/python-list/2006-December/418768.html Basically, the general advice you're likely to get here is: don't use __slots__, or at least don't use __slots__ with inheritance. BTW, what are you trying to do? Is it really a memory footprint optimization, which is the intended use case for __slots__, or are you just doing Java in Python? -- python -c print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-']) Thanks for your answer. I use __slots__ not for memory optimization nor doing java. I use __slots__ because my class are used by other lib, and in the past, some of them misspell some attributes and involved a very annoying comportment of the global application. So the objective is only to prevent unwanted dynamism (but not in all the application, just some class). PS: I very like your signature ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: Multi Heritage with slots
On Sep 5, 2:56 pm, Michele Simionato [EMAIL PROTECTED] wrote: On Sep 5, 2:52 pm, Simon Brunning [EMAIL PROTECTED] wrote: On 9/5/07, Alexandre Badez [EMAIL PROTECTED] wrote: I use __slots__ not for memory optimization nor doing java. I use __slots__ because my class are used by other lib, and in the past, some of them misspell some attributes and involved a very annoying comportment of the global application. So the objective is only to prevent unwanted dynamism (but not in all the application, just some class). Using slots to prevent the creation of new properties is what Eric *means* by doing java. You're trying to write Java style code in Python, and it's not going to be pretty. Slots are not intended for this purpose, and they aren't very good for it. Right, and this the way to do what the original poster wants: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252158 Michele Simionato Thanks every body for your remarks. I still have a lot to learn in python... -- http://mail.python.org/mailman/listinfo/python-list
Re: Setting a read-only attribute
On Aug 30, 11:35 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I have an object and wish to set an attribute on it which, unfortunately for me, is read-only. How can I go about this? Cheers. -T Could you show the object you want to set his attribute? Until that, it's difficult to answer to you. PS: If the attribut is on read only, their must a good reason for that ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: What's the difference ?
Thanks for all you information. I'll continue to use 'in' instead of 'has_key' for a faster, more concise, readable code (^L^ ) -- http://mail.python.org/mailman/listinfo/python-list