Re: is_whatever_you_are_testing_for as method or property?
Mateusz Loskot wrote: On 12 December 2014 at 12:26, Chris Angelico ros...@gmail.com wrote: On Fri, Dec 12, 2014 at 10:21 PM, Mateusz Loskot mate...@loskot.net wrote: I've got several cases which are not obvious to me. For instance, class Foo has a boolean attribute, read-write, which I see a couple of realisations for possible: [...] I mentioned, setting the new value involves more changes to Foo() instance, so i's not possible to capture it with just an assignment. Hence, the discussion between property vs method. If the calculation is cheap and fast and feels like getting/setting an attribute, then use property. If the calculation is expensive, or might fail, then use explicit getter/setter methods. I'm afraid that there is no objective way to tell when something feels like an attribute. That depends partly on the class you are dealing with, and partly on personal taste. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: list comprehension return a list and sum over in loop
On 13/12/2014 03:04, KK Sasa wrote: Sorry, i should say I'm using pythonxy, maybe it imports other things. That is good to know but without any context it's rather difficult to relate it to anything. Some people may have photographic memories and so remember everything that's been said in a thread, that certainly doesn't apply to me, and right now I'm just too lazy to go back and find out what this relates to :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Extension of while syntax
Nelson Crosby wrote: I was thinking a bit about the following pattern: value = get_some_value() while value in undesired_values: value = get_some_value() I've always hated code that looks like this. Partly due to the repetition, but partly also due to the fact that without being able to immediately recognise this pattern, it isn't very readable. I agree! There are two fundamental indefinite loop structure: - loop zero or more times - loop one or more times Python has syntax to support the first, namely `while`, but doesn't have syntax to support the second. Now it is certainly true that not everything needs to be syntax. You can easily adjust a `while` loop to behave like a one-or-more loop. One way is to use a sentinel value that is guaranteed to be in the undesired set: value = something_undesired while value in undesired_values: value = get_some_value() Another way is to use an infinite loop and then break out after at least one cycle: while True: value = get_some_value() if value in undesired_values: break Both of these can be good enough. A good programmer should know these techniques because they can be generalised to loop and a half: while True: first_half() if condition: break second_half() and any other semantics you might like. (This suggestions that there is, in fact, only one *fundamental* indefinite loop: the infinite loop.) But neither is elegant and neither reads like English pseudo-code. Pascal has syntax for one-or-more loops, and inspired by that Python might have had something like this: repeat: block until condition That however would require two new keywords (repeat and until), and the benefit is not enough to make it worth breaking all the code that already uses repeat as a variable. Python already has one-line syntaxes (e.g. list comprehensions), I was wondering what people thought about a similar thing with while. It might look something like: value = get_some_value() while value in undesired_values() That is no help at all for the general case where you have a block of code inside the while loop. It certainly isn't worth having syntax for such a special case. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: list comprehension return a list and sum over in loop
KK Sasa genwei...@gmail.com writes: Hi there, The list comprehension is results = [d2(t[k]) for k in xrange(1000)], where d2 is a function returning a list, say [x1,x2,x3,x4] for one example. So results is a list consisting of 1000 lists, each of length four. Here, what I want to get is the sum of 1000 lists, and then the result is a list of length four. Is there any efficient way to do this? Because I found it is slow in my case. I tried sum(d2(t[k]) for k in xrange(1000)), but it returned error: TypeError: unsupported operand type(s) for +: 'int' and 'list'. Thanks. Why didn't you follow Mark Lawrence's advice? In your problem, results is a list of N sublists, each containing exactly four numerical values, Let's try with N=2 In [36]: results = [d2(t[k]) for k in range(2)] In [37]: print results [[1, 2, 3, 4], [5, 6, 7, 8]] Let's try the obvious method to sum In [38]: [sum(el) for el in results] Out[38]: [10, 26] not what you're looking for, but what if we had In [39]: [sum(el) for el in zip(*results)] Out[39]: [6, 8, 10, 12] correct. BTW, as you're using the scientific stack the answer of Christian Gollwitzer is the more appropriate. -- https://mail.python.org/mailman/listinfo/python-list
Re: Creating interactive command-line Python app?
um, what if I want to USE a command line for python WITHOUT downloading or installing it -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 2.x and 3.x use survey, 2014 edition
On Thu, Dec 11, 2014 at 10:32 PM, Ben Finney ben+pyt...@benfinney.id.au wrote: Giampaolo Rodola' g.rod...@gmail.com writes: I still think the only *real* obstacle remains the lack of important packages such as twisted, gevent and pika which haven't been ported yet. What disqualifies other obstacles from being “*real* obstacles”? How do you determine that? With those ones ported switching to Python 3 *right now* is not only possible and relatively easy, but also convenient. If my program relies on an obscure library ‘foo’, and that library is not ported to Python 3, switching to Python 3 is not feasible, and certainly not convenient — regardless of the status of “important packages such as twisted, gevent, and pika”. So your assertion here is plainly false. What is it you're actually wanting to say? What I'm saying is that for a very long time a considerable number of libraries haven't been ported to python 3 and that lasted for years, say until Python 3.3, or until Django started supporting Python 3, which happened less than a year ago. Names such as Twisted, gevent, eventlet, python-daemon and paramiko means that literally hundreds of thousands of users cannot even think about migrating *right now*: they're just stuck. My perception is that for way too long Python 3 was kind of ignored by some of the most important library vendors and it (partially) still is, and that's what is affecting Python 3 adoption the most. Try to take a look at how many missing dependencies a project such as OpenStack still has: http://stackoverflow.com/questions/20075574/finding-which-packages-support-python-3-x-vs-2-7-x/22113627#22113627. OpenStack is probably a bad example 'cause it's *huge*, but when the missing deps have hundreds of thousands of user (see https://python3wos.appspot.com/) it is very easy to hit one of those and remain stuck even if your project is a lot smaller. I personally tried to migrate 2 medium-sized ( 10.000 LOC) projects at work for 2 different companies and what I ended up doing was modernizing the code so that both 2.7 and 3.3+ interpreters could execute it and tests didn't raise any python-related error (SyntaxError, TypeError, UnicodeError or whatever), but I punctually hit the wall of 1, 2 or 3 missing dependencies. So basically both of these 2 projects are python 3 ready but since the library ecosystem is not I just wait (it's been a year now). -- Giampaolo - http://grodola.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Creating interactive command-line Python app?
rfreundlic...@colonial.net wrote: um, what if I want to USE a command line for python WITHOUT downloading or installing it Who are you talking to? What is the context? Like all software, you can't use Python apps without all their dependencies being installed. If you use the Linux operating system, it will have Python already installed. Otherwise, you will have to install it. If you can't install it, or don't want to, you can't use Python. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 2.x and 3.x use survey, 2014 edition
Giampaolo Rodola' g.rod...@gmail.com: What I'm saying is that for a very long time a considerable number of libraries haven't been ported to python 3 Ok, that's at least half the fault of the library developers. Names such as Twisted, gevent, eventlet, python-daemon and paramiko means that literally hundreds of thousands of users cannot even think about migrating *right now*: they're just stuck. I *have* always been very suspicious of third-party libraries and platforms. The comes-with-batteries approach has been enough for my needs. My perception is that for way too long Python 3 was kind of ignored by some of the most important library vendors and it (partially) still is, and that's what is affecting Python 3 adoption the most. Maybe. I'm not afraid of the Python 3 transition, but it's not current yet. I'm running a Python 3 application at home. At work, Python 2.3 is the version in one environment, Python 2.6 in another. When Python 3.x becomes the least common denominator, we'll build on that. Some other teams have already made the jump. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 2.x and 3.x use survey, 2014 edition
Marko Rauhamaa wrote: At work, Python 2.3 is the version in one environment Good grief! What's the OS you are using for that? -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 2.x and 3.x use survey, 2014 edition
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info: Marko Rauhamaa wrote: At work, Python 2.3 is the version in one environment Good grief! What's the OS you are using for that? RHEL 4. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition
On 2014-12-10, Bruno Cauet brunoca...@gmail.com wrote: Nathaniel, I'm not sure about that: even if the code is 2- and 3-compatible you'll pick one runtime. Why do you say that? I have both installed. I use both. Sometimes it depends on which OS/distro I'm running, sometimes other reasons prevail. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Creating interactive command-line Python app?
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: rfreundlic...@colonial.net wrote: um, what if I want to USE a command line for python WITHOUT downloading or installing it Who are you talking to? What is the context? Like all software, you can't use Python apps without all their dependencies being installed. If you use the Linux operating system, it will have Python already installed. Otherwise, you will have to install it. If you can't install it, or don't want to, you can't use Python. cx_Freeze, PyInstaller, py2exe, etc allow to create a standalone distribution i.e., you could ship your executable with a bundled Python interpreter. -- Akira -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Script to convert firewall rules
On Saturday, December 13, 2014 6:31:34 AM UTC+4, Jason Friedman wrote: Thanks for the reply. Yes I can make the all possible keywords/values for both formate. But after that what gonna be the logic to convert one format to other format. Like to convert one line below are the keywords: set interface ethernet2/5 ip 10.17.10.1/24 (format 1) set interfaces ge-0/0/0 unit 0 family inet address 10.17.10.1/24 (format 2) (set, interface, ip) = (set, interfaces, family inet address) But some values are variable and should ask the user to convert manually like ethernet2/5 equal to ge-0/0/0 or ge-0/0/1 or ge-0/0/2 And some values keep as it is like 10.17.10.1/24 Also then format 2 can be converted int o format 3 (as below) for more readability of format 2. This is just optional. interfaces { ge-2/0/5 { unit 0 { family inet { address 10.17.10.1/24; } } } } Note that the practice on this list is to put your response after the (edited) portion of the previous posts. Are you willing to learn some Python, if someone gets you started? Would it be helpful if someone provided Python code to convert this: set interfaces ge-0/0/0 unit 0 family inet address 10.17.10.1/24 to this: interfaces { ge-2/0/5 { unit 0 { family inet { address 10.17.10.1/24; } } } } ? Hello Thanks for the reply. I am learning python using CBT nuggets for python. But If you can refer me some good course, that should be practical then it would be great. For my requirement, if you can give me the best approach to start with or high level steps or give me some sample cod, I really appreciate that. Regards, Kashif -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition
On Sat, Dec 13, 2014 at 9:51 AM, Grant Edwards invalid@invalid.invalid wrote: On 2014-12-10, Bruno Cauet brunoca...@gmail.com wrote: Nathaniel, I'm not sure about that: even if the code is 2- and 3-compatible you'll pick one runtime. Why do you say that? I have both installed. I use both. Sometimes it depends on which OS/distro I'm running, sometimes other reasons prevail. Just to give another anecdote, I wrote myself a little tool last night for visualizing healthcare scenarios to help my family decide which insurance plan to choose this year. I didn't realize until I added 'subTest's to the tests and mistakenly invoked them as python -m test instead of python3 -m test that I'd accidentally written it to be 2/3 compatible! I took the subTest back out, and tests pass with both interpreters. -- Zach (If such a tool could be useful to anyone, I can post it on BitBucket/GitHub. Its support for all possibilities is far from complete, but it helped us a bit. Also, I make no guarantees that you won't want to gouge your eyes out reading the code, but that *shouldn't* happen ;) -- https://mail.python.org/mailman/listinfo/python-list
numpy question (fairly basic, I think)
Hi, I am new to numpy. I am reading binary data one record at a time (I have to) and I would like to store all the records in a numpy array which I pre-allocate. Below I try to fill the empty array with exactly one record, but it is filled with as many rows as there are columns. Why is this? It is probably something simple, but I am stuck! It is like the original record is not unpacked *as in tuple unpacking) into the array, so it remains one chunk, not an (nrows, ncols) structure. from __future__ import print_function import numpy as np # one binary record s = '\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00;@\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x80U\xe1@\x00\x00\x00\x00\x80\xd9\xe4@\x00\x00\x00\x00@\xa7\xe3@\xab\xaa\xaa\xaajG\xe3@\x00\x00\x00\x00\x80\xd9\xe4@\x00\x00\x00\x00\x00\x00;@\x00\x00\x00\x00\x00\x00;@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\xa4DI\tBx qwertyuiopasdfghjklzxcvbnm,./ \x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00p\x9f@\x00\x00\x00\x00\x00\x00\x10@\x00\x00\x00\x00\x00\x00(@DEC 2012' # read it into a structured array formats = ['d', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'a8', 'a104', 'd', 'd', 'd', 'd', 'a8'] names = [v%02d % i for i in range(len(formats))] dt = np.dtype({'formats': formats, names: names}) record = np.fromstring(s, dtype=dt) # make it more compact trunc_formats = ['f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'a1', 'a100', 'f4', 'f4', 'f4', 'f4', 'a8'] trunc_dt = np.dtype({'formats': trunc_formats, names: names}) record = record.astype(trunc_dt) print(record.shape) # (1,), but it needs to be (1, 22)?? #record = np.asarray(*tuple(record.astype(trunc_dt)), dtype=np.object) #record = np.expand_dims(record, axis=0) # initialize an empty array and fill it with one record nrows = 50 # arbitrary number ncols = len(formats) # 22 array = np.zeros((nrows, ncols), trunc_dt) array[0,:] = record print(array) # output: why is the record repeated ncols times? [[ (1.0, 27.0, 1.0, 35500.0, 42700.0, 40250.0, 39483.33203125, 42700.0, 27.0, 27.0, 0.0, 1.0, 1.0, 1.0, 13575427072.0, 'x', 'qwertyuiopasdfghjklzxcvbnm,./ ', 1.0, 2012.0, 4.0, 12.0, 'DEC 2012') (1.0, 27.0, 1.0, 35500.0, 42700.0, 40250.0, 39483.33203125, 42700.0, 27.0, 27.0, 0.0, 1.0, 1.0, 1.0, 13575427072.0, 'x', 'qwertyuiopasdfghjklzxcvbnm,./ ', 1.0, 2012.0, 4.0, 12.0, 'DEC 2012') (1.0, 27.0, 1.0, 35500.0, 42700.0, 40250.0, 39483.33203125, 42700.0, 27.0, 27.0, 0.0, 1.0, 1.0, 1.0, 13575427072.0, 'x', 'qwertyuiopasdfghjklzxcvbnm,./ ', 1.0, 2012.0, 4.0, 12.0, 'DEC 2012') ..., (1.0, 27.0, 1.0, 35500.0, 42700.0, 40250.0, 39483.33203125, 42700.0, 27.0, 27.0, 0.0, 1.0, 1.0, 1.0, 13575427072.0, 'x', 'qwertyuiopasdfghjklzxcvbnm,./ ', 1.0, 2012.0, 4.0, 12.0, 'DEC 2012') (1.0, 27.0, 1.0, 35500.0, 42700.0, 40250.0, 39483.33203125, 42700.0, 27.0, 27.0, 0.0, 1.0, 1.0, 1.0, 13575427072.0, 'x', 'qwertyuiopasdfghjklzxcvbnm,./ ', 1.0, 2012.0, 4.0, 12.0, 'DEC 2012') (1.0, 27.0, 1.0, 35500.0, 42700.0, 40250.0, 39483.33203125, 42700.0, 27.0, 27.0, 0.0, 1.0, 1.0, 1.0, 13575427072.0, 'x', 'qwertyuiopasdfghjklzxcvbnm,./ ', 1.0, 2012.0, 4.0, 12.0, 'DEC 2012')] [ (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, '', '', 0.0, 0.0, 0.0, 0.0, '') (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, '', '', 0.0, 0.0, 0.0, 0.0, '') (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, '', '', 0.0, 0.0, 0.0, 0.0, '') ..., (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, '', '', 0.0, 0.0, 0.0, 0.0, '') (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, '', '', 0.0, 0.0, 0.0, 0.0, '') (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, '', '', 0.0, 0.0, 0.0, 0.0, '')] etc etc Thank you in advance! Regards, Albert-Jan ~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~ -- https://mail.python.org/mailman/listinfo/python-list
Re: Creating interactive command-line Python app?
Akira Li wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: rfreundlic...@colonial.net wrote: um, what if I want to USE a command line for python WITHOUT downloading or installing it Who are you talking to? What is the context? Like all software, you can't use Python apps without all their dependencies being installed. If you use the Linux operating system, it will have Python already installed. Otherwise, you will have to install it. If you can't install it, or don't want to, you can't use Python. cx_Freeze, PyInstaller, py2exe, etc allow to create a standalone distribution i.e., you could ship your executable with a bundled Python interpreter. You still have to download and install the application. Sounds to me like the OP wants to use the Python interactive interpreter without installing Python. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: numpy question (fairly basic, I think)
Albert-Jan Roskam wrote: Hi, I am new to numpy. I am reading binary data one record at a time (I have to) and I would like to store all the records in a numpy array which I pre-allocate. Below I try to fill the empty array with exactly one record, but it is filled with as many rows as there are columns. Why is this? It is probably something simple, but I am stuck! It is like the original record is not unpacked *as in tuple unpacking) into the array, so it remains one chunk, not an (nrows, ncols) structure. Can you simplify the example to something shorter that focuses on the issue at hand? It isn't clear to me which bits of the code you show are behaving the way you expect and which bits are not. To get you started, here is what I got working: import numpy as np # one binary record s = '\x00\x01\x00\xff'*2 # eight bytes makes one C double # read it into a structured array formats = ['d'] names = [v%02d % i for i in range(len(formats))] dt = np.dtype({'formats': formats, names: names}) record = np.fromstring(s, dtype=dt) which gives this for record: array([(-5.4874686660912e+303,)], dtype=[('v00', 'f8')]) Is that what you expected? If not, what did you expect? Now modify the example the *least amount possible* to demonstrate the issue. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition
On 13 Dec 2014 05:19, Petr Viktorin encu...@gmail.com wrote: Also keep in mind that not all Python libraries are on PyPI. For non-Python projects with Python bindings (think video players, OpenCV, systemd, Samba), distribution via PyPI doesn't make much sense. And since the Python bindings are usually second-class citizens, the porting doesn't have a high priority. If anyone is wondering why their favorite Linux distribution is stuck with Python 2 – well, I can only speak for Fedora, but nowadays most of what's left are CPython bindings. No pylint --py3k or 2to3 will help there... That's a good point. I actually think https://docs.python.org/3/howto/cporting.html#cporting-howto is actually in a worse state than the state the Python level porting guide was in until Brett's latest round of updates, as it covers the underlying technical details of the incompatibilities moreso than the available tools and recommended processes for *executing* a migration. For example, replacing a handcrafted Python extension with a normal C library plus cffi, Cython or SWIG generated Python bindings can deliver both an easier to maintain extension *and* Python 3 compatibility. Similarly, converting an extension from C to Cython outright (without a separate C library) can provide both benefits. It's mainly when converting to one of those isn't desirable and/or feasible that you really need to worry about C API level porting. For that, tools like Dave Malcolm's static CPython extension analyser for gcc could potentially be helpful (as pylint was to Brett's update to the Python level guide), and Lennart also provides some more detailed practical suggestions in http://python3porting.com/cextensions.html I'm sure there are other useful techniques that can be employed, but aren't necessarily well known outside the folks that have been busy implementing these migrations. Barry, Petr, any of the other folks working on distro level C extension ports, perhaps one of you would be willing to consider an update to the C extension porting guide to be more in line with Brett's latest version of the Python level porting guide? Regards, Nick. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Script to convert firewall rules
Thanks for the reply. I am learning python using CBT nuggets for python. But If you can refer me some good course, that should be practical then it would be great. For my requirement, if you can give me the best approach to start with or high level steps or give me some sample cod, I really appreciate that. Good, some other sources for learning: https://docs.python.org/3/tutorial/ http://learnpythonthehardway.org/ Here's some code to get you started (version 3.4.0): convert set interfaces ge-0/0/0 unit 0 family inet address 10.17.10.1/24 to interfaces { ge-2/0/5 { unit 0 { family inet { address 10.17.10.1/24; } } } } class interface(): attribute_name_list = (ge, unit, family, address) def __init__(self, ge, unit, family, address): self.ge = ge self.unit = unit self.family = family self.address = address def convert(interface_list, indent=4): indentation = 0 return_list = list() return_list.append( * indentation + interfaces {) for interface in interface_list: for attribute_name in interface.attribute_name_list: indentation += indent text = %s %s { % (attribute_name, getattr(interface, attribute_name)) return_list.append( * indentation + text) while indentation indent: indentation -= indent return_list.append( * indentation + }) indentation -= indent return_list.append(}) return \n.join(return_list) if __name__ == __main__: interface1 = interface(0/0/0, 0, inet, 10.17.10.1/24) interface2 = interface(2/0/5, 0, inet, 11.18.10.1/24) print(convert((interface1, interface2, ))) -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Script to convert firewall rules
Hi Jason Thank you very much. Appreciated ! But the first requirement was to convert format1 to format2 as below: set interface ethernet2/5 ip 10.17.10.1/24 (format 1) set interfaces ge-0/0/0 unit 0 family inet address 10.17.10.1/24 (format 2) (set, interface, ip) = (set, interfaces, family inet address) But some values are variable and should ask the user to convert manually like ethernet2/5 equal to ge-0/0/0 or ge-0/0/1 or ge-0/0/2 And some values keep as it is like 10.17.10.1/24 Thanks and Regards, Kashif On Sun, Dec 14, 2014 at 5:35 AM, Jason Friedman jsf80...@gmail.com wrote: Thanks for the reply. I am learning python using CBT nuggets for python. But If you can refer me some good course, that should be practical then it would be great. For my requirement, if you can give me the best approach to start with or high level steps or give me some sample cod, I really appreciate that. Good, some other sources for learning: https://docs.python.org/3/tutorial/ http://learnpythonthehardway.org/ Here's some code to get you started (version 3.4.0): convert set interfaces ge-0/0/0 unit 0 family inet address 10.17.10.1/24 to interfaces { ge-2/0/5 { unit 0 { family inet { address 10.17.10.1/24; } } } } class interface(): attribute_name_list = (ge, unit, family, address) def __init__(self, ge, unit, family, address): self.ge = ge self.unit = unit self.family = family self.address = address def convert(interface_list, indent=4): indentation = 0 return_list = list() return_list.append( * indentation + interfaces {) for interface in interface_list: for attribute_name in interface.attribute_name_list: indentation += indent text = %s %s { % (attribute_name, getattr(interface, attribute_name)) return_list.append( * indentation + text) while indentation indent: indentation -= indent return_list.append( * indentation + }) indentation -= indent return_list.append(}) return \n.join(return_list) if __name__ == __main__: interface1 = interface(0/0/0, 0, inet, 10.17.10.1/24) interface2 = interface(2/0/5, 0, inet, 11.18.10.1/24) print(convert((interface1, interface2, ))) -- https://mail.python.org/mailman/listinfo/python-list
[issue17128] OS X system openssl deprecated - installer should build local libssl
Roundup Robot added the comment: New changeset 288b03b5c60d by Ned Deily in branch '3.4': Issue #17128: Use private version of OpenSSL for 3.x OS X 10.5+ installers. https://hg.python.org/cpython/rev/288b03b5c60d New changeset 1c249d0cab5d by Ned Deily in branch 'default': Issue #17128: Merge / update from 3.4 https://hg.python.org/cpython/rev/1c249d0cab5d New changeset 961f988eaa6a by Ned Deily in branch '2.7': Use rtf format files for legacy OS X installer builds. https://hg.python.org/cpython/rev/961f988eaa6a -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17128 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23047] typo in pyporting.rst
New submission from Xavier de Gaye: In Doc/howto/pyporting.rst at line from __future__ import print_statement: s/print_statement/print_function/ -- assignee: docs@python components: Documentation messages: 232600 nosy: brett.cannon, docs@python, xdegaye priority: normal severity: normal status: open title: typo in pyporting.rst type: behavior versions: Python 3.5 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23047 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17636] Modify IMPORT_FROM to fallback on sys.modules
Roundup Robot added the comment: New changeset 3a35638bce66 by Ned Deily in branch 'default': Issue #17636: Install new test directories. https://hg.python.org/cpython/rev/3a35638bce66 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17636 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23031] pdb crashes when jumping over with statement
Xavier de Gaye added the comment: This has been fixed by issue 14612 for version 2.7.4. -- nosy: +xdegaye ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23031 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23031] pdb crashes when jumping over with statement
Changes by Dan potapovdan...@mail.ru: -- resolution: - out of date status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23031 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23030] lru_cache manual get/put
Constantin added the comment: It may be the case, that an lru_cache does not provide the best strategy for reliably caching many base cases in recursively written code. I suggest that someday we think about a different caching paradigm which fits this purpose and add it to functools e.g. as functools.recopt_cache. This cache would then implement the same interface as lru_cache and therefore all code currently using lru_cache could benefit from recopt_cache with just one line of code change. Furthermore, by designing this interface, it becomes more probable that user defined caching decorators are compatible. Please remember: My suggestion isn't just about lru_cache, but about an interface for caching decorators. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23030 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23048] abort when jumping out of a loop
New submission from Xavier de Gaye: With the following jump.py script: def foo(): import pdb; pdb.set_trace() while 1: pass return # this is line 5 foo() The following debugging session aborts on Python 3.5.0a0 (default:334c01aa7f93, Dec 3 2014, 16:20:19): $ python jump.py /tmp/test/jump.py(3)foo() - while 1: (Pdb) next /tmp/test/jump.py(4)foo() - pass (Pdb) jump 5 python: Objects/frameobject.c:258: frame_setlineno: Assertion `blockstack_top == 0' failed. Aborted (core dumped) -- components: Interpreter Core messages: 232604 nosy: xdegaye priority: normal severity: normal status: open title: abort when jumping out of a loop type: crash versions: Python 3.5 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23048 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23047] typo in pyporting.rst
Chaitanya agrawal added the comment: Typo corrected according to message232600. -- keywords: +patch nosy: +krypten Added file: http://bugs.python.org/file37438/issue23047.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23047 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23040] Better documentation for the urlencode safe parameter
Wojtek Ruszczewski added the comment: Updated the patch, additionally changing be to contain in the first sentence. -- Added file: http://bugs.python.org/file37439/urlencode-safe-v2.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23040 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23041] csv needs more quoting rules
Skip Montanaro added the comment: It doesn't look like a difficult change, but is it really needed? I guess my reaction is the same as Raymond's. Are there real-world uses where the current set of quoting styles isn't sufficient? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23041 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23047] typo in pyporting.rst
Roundup Robot added the comment: New changeset 914e9092984e by Berker Peksag in branch '3.4': Issue #23047: Fix typo in pyporting.rst. https://hg.python.org/cpython/rev/914e9092984e New changeset 81a56c9e1e1c by Berker Peksag in branch 'default': Issue #23047: Fix typo in pyporting.rst. https://hg.python.org/cpython/rev/81a56c9e1e1c -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23047 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23047] typo in pyporting.rst
Roundup Robot added the comment: New changeset f1f404f5422a by Berker Peksag in branch '2.7': Issue #23047: Fix typo in pyporting.rst. https://hg.python.org/cpython/rev/f1f404f5422a -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23047 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23047] typo in pyporting.rst
Berker Peksag added the comment: Thanks for the report, Xavier and thanks for the patch, Chaitanya. -- nosy: +berker.peksag resolution: - fixed stage: - resolved status: open - closed versions: +Python 2.7, Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23047 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23004] mock_open() should allow reading binary data
Aaron Hill added the comment: I've created a new patch, which addresses the problem. Your example now currently returns [b'foo\n', b'bar\n'] -- Added file: http://bugs.python.org/file37440/mock-open-allow-binary-data-updated.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23004 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19698] Implement _imp.exec_builtin and exec_dynamic
Nick Coghlan added the comment: Yes, if we don't get to it beforehand. I'd still like to take the draft Create/Exec C level hook design I came up with and turn it into a PEP, but I don't know when I'll get time. Maybe I should just put that together as a (very) rough draft and lob it at import-sig? Then we'll have a concrete base for discussion at PyCon, and someone may be able to put together a draft implementation while you, me Eric are all in the same place at the same time. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19698 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23017] string.printable.isprintable() returns False
Akira Li added the comment: C standard defines locale-specific *printing characters* that are [ -~] in C locale for implementations that use 7-bit US ASCII character set i.e., SP (space, 0x20) is a printing character in C (isprint() returns nonzero). There is isgraph() function that returns zero for the space but otherwise is equivalent to isprint(). POSIX definition is aligned with the ISO C standard. I don't know what RFC 5822 has to do with this issue but the rfc contradicts itself e.g., in one place it has: printable US-ASCII characters except SP that imlies that SP *is* printable but in other places it considers isprint==isgraph. The authors probably meant characters for which isgraph() is nonzero when they use printable US-ASCII (that is incorrect according to C standard). Tests from issue9770 show the relation between C character classes and string constants [1]: set(string.printable) == set(C['graph']) + set(C['space']) where C['space'] is '\t\n\v\f\r ' (the standard C whitespace). It is a documented behavior [2]: This is a combination of digits, ascii_letters, punctuation, and whitespace where *whitespace* is C['space']. In Python 2, *printable* is locale-dependent and it coincides with the corresponding Python 3 definition in C locale with ASCII charset. Unlike other string constants, *printable* differs from C['print'] on both Python 2 and 3 because it includes whitespace characters other than space. str.isprintable [3] obeys C['print'] (in ASCII range) and considers SP to be printable. --- It might be too late to change string.printable to correspond to C isprint() (for ASCII characters). I've uploaded a documentation patch that mentions that string.printable and str.isprintable differ. [1] http://bugs.python.org/review/9770/diff/12212/Lib/test/test_curses_ascii.py [2] https://hg.python.org/cpython/file/3.4/Doc/library/string.rst#l62 [3] https://docs.python.org/3.4/library/stdtypes.html#str.isprintable -- nosy: +akira Added file: http://bugs.python.org/file37441/docs-string.printable.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23017 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23048] abort when jumping out of a loop
Raymond Hettinger added the comment: Building on OS X 10.10 with the head of the code tree (as of today), I cannot reproduce this. Also the disassembly looks fine: $ python3.5 jump.py /Users/raymond/tmp/jump.py(3)foo() - while 1: (Pdb) next /Users/raymond/tmp/jump.py(4)foo() - pass (Pdb) jump 5 /Users/raymond/tmp/jump.py(5)foo() - return # this is line 5 (Pdb) list 1 def foo(): 2 import pdb; pdb.set_trace() 3 while 1: 4 pass 5 - return # this is line 5 6 7 foo() 8 [EOF] (Pdb) !from dis import dis (Pdb) !dis(foo) 2 0 LOAD_CONST 1 (0) 3 LOAD_CONST 0 (None) 6 IMPORT_NAME 0 (pdb) 9 STORE_FAST 0 (pdb) 12 LOAD_FAST0 (pdb) 15 LOAD_ATTR1 (set_trace) 18 CALL_FUNCTION0 (0 positional, 0 keyword pair) 21 POP_TOP 3 22 SETUP_LOOP 3 (to 28) 425 JUMP_ABSOLUTE 25 528 LOAD_CONST 0 (None) 31 RETURN_VALUE (Pdb) !import sys (Pdb) p sys.version_info sys.version_info(major=3, minor=5, micro=0, releaselevel='alpha', serial=0) -- nosy: +rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23048 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19527] Test failures with COUNT_ALLOCS
Serhiy Storchaka added the comment: Thenks Antoine for great idea proposed in comments on Rietveld. Following patch introduces strip_python_stdout() which strips COUNT_ALLOCS debug output from stdout (unfortunately this operation is not always unambiguous) and call it in assert_python_ok() and assert_python_failure(). This automatically fixes a large number of tests. Also fixed a number of other tests failing with COUNT_ALLOCS. Virtually all tests are now fixed except test_doctest and test_distutils. A large part of the patch will be applied only to 3.4 and 2.7. With resolved issue23034 the patch for 3.5 will be much simpler, strip_python_stdout() and @requires_clean_stdout will gone away. -- dependencies: +Dynamically control debugging output Added file: http://bugs.python.org/file37442/00141-fix-tests_with_COUNT_ALLOCS-v5.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19527 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22955] Pickling of methodcaller, attrgetter, and itemgetter
Serhiy Storchaka added the comment: functools.partial is a somewhat less than ideal comparison. The pure-Python version is not picklable, the Python and C versions return different things (the Python version is a function returning a function, the C version is a regular class and returns an instance). Looks as Python version of functools.partial() needs a fix. Reimplementations of the pure-Python itemgetter and attrgetter to automatically pickleable Python classes have a disadvantage. It makes the pickling incompatible between Python and C versions. This means that itemgetter pickled in CPython will be not unpickleable on Python implementation which don't use C accelerator and vice versa. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22955 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22955] Pickling of methodcaller, attrgetter, and itemgetter
Zachary Ware added the comment: Serhiy Storchaka added the comment: Reimplementations of the pure-Python itemgetter and attrgetter to automatically pickleable Python classes have a disadvantage. It makes the pickling incompatible between Python and C versions. This means that itemgetter pickled in CPython will be not unpickleable on Python implementation which don't use C accelerator and vice versa. That's a very good point that I hadn't thought about. Consider my patch withdrawn. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22955 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9393] shelve.open/bsddb.hashopen exception with unicode paths
Changes by Serhiy Storchaka storch...@gmail.com: -- stage: test needed - needs patch versions: +Python 3.4, Python 3.5 -Python 3.1, Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9393 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22823] Use set literals instead of creating a set from a list
Changes by Serhiy Storchaka storch...@gmail.com: -- assignee: benjamin.peterson - serhiy.storchaka ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22823 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22823] Use set literals instead of creating a set from a list
Roundup Robot added the comment: New changeset c3f960cff3e6 by Serhiy Storchaka in branch '3.4': Issue #22823: Use set literals in lib2to3. https://hg.python.org/cpython/rev/c3f960cff3e6 New changeset d3e43f7ecca8 by Serhiy Storchaka in branch 'default': Issue #22823: Use set literals in lib2to3. https://hg.python.org/cpython/rev/d3e43f7ecca8 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22823 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22823] Use set literals instead of creating a set from a list
Serhiy Storchaka added the comment: That's all I think. Distutils is too conservative for such changes. -- resolution: - fixed stage: patch review - resolved status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22823 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22875] asyncio: call_soon() documentation unclear on timing
Guido van Rossum added the comment: Docfix LGTM. On Fri, Dec 12, 2014 at 10:53 PM, Martin Panter rep...@bugs.python.org wrote: Martin Panter added the comment: I have been bitten by this when attempting to implement my own event loops. Parts of the “asyncio” code itself expects that the callback is not invoked directly after call_soon() returns. Here is a simple patch. -- keywords: +patch nosy: +vadmium versions: +Python 3.4 Added file: http://bugs.python.org/file37437/call_soon.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22875 ___ -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22875 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19949] Explicitly skip or mask skipped/disabled tests in test_xpickle
Serhiy Storchaka added the comment: In updated patch the xpickle resource is tested before attempts to run Python executables. Also these checks are moved from decorator to the setUp() method. The result of have_python_version() now is memoized. Fixed running the test in unicode-disabled build. And added tests for installed Python 2.7. As far as older Python versions are rarely installed nowadays, this allows to check that the test is work at all (and that there is no significant regression against previous bugfix). -- Added file: http://bugs.python.org/file37443/test_xpickle_cleanup_2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19949 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23048] abort when jumping out of a loop
Changes by Benjamin Peterson benja...@python.org: -- assignee: - benjamin.peterson nosy: +benjamin.peterson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23048 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23048] abort when jumping out of a loop
Roundup Robot added the comment: New changeset 09f938915c6f by Benjamin Peterson in branch '3.4': pop the loop block even for infinite while loops (closes #23048) https://hg.python.org/cpython/rev/09f938915c6f New changeset baa5258bef22 by Benjamin Peterson in branch '2.7': pop the loop block even for infinite while loops (closes #23048) https://hg.python.org/cpython/rev/baa5258bef22 New changeset ec96ffa6aa95 by Benjamin Peterson in branch 'default': merge 3.4 (#23048) https://hg.python.org/cpython/rev/ec96ffa6aa95 -- nosy: +python-dev resolution: - fixed stage: - resolved status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23048 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19698] Implement _imp.exec_builtin and exec_dynamic
Brett Cannon added the comment: sgtm -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19698 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21279] str.translate documentation incomplete
Terry J. Reedy added the comment: Many people may not know that IndexError and KeyError are subclasses of LookupError. I have not decided what to add yet, but I think we are close. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21279 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23011] Duplicate Paragraph in documentation for json module
Terry J. Reedy added the comment: Will reconsider if an actual duplication is presented. -- resolution: - not a bug stage: - resolved status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23011 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23049] Fix functools.reduce code equivalent.
New submission from Terry J. Reedy: from functools import reduce def add(a,b): return a+b reduce(add, {}) Traceback (most recent call last): File C:\Programs\Python34\tem.py, line 3, in module reduce(add, {}) TypeError: reduce() of empty sequence with no initial value However, the reduce-equivalent code in the doc sets a bad example and forgets to account for empty iterators. def reduce(function, iterable, initializer=None): it = iter(iterable) if initializer is None: value = next(it) else: ... So it lets the StopIteration escape (a bad practice that can silently break iterators). The code should be def reduce(function, iterable, initializer=None): it = iter(iterable) if initializer is None: try: value = next(it) except StopIteration: raise TypeError(reduce() of empty sequence with no initial value) from None else: ... (patch coming) -- assignee: docs@python components: Documentation, Interpreter Core messages: 232626 nosy: docs@python, terry.reedy priority: normal severity: normal stage: needs patch status: open title: Fix functools.reduce code equivalent. type: behavior versions: Python 3.4, Python 3.5 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23049 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23030] lru_cache manual get/put
Raymond Hettinger added the comment: Sorry Constantin, I am rejecting this proposal or any variants of it. * As Nick pointed-out in the referenced thread, we provide two tools: a functools caching decorator that is tightly focused on the task of caching function calls and a collections OrderedDict that is a general purpose data store suitable for implementing custom LRU logic when needed. * As John pointed-out, this proposal isn't even fit for the original use case. Any speed benefits of a tail recursion optimization get immediately wiped out by overhead of a LRU cache decorator, and the clarity of the original code starts to get lost in the extra code to call cache_get() and cache_put() -- remember the decorator was designed to wrap around a function without having to change the logic inside it. Also, the optimization itself is fundamentally suspect because it changes the semantics of the language (thereby defeating all decorators that supply wrapper functions including memoization decorators, call loggers, precondition/postcondition checkers, subscription notifiers, type checkers, etc). * The essence of this proposal is at odds with what the functools caching decorator is all about -- providing a cache for function calls. The proposal bypasses the function call itself, making it more difficult to reason about what is in the cache (i.e. the result of previous function calls) and mucking up the cache hit/miss statistics which stop being meaningful. * The proposal also adds API complexity (making it less like a function decorator and more like an exposed data store such as an ordered dictionary). And, it creates a new control flow exception NotInCache. Collectively, these changes make the decorator slower, harder to maintain, harder to learn, harder to avoid reentrancy and locking problems, and harder to reason about but it doesn't provide much if any incremental benefit over using an OrderedDict directly. * To the extent there are valid niche use cases, we shouldn't try to cater to all of them. Good standard library API design stay focused on serving on the common case as well as possible and leaving the rest to OrderedDict or a third-party package (you're welcome to publish one to see if it actually serves a real need). * In designing the cache, I surveyed previously published memoization decorators and did not find the proposed feature. That means that it is false to state that every memoization decorator *must have* some functionality to insert or lookup entries while bypassing the function call that was intended to be cached. If it really was must have behavior, then it would have already been commonplace. IMO, cache_put() is bad design (would you want you database cache to return something that was never in the database or your disk cache to return values that had never been written to disk?) * Hopefully, this message explains my reasoning clearly, so you will understand why I'm closing this one. That said, judging by the insistent wording of your posts, I don't expect that you will be convinced. Your mental model of caching tools is very different from what the functools.lru_cache was intended to accomplish. To the extent that you don't really want a transparent function decorator and would prefer a full featured class (with methods for getting, setting, deleting, re-ordering, listing, monitoring, etc), I recommend that you write one and post it to the Python Package Index. The collections.OrderedDict() class should easily handle the LRU storage logic, so all you have to do is specify your API and decide which parts of the store you want to expose. -- resolution: - rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23030 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23049] Fix functools.reduce code equivalent.
Changes by Raymond Hettinger raymond.hettin...@gmail.com: -- assignee: docs@python - rhettinger nosy: +rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23049 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22735] Fix various crashes exposed through mro() customization
Benjamin Peterson added the comment: I will try to look eventually. -- assignee: - benjamin.peterson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22735 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23004] mock_open() should allow reading binary data
Demian Brecht added the comment: Thanks for the update, but this doesn't quite work either as you're assuming utf-8 (which is what .encode() and .decode() default to). For example, when using latin-1: m = mock_open(read_data= b'\xc6') with patch('__main__.open', m, create=True) : ... with open('abc', 'rb') as f : ... print(f.read()) ... Traceback (most recent call last): [snip] UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc6 in position 0: unexpected end of data Additionally, a bytes object may simply be binary data that doesn't adhere to any specific encoding. My suggestion is to remove the use of format() altogether as it's really not doing anything complex and simply append either '\n' or b'\n' depending on the type of object passed in. That way, you can deal with the type of object passed in directly without coercion. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23004 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23041] csv needs more quoting rules
Chaitanya agrawal added the comment: Used function PyUnicode_Check instead of PyString_Check -- keywords: +patch nosy: +krypten Added file: http://bugs.python.org/file37444/issue23041.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23041 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23041] csv needs more quoting rules
Changes by Chaitanya agrawal chaitiagra...@gmail.com: Added file: http://bugs.python.org/file37445/issue23041_test.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23041 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com