[issue11354] argparse: nargs could accept range of options count

2011-04-11 Thread Wojciech Muła
Wojciech Muła wojciech_m...@poczta.onet.pl added the comment: Steven, thank you for links, I prepared patch against trunk. All tests passed. -- Added file: http://bugs.python.org/file21617/issue11354.patch ___ Python tracker rep...@bugs.python.org

[issue11397] os.path.realpath() may produce incorrect results

2011-03-05 Thread Wojciech Muła
Wojciech Muła wojciech_m...@poczta.onet.pl added the comment: Confirmed in python3.2. Lib/posixpath.py/_resolve_link: path returned by readlink is normalized by normpath. In this case readlink('zlink') returns 'xlink/../blink', then normpath is called, and returns 'blink'. This ends processing

[issue11354] argparse: nargs could accept range of options count

2011-03-02 Thread Wojciech Muła
Changes by Wojciech Muła wojciech_m...@poczta.onet.pl: Removed file: http://bugs.python.org/file20948/test.py ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11354

[issue11354] argparse: nargs could accept range of options count

2011-03-02 Thread Wojciech Muła
Wojciech Muła wojciech_m...@poczta.onet.pl added the comment: Daniel, thanks for note, fixed. -- Added file: http://bugs.python.org/file20981/test.py ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11354

[issue11354] argparse: nargs could accept range of options count

2011-02-28 Thread Wojciech Muła
New submission from Wojciech Muła wojciech_m...@poczta.onet.pl: Hi, sometimes it is needed to grab variable, but limited, number of options. For example --point could accept 2, 3 or 4 values: (x,y) or (x,y,z) or (x,y,z,w). Current version of argparse requires postprocessing

[issue11354] argparse: nargs could accept range of options count

2011-02-28 Thread Wojciech Muła
Wojciech Muła wojciech_m...@poczta.onet.pl added the comment: tests -- Added file: http://bugs.python.org/file20948/test.py ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11354

Re: interleave string

2011-02-15 Thread Wojciech Muła
On Tue, 15 Feb 2011 10:53:56 +0100 Andrea Crotti andrea.crott...@gmail.com wrote: Just a curiosity not a real problem, I want to pass from a string like xxaabbddee to xx:aa:bb:dd:ee so every two characters insert a :. At the moment I have this ugly inliner interleaved =

Re: use strings to call functions

2010-02-08 Thread Wojciech Muła
Klaus Neuner klausneune...@googlemail.com wrote: handlers = {     .txt : handle_txt,     .py : handle_py,     # etc     } That is exactly what I would like to avoid: Having to map the function 'handle_txt' to '.txt'. Firstly, because I don't want to repeat anything and secondly,

Re: assert type([]) == type(())

2010-01-02 Thread Wojciech Muła
VanceE vne...@invalid.invalid wrote: for x in []: assert type(x) == type(()) I expected an AssertionError but get no errors at all. Any explaination? [] is an empty sequence, so your loop executes exactly 0 times. :) for x in [None]: assert ... w. --

Re: [OT] stable algorithm with complexity O(n)

2008-12-13 Thread Wojciech Muła
David Hláčik da...@hlacik.eu wrote: I have to create stable algorithm for sorting n numbers from interval [1,n^2] with time complexity O(n) . Some kind of radix sort or counting sort. These algo. has O(n) complexity. w. -- http://mail.python.org/mailman/listinfo/python-list

Re: 1 or 1/0 doesn't raise an exception

2008-12-13 Thread Wojciech Muła
Daniel Fetchinson fetchin...@googlemail.com wrote: Is it a feature that 1 or 1/0 returns 1 and doesn't raise a ZeroDivisionError? If so, what's the rationale? See: http://en.wikipedia.org/wiki/Short-circuit_evaluation -- http://mail.python.org/mailman/listinfo/python-list

Re: Memory Leak with Tkinter Canvas (Python 2.5 Win32)

