Re: Use and usefulness of the as syntax
On Nov 12, 7:48 am, Rafael Durán Castañeda rafadurancastan...@gmail.com wrote: El 12/11/11 13:43, Tim Chase escribió: I hate trying to track down variable-names if one did something like from Tkinter import * +1 Really, this questionable code is always mentioned as example in Tkinter tuts. IMHO much better is import Tkinter as tk In common case `as` is useful when: 1. You `import ThirdPartyModuleWithTerriblyLongName as tpm` 2. Whant to free some common variable name, which is engaged by module name by default (right what Mel Wilson has pictured) -- http://mail.python.org/mailman/listinfo/python-list
RE: Dynamically altering __init__
I wrote: I will post a link to a complete example once I have done the AST transformations etc. I hope this will be useful to readers of this list. I didn't find such an example, so maybe the next asker will find it... Finally got time to do this. The example can be found at: https://github.com/akaariai/ast_model In the example I rewrote a small part of Django's model __init__ to use: self.field1, self.field2, ... = args instead of: for f_name, val in izip(field_names, args): setattr(self, f_name, val) The speedup of that rewrote is about 50% for a model having 10 fields. The example implementation might not be optimal, but it seems to work. I hope it will be useful to the readers of this list. It was a nice learning experience for me. Thanks for your help, - Anssi Kääriäinen -- http://mail.python.org/mailman/listinfo/python-list
socket.socket.makefile
I'm writing an alternative socket module, and have come across the code for the makefile call, which mentions the following: (XXX refactor to share code?) http://hg.python.org/cpython/file/27adb952813b/Lib/socket.py#l149 Has this been refactored elsewhere? Is there something I can use to wrap the SocketIO inheriting from RawIOBase in all the variants the io.open/socket.makefile functions return for me? -- http://mail.python.org/mailman/listinfo/python-list
How to indent blocks when readline completion is on?
I have set up readline completion as described here: http://docs.python.org/library/rlcompleter.html Now how do I indent blocks in the interactive interpreter? If I press the TAB key, the completer prompts me instead of indenting: readline.parse_and_bind(tab: complete) while True: ... Display all 182 possibilities? (y or n) ... Surely I'm not stuck with indenting by manually typing spaces? I thought I could add a wrapper around the rlcompleter method, like this: import readline import rlcompleter readline.parse_and_bind(tab: complete) completer = readline.get_completer() def wrapped_completer(text, state): ... if not text or text.isspace(): ... return \t ... else: ... return completer(text, state) ... readline.set_completer(wrapped_completer) Completion appears to work if I have something in the line to start with, e.g. if I type whi TAB Tr TAB I get while True, but if I press TAB on an empty line (intending to get an actual tab character for indentation), it plays merry havoc with my session. All keyboard input appears to be dead, eventually I used Ctrl-Z to interrupt the process and killed it from the shell. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: How to indent blocks when readline completion is on?
On Mon, Nov 14, 2011 at 12:30 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I thought I could add a wrapper around the rlcompleter method, like this: import readline import rlcompleter readline.parse_and_bind(tab: complete) completer = readline.get_completer() def wrapped_completer(text, state): ... if not text or text.isspace(): ... return \t ... else: ... return completer(text, state) ... readline.set_completer(wrapped_completer) Attempting to duplicate this failed in my Py3 (no readline module - probably I didn't have the dev version when I built that Python), but in Py2, I can see the same issue. The wrapped_completer function is called repeatedly with successive values for 'state', and it needs to return None at some point to indicate that there are no more possibilities. (Why isn't it specced to simply return an iterable?) def wrapped_completer(text, state): ... if not text or text.isspace(): ... if state: return None ... return \t ... else: ... return completer(text, state) ... This function appears (to me!) to do what you're looking for; it allows me to enter tabs while still using tab completion. However, I seem to have some slightly different tab-completion settings somewhere (for instance, typing whi TAB produces while with no space after it, so I need to type Tr not Tr), so this may not work on your setup. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: xmlrpclib date times and a trailing Z
On Nov 11, 7:20 pm, Travis Parks jehugalea...@gmail.com wrote: I am trying to connect to Marchex's a call tracking software using xmlrpclib. I was able to get some code working, but I ran into a problem dealing with transfering datetimes. When I construct a xmlrpclib.ServerProxy, I am setting the use_datetime flag to indicate that I want to automatically convert back and forth between date times in the datetime library. I have a working version that doesn't use this flag, and I have to convert from the xmlrpclib.DateTime type to the datetime.datetime type manually, via string parsing. The thing is, Marchex's API returns date's with a trailing Z, after the time component. I did some research and this is supposed to be an indicator that UTC was used. However, it doesn't seem like the xmlrpclib likes it very much. It looks like it is using this code internally: time.strptime(data, %Y %m%dT%H:%M:%S) This code doesn't look like it handles time zones at all. I guess, is there a way to tell xmlrpclib to include time zones when parsing date times? Thanks, Travis Parks I did some chatting on IRC and it seems that the date/time format is not very well defined in XML RPC specs. So, basically, Marchex is using a format that the XML RPC library doesn't support. Strangely, Marchex supports incoming dates with the format MMddThhmmss. It just spits dates back out with -MM-ddThh:mm:ssZ. The ISO8601 standard seems to be used a lot, so it is surprising the library doesn't try multiple formats, at least. I find it strange that the library, in light of the fact that date formats aren't standardized, doesn't provide the ability to configure this. I also find it strange that the library doesn't incorporate Basic Authentication using urllib2, but instead rolls its own method of putting username:password@ before the netloc. I wish Python's libraries acted more like an integrated framework than just unrelated libraries. I suppose I am spoiled from years of working with all-in-one frameworks managed by a single group. That is not the way C/C++ works or how Linux works. The power generated by using a conglomeration of unrelated libraries is indisputable, even if it can be a productivity killer and just plain confusing. -- http://mail.python.org/mailman/listinfo/python-list
Uninstalling Py 2.5.2 from Windows 7
For many months I had sporadically used 2.5.2 under Win 7, then something went awry. I tried an uninstall/install and it didn't get any better. I thought I'd take another shot at it today. The uninstall went OK, but c:\python25 remained with several py files and a folder, Lib. I went ahead with the install and got a msg that asked if I wanted to write over the python25 folder. I figured maybe I should ask about this. It's probably OK. Yes, I know I have an old version of Python, but I need it occasionally. Comments? -- http://mail.python.org/mailman/listinfo/python-list
can't decompress data; zlib not available
Hi, I'm trying to install a tool for Plone called ZopeSkel, but when I run the setup file ez_setup.py, I get dr_shred@merle:~$ ez_setup.py Downloading http://pypi.python.org/packages/2.4/s/setuptools/setuptools-0.6c11-py2.4.egg Traceback (most recent call last): File /home/dr_shred/python/ez_setup.py, line 279, in ? main(sys.argv[1:]) File /home/dr_shred/python/ez_setup.py, line 213, in main from setuptools.command.easy_install import main zipimport.ZipImportError: can't decompress data; zlib not available I believe this means the python installation didn't include zlib. Python was installed with Plone and has the following config directory: dr_shred@merle:/usr/local/Plone/Python-2.6/lib/python2.6/config$ ls -l total 10208 -rw-r--r-- 1 root root 2139 2011-10-24 17:53 config.c -rw-r--r-- 1 root root 1507 2011-10-24 17:53 config.c.in -rwxr-xr-x 1 root root 7122 2011-10-24 17:53 install-sh -rw-r--r-- 1 root root 10342706 2011-10-24 17:53 libpython2.6.a -rw-r--r-- 1 root root42568 2011-10-24 17:53 Makefile -rwxr-xr-x 1 root root 7431 2011-10-24 17:53 makesetup -rw-r--r-- 1 root root 6528 2011-10-24 17:53 python.o -rw-r--r-- 1 root root18265 2011-10-24 17:53 Setup -rw-r--r-- 1 root root 368 2011-10-24 17:53 Setup.config -rw-r--r-- 1 root root 41 2011-10-24 17:53 Setup.local There's no readme file, or anything to describe how it all works. The Setup file has an entry zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz which appears to install zlib when python is reinstalled. Except I can't run make without errors and there is no configuration file. How do I reinstall python to include zlib? Many Thanks, Steve Edlefsen -- http://mail.python.org/mailman/listinfo/python-list
(n00b) Tkinter trouble
Hello, I'm trying my hand at creating a Tkinter application, but not having much luck. I'm trying to have my top level window be a series of buttons with different options on them. Every time a button is pressed, it opens up a new window with options. While that new window is open, all of the buttons on the original window are disabled. However, I want all of those buttons to become active again once I quit my new window. I can't seem to reactivate those buttons no matter what I do. This is the approach I'm trying: #!/usr/bin/env python from Tkinter import * class ActionButton(Button): def __init__(self, frame, text): self.frame = frame Button.__init__(self, master=self.frame, text=text, command=self.execute) def execute(self): window = Toplevel() new_button = ActionButton(window, '2nd level button') quit_button = Button(window, text='Quit!', command=window.destroy) window.buttons = [new_button, quit_button] for button in window.buttons: button.pack() # Deactivate buttons from containing shell for button in self.frame.buttons: button.config(state=DISABLED) window.mainloop() for button in self.frame.buttons: button.config(state=ACTIVE) top = Tk() top_button = ActionButton(top, 'Button on top!') top_button.pack() quit_button = Button(top, text='Quit', command=top.destroy) quit_button.pack() top.buttons = [top_button, quit_button] top.mainloop() I'm really kind of running around in the dark here, so any advice or explanation is appreciated. Thanks! Jason -- http://mail.python.org/mailman/listinfo/python-list
Re: Uninstalling Py 2.5.2 from Windows 7
On 13-11-11 18:46, W. eWatson wrote: For many months I had sporadically used 2.5.2 under Win 7, then something went awry. I tried an uninstall/install and it didn't get any better. I thought I'd take another shot at it today. The uninstall went OK, but c:\python25 remained with several py files and a folder, Lib. I went ahead with the install and got a msg that asked if I wanted to write over the python25 folder. I figured maybe I should ask about this. It's probably OK. Yes, I know I have an old version of Python, but I need it occasionally. Comments? Just go ahead and manually delete c:\python25 and everything in it. But make sure that the leftover stuff in there is something you won't need again, or that you can get back by re-installing the third party library that it was part of. Then re-install from the 2.5.2 msi. (Or perhaps 2.5.4). Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: can't decompress data; zlib not available
On Sun, 2011-11-13 at 11:17 -0700, Steve Edlefsen wrote: which appears to install zlib when python is reinstalled. Except I can't run make without errors and there is no configuration file. How do I reinstall python to include zlib? Which OS are you on? Linux? BSD? How did you install Plone? First I'd check if there's a module shadowing the builtin zlib module - i.e. if you've got a local file called zlib.py which is getting imported by mistake. Fairly much all *nix systems will have a python installation out of the box - it looks like you need python2.6 I've never had a missing zlib module - but it's possible that it might be missing if you don't have the zlib/deflate headers installed - if they're not available then I'd try installing them and then reinstalling the package you started with. Tim Wintle -- http://mail.python.org/mailman/listinfo/python-list
Re: Uninstalling Py 2.5.2 from Windows 7
On 11/13/2011 12:46 PM, W. eWatson wrote: For many months I had sporadically used 2.5.2 under Win 7, then something went awry. I tried an uninstall/install and it didn't get any better. I thought I'd take another shot at it today. The uninstall went OK, but c:\python25 remained with several py files and a folder, Lib. I went ahead with the install and got a msg that asked if I wanted to write over the python25 folder. Uninstall (should) only uninstall files that it installed and directories that are empty. The 'several py files' should be files that you or some third-party software installed. I personally put everything I write under /pythonxy in a subdirectory thereof that install and uninstall pay no attention to. The Lib directory contains all the python-coded stdlib modules. Unless you know there is something that you wrote that you want, I would delete it before re-installing. I suspect that current installers work a bit better than 2.5. I would definitely use the latest 2.5.z that comes with an installer and not 2.5.2. They are all the same version of the language. The only difference is bug fixes. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Use and usefulness of the as syntax
On 11/13/2011 3:55 AM, 0xfn wrote: On Nov 12, 7:48 am, Rafael Durán Castañeda rafadurancastan...@gmail.com wrote: El 12/11/11 13:43, Tim Chase escribió: I hate trying to track down variable-names if one did something like from Tkinter import * +1 Really, this questionable code is always mentioned as example in Tkinter tuts. I see it is still in the 3.2 tkinter doc, near the top. IMHO much better is import Tkinter as tk My opinion also. I will think about changing it someday, but then all the examples will need to be changed ;-). So it will not be trivial. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Trying to write beautifulsoup result to a file and get error message
If I try: ... soup = BeautifulSoup(ft3) f = open(r'c:\NewFolder\clean4.html', w) f.write(soup) f.close() I get error message: Traceback (most recent call last): File C:\Documents and Settings\user01\Desktop\py\tb1a.py, line 203, in module f.write(soup) TypeError: expected a character buffer object I want to write beautiful soup's result to a file, I am doing something wrong. Help appreciated. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to write beautifulsoup result to a file and get error message
On 13/11/2011 22:37, goldtech wrote: If I try: ... soup = BeautifulSoup(ft3) f = open(r'c:\NewFolder\clean4.html', w) f.write(soup) f.close() I get error message: Traceback (most recent call last): File C:\Documents and Settings\user01\Desktop\py\tb1a.py, line 203, inmodule f.write(soup) TypeError: expected a character buffer object I want to write beautiful soup's result to a file, I am doing something wrong. Help appreciated. What do you mean by beautiful soup's result? The original HTML is text, and you want it to write some text to the file, but what exactly are you expecting it to write? -- http://mail.python.org/mailman/listinfo/python-list
Re: Uninstalling Py 2.5.2 from Windows 7
On 11/13/2011 2:08 PM, Terry Reedy wrote: On 11/13/2011 12:46 PM, W. eWatson wrote: For many months I had sporadically used 2.5.2 under Win 7, then something went awry. I tried an uninstall/install and it didn't get any better. I thought I'd take another shot at it today. The uninstall went OK, but c:\python25 remained with several py files and a folder, Lib. I went ahead with the install and got a msg that asked if I wanted to write over the python25 folder. Uninstall (should) only uninstall files that it installed and directories that are empty. The 'several py files' should be files that you or some third-party software installed. I personally put everything I write under /pythonxy in a subdirectory thereof that install and uninstall pay no attention to. The Lib directory contains all the python-coded stdlib modules. Unless you know there is something that you wrote that you want, I would delete it before re-installing. I suspect that current installers work a bit better than 2.5. I would definitely use the latest 2.5.z that comes with an installer and not 2.5.2. They are all the same version of the language. The only difference is bug fixes. Thanks to both of you. Deleting python25 folder. Nothing of personal use in it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Uninstalling Py 2.5.2 from Windows 7
Well, let be a careful a little more. I have PIL, numpy, scipy, pymatplotlib and pyephem installed, I think. There are Removeexe files in the python25 folder for them. There's also a Removepy2exe.exe. Probably that was somehow used to get out py2.5. -- http://mail.python.org/mailman/listinfo/python-list
[ANN] PikoTest.py - a small testing library
I released PikoTest.py 0.1.0. http://pypi.python.org/pypi/PicoTest PikoTest.py is a samll testing library for Python. Features: * Structured Test * Setup/Teardown * Fixture Injection * Skip Test * TODO Example:: from __future__ import with_statement import picotest test = picotest.new() with test(type 'str'): with test(operator '*'): @test(repeats string N times.) def _(self): self.assertEqual(AAA, A * 3) @test(returns empty string when N is negative.) def _(self): self.assertEqual(, A * -1) if __name__ == '__main__': picotest.main() Output example:: $ python -m picotest -h# show help $ python example_test.py # or python -m picotest example_test.py example_test.py * type 'str' * operator '*' - [passed] repeats string N times. - [passed] returns empty string when N is negative. ## total:2, passed:2, failed:0, error:0, skipped:0, todo:0 See http://pypi.python.org/pypi/PicoTest for details. -- regards, makoto kuwata -- http://mail.python.org/mailman/listinfo/python-list
Slave to master auto linking.
Hello. I try make some weird thing. I want to get from code like this: class master: ... class slave: ... m = master() s = m.slave() s.master is m Last expression must be true. I want link master to be set automatically by master object while creating slave object. Additional requirement - master link must be available for constructor of slave object. Best what I can get is: import functools from weakref import WeakKeyDictionary from threading import RLock class meth_wrap(object): def __init__(self, func): object.__init__(self) self.func = func functools.update_wrapper(self, func, updated=()) class lazy_attr(meth_wrap): def __get__(self, obj, type=None): if obj is None: return self val = self.func(obj) setattr(obj, self.__name__, val) return val class slave_mixin(object): @lazy_attr def master(self): m = slave_gen._unbound_master assert m is not None, 'Slave object can\'t find master link. Is it was correctly created? obj:%s' % repr(self) return m class slave_gen(meth_wrap): _storage = WeakKeyDictionary() # Используется глобально _unbound_master = None _lock = RLock() def __get__(self, mobj, type=None): if mobj is None: return self.func d = { 'm': mobj, 'w': self} obj = self.delay_init() self._storage[obj] = d functools.update_wrapper(obj, self.func, updated=()) return obj class delay_init(object): def __call__(self, *args, **kw_args): d = slave_gen._storage[self] slave_gen._lock.acquire() try: slave_gen._unbound_master = d['m'] obj = d['w'].func(*args, **kw_args) obj.master = d['m'] slave_gen._unbound_master = None finally: slave_gen._lock.release() return obj def __getattr__(self, attr): d = slave_gen._storage[self] return getattr(d['m'], attr) def __setattr__(self, attr, val): d = slave_gen._storage[self] return setattr(d['m'], attr, val) class Master(object): @slave_gen class Slave(slave_mixin): def __init__(self): slave_mixin.__init__(self) print 'Slave.__init__: self.master: ', self.master if __name__ == '__main__': m = Master() s = m.Slave() print 's.master: ', s.master It works, by looking little weird... and I can't find way to escape from using lock at object creation phase. It can be done by adding mandatory attribute to slave class constructor, but this is even worse(for me) than using lock. Please show me more clear way to make this slave to master link. PS Sorry for my English. -- Богун Дмитрий aka vugluskr -- http://mail.python.org/mailman/listinfo/python-list
Re: Slave to master auto linking.
2011/11/14 Богун Дмитрий vuglu...@vugluskr.org.ua: m = master() s = m.slave() s.master is m Can you simply have m.slave() pass a parameter to the slave's constructor? class Master(object): class Slave(object): def __init__(self,master): self.master=master print 'Slave.__init__: self.master: ', self.master def slave(self): return self.Slave(self) Alternatively, you don't have to nest the classes at all: class Slave(object): def __init__(self,master): self.master=master print 'Slave.__init__: self.master: ', self.master class Master(object): def slave(self): return Slave(self) By passing 'self' to the Slave() constructor, I give the slave a chance to keep a reference to its own master. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list
Re: all() is slow?
On Nov 13, 4:28 pm, Devin Jeanpierre jeanpierr...@gmail.com wrote: which implies that getattr(x, 'a!b') should be equivalent to x.a!b No, it does not. The documentation states equivalence for two particular values It states equivalence for two values _based on the name_. If the string is the name of one of the object’s attributes, the result is the value of that attribute. For example, getattr(x, 'foobar') is equivalent to x.foobar. The string 'a!b' is the name of the attribute, ergo getattr(x, 'a!b') _is_ x.a!b. If x.a!b isn't valid CPython, then etc. CPython breaks that equivalence So you're outright ignoring the comments that this behaviour is to make CPython more performant? -- http://mail.python.org/mailman/listinfo/python-list
Re: all() is slow?
It states equivalence for two values _based on the name_. I don't know what you mean. Based on the name doesn't mean anything in particular to me in this context. So you're outright ignoring the comments that this behaviour is to make CPython more performant? I don't see how I'm ignoring the comment. Yes, breaking the spec improves performance. Is that a reason to not fix the spec, or something? Devin On Sun, Nov 13, 2011 at 9:50 PM, alex23 wuwe...@gmail.com wrote: On Nov 13, 4:28 pm, Devin Jeanpierre jeanpierr...@gmail.com wrote: which implies that getattr(x, 'a!b') should be equivalent to x.a!b No, it does not. The documentation states equivalence for two particular values It states equivalence for two values _based on the name_. If the string is the name of one of the object’s attributes, the result is the value of that attribute. For example, getattr(x, 'foobar') is equivalent to x.foobar. The string 'a!b' is the name of the attribute, ergo getattr(x, 'a!b') _is_ x.a!b. If x.a!b isn't valid CPython, then etc. CPython breaks that equivalence So you're outright ignoring the comments that this behaviour is to make CPython more performant? -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Uninstalling Py 2.5.2 from Windows 7 (Invalid on Win 32 app)
I just pushed aside the python25 folder by renaming it, and installed py 2.5.2. However, when I try to open the simplest of py programs with IDLE, I get an error from Win7. c:\Users\blah\...\junk.py is not a valid Win 32 app. Here's one: def abc(one): print abc: , one, is one def duh(two): print duh: ,abc(2) abc(1) duh(2) duh(so what) abc(36.333) -- http://mail.python.org/mailman/listinfo/python-list
Re: Get keys from a dicionary
On Nov 11, 11:31 pm, macm moura.ma...@gmail.com wrote: I pass a nested dictionary to a function. def Dicty( dict[k1][k2] ): print k1 print k2 There is a fast way (trick) to get k1 and k2 as string. It might be possible to do something using a reverse dictionary and getting rid of the nested dictionary. This is a quick and simple 'two-way' dictionary class that works by maintaining two dictionaries: the original key/value, and the reversed value/key. It returns a list of keys, allowing for a value to be assigned against more than from collections import defaultdict class TwoWayDict(dict): def __init__(self, *args, **kwargs): self._reversed = defaultdict(list) for key, val in kwargs.iteritems(): self[key] = val def __setitem__(self, key, value): super(TwoWayDict, self).__setitem__(key, value) self._reversed[value].append(key) def getkeys(self, match): return self._reversed[match] original = TwoWayDict(a=100,b='foo',c=int,d='foo') original.getkeys(100) ['a'] original.getkeys('foo') ['b', 'd'] As for the nested dictionary, you could replace it with a _single_ dictionary that uses a composite key: original = TwoWayDict(a=100,b=100) original.getkeys(100) ['a', 'b'] original = TwoWayDict() original['record1','user1'] = 'martin' original['record1','user2'] = 'robert' original['record2','user1'] = 'robert' original.getkeys('robert') [('record1', 'user2'), ('record2', 'user1')] Whithout loop all dict. Just it! The TwoWayDict class removes the need to loop across the dict looking for keys that match a value by replacing it with another dict lookup. Reducing the nested dict to a single dict with composite keys removes the need to traverse the outer dict to compare against its children. -- http://mail.python.org/mailman/listinfo/python-list
Re: Get keys from a dicionary
On Nov 11, 11:31 pm, macm moura.ma...@gmail.com wrote: I pass a nested dictionary to a function. def Dicty( dict[k1][k2] ): print k1 print k2 There is a fast way (trick) to get k1 and k2 as string. It might be possible to do something using a reverse dictionary and getting rid of the nested dictionary. This is a quick and simple 'two-way' dictionary class that works by maintaining two dictionaries: the original key/value, and the reversed value/key. It returns a list of keys, allowing for a value to be assigned against more than from collections import defaultdict class TwoWayDict(dict): def __init__(self, *args, **kwargs): self._reversed = defaultdict(list) for key, val in kwargs.iteritems(): self[key] = val def __setitem__(self, key, value): super(TwoWayDict, self).__setitem__(key, value) self._reversed[value].append(key) def getkeys(self, match): return self._reversed[match] original = TwoWayDict(a=100,b='foo',c=int,d='foo') original.getkeys(100) ['a'] original.getkeys('foo') ['b', 'd'] As for the nested dictionary, you could replace it with a _single_ dictionary that uses a composite key: original = TwoWayDict(a=100,b=100) original.getkeys(100) ['a', 'b'] original = TwoWayDict() original['record1','user1'] = 'martin' original['record1','user2'] = 'robert' original['record2','user1'] = 'robert' original.getkeys('robert') [('record1', 'user2'), ('record2', 'user1')] Whithout loop all dict. Just it! The TwoWayDict class removes the need to loop across the dict looking for keys that match a value by replacing it with another dict lookup. Reducing the nested dict to a single dict with composite keys removes the need to traverse the outer dict to compare against its children. -- http://mail.python.org/mailman/listinfo/python-list
Re: (n00b) Tkinter trouble
On Sun, Nov 13, 2011 at 1:27 PM, Jason Swails jason.swa...@gmail.comwrote: Hello, I'm trying my hand at creating a Tkinter application, but not having much luck. I'm trying to have my top level window be a series of buttons with different options on them. Every time a button is pressed, it opens up a new window with options. While that new window is open, all of the buttons on the original window are disabled. However, I want all of those buttons to become active again once I quit my new window. I can't seem to reactivate those buttons no matter what I do. This is the approach I'm trying: #!/usr/bin/env python from Tkinter import * class ActionButton(Button): def __init__(self, frame, text): self.frame = frame Button.__init__(self, master=self.frame, text=text, command=self.execute) def execute(self): window = Toplevel() new_button = ActionButton(window, '2nd level button') quit_button = Button(window, text='Quit!', command=window.destroy) window.buttons = [new_button, quit_button] for button in window.buttons: button.pack() # Deactivate buttons from containing shell for button in self.frame.buttons: button.config(state=DISABLED) window.mainloop() for button in self.frame.buttons: button.config(state=ACTIVE) top = Tk() top_button = ActionButton(top, 'Button on top!') top_button.pack() quit_button = Button(top, text='Quit', command=top.destroy) quit_button.pack() top.buttons = [top_button, quit_button] top.mainloop() I'm really kind of running around in the dark here, so any advice or explanation is appreciated. Another approach I think will work, and that I'm going to try, is to subclass Toplevel and simply assign the higher-level frame/window as an instance attribute. Then, I can reactivate all of the buttons in the destroy() method before calling the destroy() method of Toplevel on self. Something like this: [untested] class MyToplevel(Toplevel): def __init__(self, root, **options): self.root = root Toplevel.__init__(self, options) for button in self.root.buttons: button.config(state=DISABLED) def destroy(self): for button in self.root.buttons: button.config(state=ACTIVE) Toplevel.destroy(self) This allows me to avoid running mainloop() on a non-root Toplevel instance, but links the re-activation of the buttons with the destruction of the child window (which was the effect I was going for). I must not understand what mainloop() does, fully (does it only make sense to run it on Tkinter.Tk()?) Thanks! Jason -- http://mail.python.org/mailman/listinfo/python-list
[issue13394] Patch to increase aifc lib test coverage with couple of minor fixes
Oleg Plakhotnyuk oleg...@gmail.com added the comment: Thanks for your review, Ezio! Here goes new patch with all issues you've mentioned been fixed. -- Added file: http://bugs.python.org/file23678/test_aifc2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13394 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13395] Python ISO-8859-1 encoding problem
New submission from Hugo Silva hugo...@gmail.com: Hi all, I'm facing a huge encoding problem in Python when dealing with ISO-8859-1 / Latin-1 character set. When using os.listdir to get the contents of a folder I'm getting the strings encoded in ISO-8859-1 (ex: ''Ol\xe1 Mundo''), however in the Python interpreter the same string is encoded to a different charset: In : 'Olá Mundo'.decode('latin-1') Out: u'Ol\xa0 Mundo' How can I force Python to decode the string to the same format. I've seen that os.listdir is returning the strings correctly encoded but the interpreter is not ('á' character corresponds to '\xe1' in ISO-8859-1, not to '\xa0'): http://en.wikipedia.org/wiki/ISO/IEC_8859-1 This is happening Any thoughts on how to overcome ? Regards, -- components: Unicode messages: 147552 nosy: Hugo.Silva, ezio.melotti priority: normal severity: normal status: open title: Python ISO-8859-1 encoding problem versions: Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13395 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13395] Python ISO-8859-1 encoding problem
Ezio Melotti ezio.melo...@gmail.com added the comment: This doesn't seem a bug to me, so you should ask for help somewhere else. You can try to pass a unicode arg to listdir to get unicode back, and double check what the input actually is. -- resolution: - invalid stage: - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13395 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13395] Python ISO-8859-1 encoding problem
Martin v. Löwis mar...@v.loewis.de added the comment: Apparently, you are using the interactive shell on Microsoft Windows. This will use the OEM code page; which one that is depends on the exact Windows regional version you are using. You shouldn't decode the string with 'latin-1', but with sys.stdin.encoding. Alternatively, you should use Unicode string literals in Python in the first place. In any case, Ezio is right: this is not a help forum, but a bug tracker. -- nosy: +loewis ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13395 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10181] Problems with Py_buffer management in memoryobject.c (and elsewhere?)
Changes by Paul Moore p.f.mo...@gmail.com: -- nosy: +pmoore ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10181 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13390] Hunt memory allocations in addition to reference leaks
Antoine Pitrou pit...@free.fr added the comment: Thanks for the comments, here is a new patch addressing them. I've kept the C API available in all builds (since it's private), but sys.getallocatedblocks() is only available in debug builds. As for the memory leak run results, I think we may have to devise a heuristic where results like [1,0,1] (or similar variation of 0s, 1s, and -1s) are considered a success, but others like [1,1,1] are a failure. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13390 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2771] Test issue
Changes by Ezio Melotti ezio.melo...@gmail.com: -- nosy: -python-dev resolution: fixed - stage: committed/rejected - test needed status: closed - open ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2771 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2771] Test issue
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset 0e94d9bef251 by Ezio Melotti in branch 'default': Closes #2771. #13388 now needs to be updated. http://hg.python.org/test/rev/0e94d9bef251 -- nosy: +python-dev resolution: - fixed stage: test needed - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2771 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13396] new method random.getrandbytes()
New submission from Amaury Forgeot d'Arc amaur...@gmail.com: I noticed that several usages of random.getrandbits() actually need bytes. A few examples: - Lib/test/test_zlib.py calls random.getrandbits(8 * _1M).to_bytes() - Twisted uses the %x format and then call .decode('hex') Another examples found with Code Search: - struct.pack(Q, random.getrandbits(64)) - for i in range(8): ClientChallenge+= chr(random.getrandbits(8)) - key = sha1(str(random.getrandbits(8*20))).digest() random.getrandbits() itself is not a cheap call: it ends with a call to _PyLong_FromByteArray, and transformation to bytes will involve more copy, conversions from 30bit digits (or 15bit digits) to bytes, or worse. This patch adds random.getrandbytes(), which creates a bytes string directly from calls to genrand_int32(). -- files: getrandbytes.patch keywords: patch messages: 147557 nosy: amaury.forgeotdarc, rhettinger priority: normal severity: normal status: open title: new method random.getrandbytes() type: feature request versions: Python 3.2, Python 3.3 Added file: http://bugs.python.org/file23679/getrandbytes.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13396 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2771] Test issue
Changes by Ezio Melotti ezio.melo...@gmail.com: -- nosy: -python-dev resolution: fixed - stage: committed/rejected - test needed status: closed - open ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2771 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2771] Test issue
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset e4fcac92a80a by Ezio Melotti in branch 'default': Closes #2771. #13388 now needs to be updated. http://hg.python.org/test/rev/e4fcac92a80a -- nosy: +python-dev resolution: - fixed stage: test needed - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2771 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13388] document hg commit hooks in the devguide
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset e4fcac92a80a by Ezio Melotti in branch 'default': Closes #2771. #13388 now needs to be updated. http://hg.python.org/test/rev/e4fcac92a80a -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13388 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13388] document hg commit hooks in the devguide
Ezio Melotti ezio.melo...@gmail.com added the comment: ...because the hook now supports multiple issue id in the same commit message. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13388 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13396] new method random.getrandbytes()
Changes by Nadeem Vawda nadeem.va...@gmail.com: -- nosy: +nadeem.vawda ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13396 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13390] Hunt memory allocations in addition to reference leaks
Changes by Antoine Pitrou pit...@free.fr: Added file: http://bugs.python.org/file23680/debugblocks2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13390 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13390] Hunt memory allocations in addition to reference leaks
Changes by Antoine Pitrou pit...@free.fr: Added file: http://bugs.python.org/file23681/debugblocks3.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13390 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13390] Hunt memory allocations in addition to reference leaks
Antoine Pitrou pit...@free.fr added the comment: And the latest patch (debugblocks3.patch) adds said heuristic. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13390 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13396] new method random.getrandbytes()
Antoine Pitrou pit...@free.fr added the comment: Good idea, IMO. +cum = set() +for i in range(100): +val = getbytes(span) +cum |= set(i for i in range(span) if val[i]) +self.assertEqual(len(cum), span) I find this test a bit strange. Also, perhaps it should be bitwise rather than bytewise. -- nosy: +pitrou stage: - patch review versions: -Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13396 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13204] sys.flags.__new__ crashes
Antoine Pitrou pit...@free.fr added the comment: Thanks for the patch. You should add the same tests for sys.version_info and sys.getwindowsversion. -- nosy: +pitrou stage: - patch review ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13204 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13355] random.triangular error when low = high=mode
Raymond Hettinger raymond.hettin...@gmail.com added the comment: I've got this one. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13355 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13217] Missing header dependencies in Makefile
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset 36375075d6aa by Antoine Pitrou in branch 'default': Issue #13217: add missing header dependencies in the Makefile for unicodeobject.o. http://hg.python.org/cpython/rev/36375075d6aa -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13217 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13217] Missing header dependencies in Makefile
Antoine Pitrou pit...@free.fr added the comment: Thank you for the patch. I only applied it to 3.3, since 3.2 doesn't have the additional header files. -- resolution: - invalid stage: patch review - committed/rejected status: open - closed versions: -Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13217 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13396] new method random.getrandbytes()
Changes by Raymond Hettinger raymond.hettin...@gmail.com: -- assignee: - rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13396 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13396] new method random.getrandbytes()
Raymond Hettinger raymond.hettin...@gmail.com added the comment: How would this work for other random number generators that don't supply genrand_int32()? The API for random is supposed to be easily subclassable and reusable for other random number generators. The requirements for those generators is intentionally kept minimal (i.e. they only need to supply random(), seed(), getstate() and setstate() and optionally getrandbits()). I'm -0 on making this API fatter. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13396 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13388] document hg commit hooks in the devguide
Eli Bendersky eli...@gmail.com added the comment: Nice, I didn't know about issue #2771 ;-) Will update the patch! -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13388 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13396] new method random.getrandbytes()
Amaury Forgeot d'Arc amaur...@gmail.com added the comment: How would this work for other random number generators that don't supply genrand_int32()? genrand_int32 is an internal function, only available in C for the Mersenne Twister generator. random.SystemRandom() should provide getrandbytes as well, it would just call os.urandom(); I don't know other generators. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13396 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13396] new method random.getrandbytes()
Raymond Hettinger raymond.hettin...@gmail.com added the comment: genrand_int32 is an internal function, only available in C for the Mersenne Twister generator. Yes, I know. I'm the one added that code ;-) I don't know other generators. The problem is that we need an API that will accommodate other random number generators and not be specific to the MersenneTwister. Right now, the starting point for everything in the random module is an underlying generator supplying a random() method returning a float and an optional getrandombits() method which returns an int (possibly a long int). The latter is easily convertible to bytes with to_bytes() which uses a fast O(n) algorithm. ISTM, the getrandbytes() proposal amounts to a micro-optimization of existing capabilities, and it comes at the expense of fattening the API. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13396 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13396] new method random.getrandbytes()
Antoine Pitrou pit...@free.fr added the comment: The problem is that we need an API that will accommodate other random number generators and not be specific to the MersenneTwister. Right now, the starting point for everything in the random module is an underlying generator supplying a random() method returning a float and an optional getrandombits() method which returns an int (possibly a long int). Well, you can provide a default getrandombytes() which calls into getrandombits(), and specialize it in the case genrand_int32() exists. The latter is easily convertible to bytes with to_bytes() which uses a fast O(n) algorithm. Well, O(n) doesn't necessarily equate fast. Can Amaury post benchmark numbers of getrandbits().to_bytes() vs getrandbytes()? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13396 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13397] Option for XMLRPC clients to automatically transform Fault exceptions into standard exceptions
New submission from Raymond Hettinger raymond.hettin...@gmail.com: Currently, an XMLRPC client communicating with a server running Python can make Python style calls but exceptions get collapsed into a standard FaultException making it difficult to program in a Pythonic style: proxy = xmlrpc.client.ServerProxy(http://localhost:8000/;) try: value = proxy.lookup('somekey') except xmlrpc.client.Fault as err: if err.faultCode == 1 and 'KeyError' in err.faultString: k = re.search(r:.(\w+)' not found$, err.faultString).groups(1) raise KeyError(k) It would be better if we could do this automatically (search for a pure python exception of the same name and raise it instead of a Fault): proxy = xmlrpc.client.ServerProxy(http://localhost:8000/;, python_exceptions=True) try: value = proxy.lookup('somekey') except KeyError as e: ... -- messages: 147572 nosy: rhettinger priority: normal severity: normal status: open title: Option for XMLRPC clients to automatically transform Fault exceptions into standard exceptions type: feature request versions: Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13397 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13397] Option for XMLRPC clients to automatically transform Fault exceptions into standard exceptions
Changes by Raymond Hettinger raymond.hettin...@gmail.com: -- components: +Library (Lib) priority: normal - low ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13397 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13397] Option for XMLRPC clients to automatically transform Fault exceptions into standard exceptions
Changes by Antoine Pitrou pit...@free.fr: -- nosy: +flox, loewis ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13397 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13396] new method random.getrandbytes()
Amaury Forgeot d'Arc amaur...@gmail.com added the comment: ./python -m timeit -s from random import getrandbits getrandbits(800).to_bytes(100, 'little') 10 loops, best of 3: 25 msec per loop ./python -m timeit -s from random import getrandbytes getrandbytes(100) 100 loops, best of 3: 9.66 msec per loop For the Mersenne Twister, getrandbytes() is ~2.5 times faster (A length of 1000 gives exactly the same ratio) When applied to the SytemRandom object, the difference is less impressive (probably because os.urandom is slow) but getrandbytes is still 20ms faster. Updated patch to add getrandbytes at the module level, and to SystemRandom. -- Added file: http://bugs.python.org/file23682/getrandbytes.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13396 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13396] new method random.getrandbytes()
Changes by Amaury Forgeot d'Arc amaur...@gmail.com: Removed file: http://bugs.python.org/file23679/getrandbytes.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13396 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12875] backport re.compile flags default value documentation
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset 87ecfd5cd5d1 by Eli Bendersky in branch '2.7': Normalize the keyword arguments documentation notation in re.rst. Closes issue #12875 http://hg.python.org/cpython/rev/87ecfd5cd5d1 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12875 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12875] backport re.compile flags default value documentation
Changes by Eli Bendersky eli...@gmail.com: -- status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12875 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13388] document hg commit hooks in the devguide
Eli Bendersky eli...@gmail.com added the comment: An updated patch attached, explaining that several issues can be mentioned in a single commit message -- Added file: http://bugs.python.org/file23683/issue13388.2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13388 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13239] Remove operator from Grammar/Grammar
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset a259511351d9 by Eli Bendersky in branch '3.2': Clarify the existence of the operator in Grammar/Grammar with a comment, for issue 13239 http://hg.python.org/cpython/rev/a259511351d9 New changeset 410115400838 by Eli Bendersky in branch 'default': Clarify the existence of the operator in Grammar/Grammar with a comment. Closes issue 13239 http://hg.python.org/cpython/rev/410115400838 -- nosy: +python-dev resolution: - fixed stage: - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13239 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13386] Document documentation conventions for optional args
Eli Bendersky eli...@gmail.com added the comment: Ezio, regarding your latest message: The problem is when the default placeholder is some unique object() or some _internal value (we had something similar with a socket timeout once). I hope this should be rare enough not to present a significant problem with the _convention_. Such cases can be reviewed specifically and the best way to document will be discussed per case. Also for something like str.strip(), would you document chars=None or chars= \n\r\t\v\f? I think it would be better to document chars=None, because this is a simple value the user can pass (if he wants to do it explicitly), without thinking (and forgetting) about the specific delimeters. That None actually means \n\r\t\v\f should be explicitly documented below the function signature, of course. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13386 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13398] _cursesmodule missing Python.h on Solaris
New submission from Maciej Bliziński maciej.blizin...@gmail.com: Compilation of Python 3.2.2 fails on Solaris 9 as follows: /opt/SUNWspro/bin/cc -xcode=pic32 -xO3 -m32 -xarch=v8 -I/opt/csw/include -c ./Modules/_cursesmodule.c -o Modules/_cursesmodule.o ./Modules/_cursesmodule.c, line 105: cannot find include file: Python.h ./Modules/_cursesmodule.c, line 117: cannot find include file: py_curses.h ./Modules/_cursesmodule.c, line 130: warning: no explicit type given ./Modules/_cursesmodule.c, line 130: syntax error before or at: attr_t ./Modules/_cursesmodule.c, line 130: warning: old-style declaration or incorrect type for: attr_t ./Modules/_cursesmodule.c, line 139: warning: no explicit type given ./Modules/_cursesmodule.c, line 139: syntax error before or at: * (...) The problem seems to be a missing -I flag for the compiler, pointing at the Include directory in Python sources. -- components: Build messages: 147578 nosy: automatthias priority: normal severity: normal status: open title: _cursesmodule missing Python.h on Solaris type: compile error versions: Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13398 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13398] _cursesmodule does not build, doesn't find Python.h on Solaris
Changes by Maciej Bliziński maciej.blizin...@gmail.com: -- title: _cursesmodule missing Python.h on Solaris - _cursesmodule does not build, doesn't find Python.h on Solaris ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13398 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11836] multiprocessing.queues.SimpleQueue is undocumented
Eli Bendersky eli...@gmail.com added the comment: Sandro - yep, the sentinels arg is also undocumented in multiprocessing.PipeConnection.recv() and further down the road... -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11836 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13229] Improve tools for iterating over filesystem directories
Nick Coghlan ncogh...@gmail.com added the comment: And walkdir is now a published package: http://walkdir.readthedocs.org My plan for this issue now is to maintain walkdir as a standalone package for 2.7 and 3.2, but still add the functionality to shutil for 3.3+. However, I'll gather feedback on the PyPI module for a while before making any changes to the 3.3 repo. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13229 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11836] multiprocessing.queues.SimpleQueue is undocumented
Eli Bendersky eli...@gmail.com added the comment: However, sentinels *are* mentioned in the multiprocessing doc, below multiprocessing.Process: sentinel A numeric handle of a system object which will become “ready” when the process ends. On Windows, this is an OS handle usable with the WaitForSingleObject and WaitForMultipleObjects family of API calls. On Unix, this is a file descriptor usable with primitives from the select module. You can use this value if you want to wait on several events at once. Otherwise calling join() is simpler. New in version 3.3. From a cursory glance on the implementation in Lib/multiprocessing/connection.py, this is the same sentinel. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11836 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13374] Deprecate usage of the Windows ANSI API in the nt module
STINNER Victor victor.stin...@haypocalc.com added the comment: I notice that the patch changes rename() and link() to use win32_decode_filename() to coerce the filename to unicode before using the wide win32 api. Well, I did that to simplify the source code. (Previously, rename() first tried the wide api, falling back to narrow if that failed; link() used wide if the args were both unicode, narrow otherwise. Some other functions like symlink() already only use the wide api.) I can change my patch to mimick the previous behaviour: try Unicode-Unicode, or fall back to encoding both arguments to the filesystem encoding. Is this approach of coercing to unicode and only using the wide api blessed? I certainly think it should be. If so then one can get rid lots windows specific code. It was already discussed before to drop the bytes API to decode Unicode filenames in Python and only use the Unicode Windows API. There is no consensus on this topic: the statut is that the bytes API is kept but deprecated. bytes filenames will continue to use the bytes Windows API. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13374 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13396] new method random.getrandbytes()
Raymond Hettinger raymond.hettin...@gmail.com added the comment: The differential cost of generating n random bytes is negligible compared to actually doing anything with the bytes once their generated. This optimization is close to being a total waste (saving 15 milliseconds for the abnormal case of generating 1 million random bytes). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13396 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12875] backport re.compile flags default value documentation
Changes by Ezio Melotti ezio.melo...@gmail.com: -- resolution: - fixed stage: commit review - committed/rejected ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12875 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13386] Document documentation conventions for optional args
Ezio Melotti ezio.melo...@gmail.com added the comment: You should also explicitly specify what happens in several optional but not keyword args are needed. AFAIU the convention is: func(arg1, arg2[, opt1, opt2]) IIUC that would mean that either you pass only arg1 and arg2, or you also pass both opt1 and opt2. I think the correct notation for that is e.g.: str.startswith(prefix[, start[, end]]) I also saw func(foo[, bar][, baz]) for cases where either bar or baz can be passed, but since this requires keyword arguments, the func(foo, bar=x, baz=y) notation should be used instead, and the documentation should then explain that either one can be passed. I also agree with what you said in your last message. What can't be expressed with a notation can always be described with words. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13386 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13386] Document documentation conventions for optional args
Eli Bendersky eli...@gmail.com added the comment: What you say makes sense, now I just have to dig up where I saw instances of [, opt1, opt2] If anything, this is another proof that such conventions must be agreed upon and meticulously documented. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13386 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com