2007-08-02 Thread Wojciech Muła
frikk wrote: [...] As you can see- I am doing nothing other than drawing a lot of rectangles on the canvas. You aren't drawing, but **creating** rectangle objects, as a meth. name suggests. You find more info at tkinter.effbot.org. [...] def clear_grid(): canv.delete(ALL)

Re: split a string of space separated substrings - elegant solution?

2007-07-31 Thread Wojciech Muła
Helmut Jarausch wrote: Hi, I'm looking for an elegant solution to the following (quite common) problem: Given a string of substrings separated by white space, split this into tuple/list of elements. The problem are quoted substrings like abc xy z 1 2 3 a \ x should be split into

Re: custom plugin architecture: how to see parent namespace?

2007-07-22 Thread Wojciech Muła
escalation746 wrote: def ViewValuable(): [...] code = Hello() Plus() Valuable() These names don't match. I replaced Valuable() with proper name, and everything work fine. w. -- http://mail.python.org/mailman/listinfo/python-list

Re: Itertools question: how to call a function n times?

2007-07-19 Thread Wojciech Muła
Matthew Wilson wrote: I want to write a function that each time it gets called, it returns a random choice of 1 to 5 words from a list of words. I can write this easily using for loops and random.choice(wordlist) and random.randint(1, 5). But I want to know how to do this using itertools,

Re: atexit, sys.exit, sys.exitfunc, reaching end of source code

2007-07-11 Thread Wojciech Muła
[EMAIL PROTECTED] wrote: I am playing with the atexit module but I don't find a way to see the difference between a script calling sys.exit(returncode) and the interpreting arriving at the end of the source code file. This has a semantic difference for my applications. Is there a way to

Re: Tkinter toggle a Label Widget based on checkbutton value

2007-07-04 Thread Wojciech Muła
O.R.Senthil Kumaran wrote: Any suggestions on how can i make this checkbutton effect. 1) Press Enable IP, the Label IP should be shown. 2) Toggle Enable IP (So that its unset). the Label IP should not be shown. #!/usr/bin/python from Tkinter import * root = Tk() root.title('something') x

Re: tkinter paint program

2007-04-24 Thread Wojciech Muła
Gigs_ wrote: I'm working on tkinter paint program, mostly to learn tkinter canvas. I have method which create buttons for oval, rectangle, line, polygon etc. How to make oval button to be sunken when i click it and to remain sunken until i click on another button (like rectangle and than is

Re: regular expression for parsing an html element

2007-04-20 Thread Wojciech Muła
abcd wrote: My regex so far is: src=\(.*)\ however the group in this case would end up being, image/blah/a.jpg id=dblah blah blah/ a. how can I tell the regex group (.*) to end when it gets to the first ? Use non-greedy matching, i.e. src=\(.*?)\ (question mark after *.) See:

Re: list comparison help?

2007-04-14 Thread Wojciech Muła
Dropkick Punt wrote: prefixes = [ the, this, that, da, d, is, are, r, you, u] And I have a string, that I split() into a list. sentence = what the blazes is this sentence = sentence.split() Now I want to strip the sentence of all words in the prefix list. I tried this method:

Re: Saving output of Turtle Graphics?

2007-04-07 Thread Wojciech Muła
Dick Moores wrote: I accidentally stumbled across the Turtle Graphics module (turtle.py) the other day and have been having some fun with it. Now I'm wondering if there is a way to build into a script the saving of each window just before it is cleared. For example, here are a couple

Re: Checking whether list element exists

2007-04-07 Thread Wojciech Muła
Rehceb Rotkiv wrote: I want to check whether, for example, the element myList[-3] exists. So far I did it like this: index = -3 if len(myList) = abs(index): print myList[index] IMHO it is good way. Another idea I had was to (ab-?)use the try...except structure: index = -3 try:

Re: Saving output of Turtle Graphics?

2007-04-07 Thread Wojciech Muła
Dick Moores wrote: Turtle module uses Tk canvas element to draw graphics ('_canvas' attribute). I've written module, that exports canvas graphics to SVG file: http://wmula.republika.pl/proj/canvas2svg/ -- it may be useful for you. I afraid I'm totally unfamiliar with SVG. Would it be

Re: Saving output of Turtle Graphics?

2007-04-07 Thread Wojciech Muła
Dick Moores wrote: What do I do to see this? For example Opera 9 and Firefox 1.5+ are able to view SVG files; there is a free plugin for IrfanView. w. -- http://mail.python.org/mailman/listinfo/python-list

Re: 08 and 09 in sequence create invalid token error?!

2007-04-06 Thread Wojciech Muła
IamIan wrote: I am confused as to why including 08 or 09 in a sequence (list or tuple) causes this error. All other numbers with a leading zero work. All literals that start with 0 digit are considered as octal numbers, i.e. only digits 0..7 are allowed. See octinteger lexical definition:

Re: Cascading ifs

2007-04-02 Thread Wojciech Muła
Ernesto García García wrote: Hi experts, How would you do this without the more and more indenting cascade of ifs?: match = my_regex.search(line) if match: doSomething(line) else: match = my_regex2.search(line) if match: doSomething2(line) else: match =

Re: pattern search

2007-03-27 Thread Wojciech Muła
Fabian Braennstroem wrote: Now, I would like to improve it by searching for different 'real' patterns just like using 'ls' in bash. E.g. the entry 'car*.pdf' should select all pdf files with a beginning 'car'. Does anyone have an idea, how to do it? Use module glob. --

Re: call to function by text variable

2007-03-25 Thread Wojciech Muła
ianaré wrote: like this: list = [Replace, ChangeCase, Move] textVariable = list[n] self.operations.insert(pos, operations.[textVariable].Panel(self, main)) Is something sort of like that possible? Yes: self.operations.insert( pos, getattr(operations,

Re: XML minidom Parsing and ToPrettyXML

2007-03-25 Thread Wojciech Muła
Paul Kozik wrote: However, if I use xml.minidom.parse to parse the xml document, change a few attributes with setAttribute, then write back with toprettyxml, my XML file gets loaded up with spaces between many of the elements. Use 'toxml' method, that writes XML document without any

Re: interpreting glyph outlines from ttfquery?

2007-03-22 Thread Wojciech Muła
swiftset wrote: I'm try to convert a glyph into a format I can easily numerically manipulate. So far I've figured out how to use ttfquery to get a list that represents the outline of a contour in a glyph: from ttfquery import describe, glyphquery, glyph f =

Re: Vim search under cursor

2007-02-07 Thread Wojciech Muła
[EMAIL PROTECTED] wrote: Hi, I am using gvim to edit python source files. When I press * or #, I would want to search for the attribute name under the cursor and not the entire string. For example, If I have os.error and pressing * on top of error searches for os.error rather than error. How

Re: Conversion of string to integer

2007-01-29 Thread Wojciech Muła
jupiter wrote: I have a problem. I have a list which contains strings and numeric. What I want is to compare them in loop, ignore string and create another list of numeric values. I tried int() and decimal() but without success. eq of problem is #hs=string.split(hs) hs

Re: Trouble with max() and __cmp__()

2007-01-28 Thread Wojciech Muła
Thomas Nelson wrote: My code: class Policy(list): def __cmp__(self,other): return cmp(self.fitness,other.fitness) Define method __gt__. -- http://mail.python.org/mailman/listinfo/python-list

Re: More Efficient fnmatch.fnmatch for multiple patterns?

2007-01-08 Thread Wojciech Muła
abcd wrote: I am using fnmatch.fnmatch to find some files. The only problem I have is that it only takes one pattern...so if I want to search using multiple patterns I have to do something like patterns = ['abc*.txt', 'foo*'] for p in patterns: if fnmatch.fnmatch(some_file_name,

Re: Change coords of a canvas.line item

2007-01-05 Thread Wojciech Muła
Fredrik Lundh wrote: Matthias Vodel wrote: I want to change the beginning/end-coordinates of a canvas.line item. Something like: self.myCanvas.itemconfigure(item_id, coords=(x1_new, y1_new, x2_new, y2_new)) self.myCanvas.coords(item_id, x1_new, y1_new, x2_new, y2_new) You can also

Re: Fuzzy string comparison

2006-12-26 Thread Wojciech Muła
Steve Bergman wrote: I'm looking for a module to do fuzzy comparison of strings. [...] Check module difflib, it returns difference between two sequences. -- http://mail.python.org/mailman/listinfo/python-list

Re: length of multidimensional table

2006-12-17 Thread Wojciech Muła
vertigo wrote: i have: x = zeros([3,4],Float) how can i check how many rows and columns x have ? (what is the X and Y size of that table) ? Data member x.shape (tuple) contains dimensions of array. -- http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter: Strange behavior using place() and changing cursors

2006-11-14 Thread Wojciech Muła
Mudcat wrote: [...] You have to set cursor once, Tk change it automatically: def buildFrame(self): self.f = Frame(self.master, height=32, width=32, relief=RIDGE, borderwidth=2) self.f.place(relx=.5,rely=.5) #self.f.bind( 'Enter',

Re: Tkinter: Strange behavior using place() and changing cursors

2006-11-14 Thread Wojciech Muła
Mudcat wrote: I have also determined that this is not a problem if the button is not packed inside the frame. So somehow the interaction of the internal button is causing this problem. Problem is really strange, and seems to be a Tk issue, not Tkinter. I've observed that if method configure

Re: How to choose the right GUI toolkit ?

2006-11-09 Thread Wojciech Muła
Nick Craig-Wood wrote: It's very mature, full-featured, and portable, and fairly easy to learn as well. ...with native look and feel on each platform unlike GTK / TK AFAIK Tk 8 uses platform's native widgets. w. -- http://mail.python.org/mailman/listinfo/python-list

Re: string formatter for tuple

2006-11-02 Thread Wojciech Muła
Tim Chase wrote: print a = %s % repr(a) or print a = %r % (a,) -- http://mail.python.org/mailman/listinfo/python-list

Re: create global variables?

2006-10-30 Thread Wojciech Muła
Alistair King wrote: is there a simple way of creating global variables within a function? def foo(name): globals()[name] = xxx globals()[name + 'aa'] = yyy globals()[name + 'ab'] = zzz -- http://mail.python.org/mailman/listinfo/python-list

Re: Negative hex to int

2006-06-14 Thread Wojciech Muła
[EMAIL PROTECTED] wrote: The problem is negative values. If the unit returns the hex value 'e7', it means -25, but python says it's 231: --- int('e7', 16) 231 --- Does anyone have a clue a to what I need to do? def u2(x): if x 0x80:

Re: math.pow(x,y)

2006-06-11 Thread Wojciech Muła
fl1p-fl0p wrote: import math math.pow(34564323, 456356) will give math range error. how can i force python to process huge integers without math range error? Any modules i can use possibly? You have to use operator **, i.e. 34564323**456356 --

Re: Sorting of list containing tuples

2006-05-18 Thread Wojciech Muła
Ronny Mandal wrote: Assume we have a list l, containing tuples t1,t2... i.e. l = [(2,3),(3,2),(6,5)] And now I want to sort l reverse by the second element in the tuple, i.e the result should ideally be: l = [(6,5),(2,3),(3,2)] Any ideas of how to accomplish this? def cmpfun(a,b):

Re: index in for loops

2006-05-17 Thread Wojciech Muła
manstey wrote: in for loops like the following: word='abcade' for letter in word: print letter Is it possible to get the position of letter for any iteration through the loop? for index, letter in enumerate(word): print index, letter --

Re: list example

2006-04-22 Thread Wojciech Muła
PAolo wrote: any comment, suggestion? Is there something not elegant? Try this: even = range(10)[0::2] odd = range(10)[1::2] -- http://mail.python.org/mailman/listinfo/python-list