Re: Functions help
On 02/23/2014 08:01 PM, ru...@yahoo.com wrote: On 02/23/2014 08:21 PM, Mark Lawrence wrote: On 24/02/2014 02:55, Benjamin Kaplan wrote: On Sun, Feb 23, 2014 at 5:39 PM, alex23 wrote: On 24/02/2014 11:09 AM, Mark Lawrence wrote: On 24/02/2014 00:55, alex23 wrote: for _ in range(5): func() the obvious indentation error above Stupid cut&paste :( Your message came through fine for me (viewing as mailing list in gmail). Mark's client must be dropping spaces. I'm reading gmane.comp.python.general using Thunderbird 24.3.0 on Windows 7. The original message was properly indented on Google Groups. Perhaps you should switch to GG or some non-broken client that doesn't mangle whitespace. LOL! How long have you waited to say that? ;) -- ~Ethan -- https://mail.python.org/mailman/listinfo/python-list
Re: Functions help
On 23Feb2014 18:55, Benjamin Kaplan wrote: > On Sun, Feb 23, 2014 at 5:39 PM, alex23 wrote: > > On 24/02/2014 11:09 AM, Mark Lawrence wrote: > >> On 24/02/2014 00:55, alex23 wrote: > >>> for _ in range(5): > >>> func() > >> > >> the obvious indentation error above > > > > Stupid cut&paste :( > > Your message came through fine for me (viewing as mailing list in > gmail). Mark's client must be dropping spaces. My copy was fine too. I'm reading it via the python-list mailing list, with mutt. -- Cameron Simpson Deep into the monitor peering, long I sat there wond'ring, fearing, Doubting, while the disk kept churning, turning yet to churn some more. "Save!" I said, "You cursed mother! Save my data from before!" One thing did the phosphors answer, only this and nothing more, Just, "Abort, Retry, Ignore?" -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
On 2014-02-25 23:10, Steven D'Aprano wrote: > On Tue, 25 Feb 2014 15:03:51 -0600, Tim Chase wrote: > > > On 2014-02-25 14:40, Skip Montanaro wrote: > >> What's the correct result of evaluating this expression? > >> > >> {'A': 1} | {'A': 2} > >> > >> I can see (at least) two possible "correct" answers. > > > > I would propose at least four: > > > > {'A': 1} # choose the LHS > > {'A': 2} # choose the RHS > > {'A': (1,2)} # a resulting pair of both > > Should that value be a tuple, a list or a set? I'd say a tuple: it has order (thus not a set), and it's a fixed record of (LHS, RHS), not mutable as a list would suggest. > Option 5: raise an exception if the values are different. Inconvenient in many use cases, but certainly another possibility > Option 6: "or" the values, so that the LHS value is used only if it > is truthy, otherwise the RHS value is used. That is: > > {'A': leftdict['A'] or rightdict['A']} > > > I don't really understand the use-case behind Option 6 I can imagine a use case for it, but certainly not the *default* behavior. Yick. > > If dicts were to support set ops, the last one would be my > > preferred result. > > What, getting a set back? > > No, I disagree. If you want a set, it's easy to do: > > dicta.keys() | dictb.keys() > > (In Python 2, use viewkeys instead.) Now that I'm aware of .viewkeys()/.keys() (herein "vk/k" for brevity) thanks to Peter Otten's post, that does what I most commonly want for set-ops-on-dicts. I'd just consider this a promotion, since for k in my_dict: pass is the same as for k in my_dict.keys(): # or .iterkeys() in 2.x pass I'd find it intuitive to have set-ops behave similarly, defaulting to vk/k. > All of these operations are quite simple to write, so personally I > would recommend people just add their own helper function with the > behaviour they prefer. And with vk/k, I now fall pretty firmly in agreement with you (except for the aforementioned possibility of having a dict's currently-unused set-ops use the results of vk/k as well). -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: Functions help
On 24Feb2014 13:59, Mark Lawrence wrote: > On 24/02/2014 04:01, ru...@yahoo.com wrote: > >On 02/23/2014 08:21 PM, Mark Lawrence wrote: > >>On 24/02/2014 02:55, Benjamin Kaplan wrote: > >>>On Sun, Feb 23, 2014 at 5:39 PM, alex23 wrote: > On 24/02/2014 11:09 AM, Mark Lawrence wrote: > >On 24/02/2014 00:55, alex23 wrote: > >> for _ in range(5): > >> func() > >the obvious indentation error above > > Stupid cut&paste :( > >>> > >>>Your message came through fine for me (viewing as mailing list in > >>>gmail). Mark's client must be dropping spaces. > >> > >>I'm reading gmane.comp.python.general using Thunderbird 24.3.0 on Windows 7. > > > >The original message was properly indented on Google Groups. > >Perhaps you should switch to GG or some non-broken client that > >doesn't mangle whitespace. > > MRAB has confirmed that as always Thunderbird is working perfectly, > thank you. He confirmed it worked for him. And yet your copy rendered incorrectly. MRAB pointed at a possible cause (mixed TABs and spaces). > But you can stick with your bug ridden, badly flawed > tool as long as you like, just expect me to keep complaining until > google fixes it, or people stop using it, or people follow the > instructions that were put up on a Python web site to prevent the > bugs showing up. Methinks rurpy's GG suggestion was bait aimed specificly at you. I recognised it as sarcasm (or parody?). Relax. -- Cameron Simpson Scott Fansler wrote: > Give me a break with this thread!! So what if another rider doesn't > wave?? Who the hell cares!?!? I wave to other riders from my HD when the > thought/moment is there. If they wave back cool, if not, so what. Maybe > they didn't see me, maybe they're pissed at their boss or spouse or life > in general and are out for a putt to clear out the BS and don't care to > wave back. Big deal. Have you seen EVERY motorcyle that EVER rode past > you going the other way?? Don't think so. Stop posing & ride, wave or no > wave. > 2 cents Somebody get the pliers, this one's hooked deep. We'll need some more bait too. You might want to fiddle with drag setting on your reel too. - Tim Simpson in rec.moto -- https://mail.python.org/mailman/listinfo/python-list
Re: python
Thank you, but from by reaserch i got these requirements .. Python, django, Twisted, MySQL, PyQt, PySide, xPython. *Technical proficiency with Python and Django. *Technical proficiency in JavaScript. *Experience with MySQL / PgSQL. *Unix/Linux expertise. *Experience with MVC design patterns and solid algorithm skills. Core Python, DJango Framework, Web2Py, Google App engine, CherryPy ( Basic Introduction) The problem for me is whether i have to learn all these technologies to work as a python developer.. On Tuesday, February 25, 2014 12:58:15 AM UTC+5:30, CM wrote: > On Monday, February 24, 2014 3:31:11 AM UTC-5, Karthik Reddy wrote: > > > I worked as a weblogic administrator and now i am changing to development > > and i am very much interested in python . please suggest me what > > are the things i need to learn more rather than python to get an I.T job. > > I came to know about Django but i am in a confusion please help me > > . > > > > I recommend you look at job advertisements in areas you'd like to work (both > > areas of the world and areas within IT) and see what they seem to want. > > > > Also, consider more informative subject lines to future posts. :D -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
On Tue, 25 Feb 2014 23:07:28 +, MRAB wrote: > On 2014-02-25 21:27, Ben Finney wrote: >> Or rather, sets *only* have values. Dictionaries have keys, sets do not >> have keys. >> > But a dictionary can have duplicate values, a set cannot. It is usual to talk about the things stored in dicts and sets using slightly different terminology: - mappings such as dicts have *key/value pairs* - sets have *elements* The elements of a set are most closely related to the keys of a mapping, not the values. Set elements are unique, just like mapping keys. Specifically, the keys in a mapping make up a set; the values in a mapping do not. When talking specifically about Python dicts and sets, there is an additional restriction: both set elements and dict keys have to be hashable. English being a little sloppy at times, sometimes we also talk about the *values of a set*, but here "value" is being used as a synonym for "element" and not as a technical term for the thing which mappings associate with a key. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Help father help son / Install Version 2.6 on Mac OSX 10.9
On 24Feb2014 21:57, Ned Deily wrote: > In article > , > Chris Angelico wrote: > > On Tue, Feb 25, 2014 at 4:28 PM, wrote: > > > Trying to install Python 2.6 because PyGames says it will only install if > > > Python 2.6 is present. > > > > Are you sure you need 2.6 and not 2.7? This suggests 2.7 works: > > > > http://pygame.org/wiki/MacCompile > > And, in any case, Apple ships OS X 10.9 with copies of both Python 2.7 > and 2.6: > > /usr/bin/python2.7 > /usr/bin/python2.6 And there's always MacPorts for your multiversion needs: python24 @2.4.6_10 (lang) python25 @2.5.6_4 (lang) python26 @2.6.9 (lang) python27 @2.7.6 (lang) python31 @3.1.5 (lang) python32 @3.2.5 (lang) python33 @3.3.4 (lang) python34 @3.4.0rc1 (lang) Cheers, -- Cameron Simpson The ZZR-1100 remains the big, fast, versatile bike for the rider with a regular pillion passenger or the desire to humiliate just about every other road user who attempted to match its straight line acceleration. - REVS -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
On 2014-02-25 23:14, Ben Finney wrote: MRAB writes: On 2014-02-25 21:27, Ben Finney wrote: > Peter Otten <__pete...@web.de> writes: > >> mauro wrote: >> >> > - Dictionaries and sets are both accessed by key >> >> but sets have no values > > Or rather, sets *only* have values. Dictionaries have keys, sets do > not have keys. > But a dictionary can have duplicate values, a set cannot. Yes. Your “but” implies you think that contradicts my statement; it doesn't. So I'm not sure what point you're making. The keys of a dictionary must be unique, like a set. The values of a dictionary don't have to be unique, unlike a set. -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
On Tue, 25 Feb 2014 15:03:51 -0600, Tim Chase wrote: > On 2014-02-25 14:40, Skip Montanaro wrote: >> What's the correct result of evaluating this expression? >> >> {'A': 1} | {'A': 2} >> >> I can see (at least) two possible "correct" answers. > > I would propose at least four: > > {'A': 1} # choose the LHS > {'A': 2} # choose the RHS > {'A': (1,2)} # a resulting pair of both Should that value be a tuple, a list or a set? > set(['A']) # you did set-ops, so you get a set Option 5: raise an exception if the values are different. Option 6: "or" the values, so that the LHS value is used only if it is truthy, otherwise the RHS value is used. That is: {'A': leftdict['A'] or rightdict['A']} I don't really understand the use-case behind Option 6, but there is a recent thread on python-id...@python.org where somebody proposed that as the Obviously One True And Correct behaviour for dict intersection. > If dicts were to support set ops, the last one would be my preferred > result. What, getting a set back? No, I disagree. If you want a set, it's easy to do: dicta.keys() | dictb.keys() (In Python 2, use viewkeys instead.) gives you a set of the intersection of the keys. The only point of having dicts support set-like operations directly is if you get a dict back. All of these operations are quite simple to write, so personally I would recommend people just add their own helper function with the behaviour they prefer. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
MRAB writes: > On 2014-02-25 21:27, Ben Finney wrote: > > Peter Otten <__pete...@web.de> writes: > > > >> mauro wrote: > >> > >> > - Dictionaries and sets are both accessed by key > >> > >> but sets have no values > > > > Or rather, sets *only* have values. Dictionaries have keys, sets do > > not have keys. > > > But a dictionary can have duplicate values, a set cannot. Yes. Your “but” implies you think that contradicts my statement; it doesn't. So I'm not sure what point you're making. -- \ “Alternative explanations are always welcome in science, if | `\ they are better and explain more. Alternative explanations that | _o__) explain nothing are not welcome.” —Victor J. Stenger, 2001-11-05 | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
On 2014-02-25 21:27, Ben Finney wrote: Peter Otten <__pete...@web.de> writes: mauro wrote: > - Dictionaries and sets are both accessed by key but sets have no values Or rather, sets *only* have values. Dictionaries have keys, sets do not have keys. But a dictionary can have duplicate values, a set cannot. -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
On 25 February 2014 22:36, Tim Chase wrote: > On 2014-02-25 22:21, Duncan Booth wrote: >> > It would save some space if I didn't have to duplicate all the >> > keys into sets (on the order of 10-100k small strings), instead >> > being able to directly perform the set-ops on the dicts. But >> > otherwise, it was pretty readable & straight-forward. >> > >> It doesn't matter whether they were small strings or full-length >> novels, creating a set from a dict doesn't duplicate any strings. > > pre-my-new-learning-about .viewkeys() it sounds like set(my_dict) > would have the overhead of storing an additional reference to a > string per set-entry (rather than duplicating every string). > With .viewkeys()/.keys(), it sounds like that overhead would go away. You lose the redundant hash-table by using the keys view. The set hash table takes 20-40 bytes per entry on this computer (according to sys.getsizeof). On the same system a short string takes a similar amount of memory. The .keys() view object apparently takes 24 bytes in total so yes it's a reasonable memory saving if the dicts or of any significant size. However the .keys() objects are not necessarily as well optimised so it may be faster to convert to sets for some operations. One example I found some time ago is that for sets A & B will iterate over the smaller set but for dicts A.keys() & B.keys() would always go over the left-hand set (or right-hand - I don't remember). This makes a considerable difference if one set is significantly larger than the other. Oscar -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
On 2014-02-25 22:21, Duncan Booth wrote: > > It would save some space if I didn't have to duplicate all the > > keys into sets (on the order of 10-100k small strings), instead > > being able to directly perform the set-ops on the dicts. But > > otherwise, it was pretty readable & straight-forward. > > > It doesn't matter whether they were small strings or full-length > novels, creating a set from a dict doesn't duplicate any strings. pre-my-new-learning-about .viewkeys() it sounds like set(my_dict) would have the overhead of storing an additional reference to a string per set-entry (rather than duplicating every string). With .viewkeys()/.keys(), it sounds like that overhead would go away. -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
On 2014-02-25 22:21, Duncan Booth wrote: > > It would save some space if I didn't have to duplicate all the > > keys into sets (on the order of 10-100k small strings), instead > > being able to directly perform the set-ops on the dicts. But > > otherwise, it was pretty readable & straight-forward. > > > It doesn't matter whether they were small strings or full-length > novels, creating a set from a dict doesn't duplicate any strings. pre-my-new-learning-about .viewkeys() it sounds like set(my_dict) would have the overhead of storing an additional reference to a string per set-entry (rather than duplicating every string). With .viewkeys()/.keys(), it sounds like that overhead would go away. -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
On 25/02/2014 22:11, mauro wrote: {1, 2} & {2, 3} == {2} In my mind the intersection is evaluated on keys, so the resulting dict should be the empty one but {1:"a", 2:"b", 3:"c"} & {2:"b", 3:"e", 4:"f"} == ??? my output will be {2:"b", 3:"e"} or {2:"b", 3:"c"} depending on the implementation choice. The most obvious result is probably the empty dict {2:"b"}, i. e. a & b is defined as dict(a.items() & b.items()) Frankly, I don't do that a lot. So what's your use-case? I do not have an use case, but I've seen that many people ask for these operations for example in stackoverflow.com Please ask one of the many people on stackoverflow to raise an enhancement request here bugs.python.org complete with a patch that changes code, docs and tests and then everybody will be happy, won't they. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
Tim Chase wrote: > a_dict = dict(...) > b_dict = dict(...) > a_set = set(a_dict) > b_set = set(b_dict) > added_keys = b_set - a_set > removed_keys = a_set - b_set > same_keys = a_set & b_set > diff_keys = a_set ^ b_set > all_keys = a_set | b_set > > It would save some space if I didn't have to duplicate all the keys > into sets (on the order of 10-100k small strings), instead being able > to directly perform the set-ops on the dicts. But otherwise, it was > pretty readable & straight-forward. > It doesn't matter whether they were small strings or full-length novels, creating a set from a dict doesn't duplicate any strings. -- Duncan Booth http://kupuguy.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
> > {1, 2} & {2, 3} == {2} > In my mind the intersection is evaluated on keys, so the resulting dict should be the empty one > but > > {1:"a", 2:"b", 3:"c"} & {2:"b", 3:"e", 4:"f"} == ??? my output will be {2:"b", 3:"e"} or {2:"b", 3:"c"} depending on the implementation choice. > > The most obvious result is probably the empty dict {2:"b"}, i. e. > > a & b is defined as dict(a.items() & b.items()) > > Frankly, I don't do that a lot. So what's your use-case? I do not have an use case, but I've seen that many people ask for these operations for example in stackoverflow.com -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
On 2014-02-25 22:54, Peter Otten wrote: > Tim Chase wrote: > > If dicts were to support set ops, > > They do in 2.7 and 3.x. > > >>> a.viewkeys() - b.viewkeys() > set(['a']) > >>> a.viewkeys() & b.viewkeys() > set(['b']) > >>> a.viewkeys() ^ b.viewkeys() > set(['a', 'c']) > >>> a.viewkeys() | b.viewkeys() > set(['a', 'c', 'b']) > > For 3.x replace viewkeys() with keys(). I missed this getting added in the 2.7 release. Thanks for the introduction to .viewkeys()/.keys() as they could prove quite handy. -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
> > {'A': 1} | {'A': 2} > > I would propose at least four: > > {'A': 1} # choose the LHS > {'A': 2} # choose the RHS > {'A': (1,2)} # a resulting pair of both > set(['A']) # you did set-ops, so you get a set The implementation should define if LHS or RHS and user should change the order of operands depending on what he wants. Your example (as well as a many questions in stackoverflow.com) shows that there is some need for these operations, that implemented in C in python library will be by far more CPU and memory efficient than implemented as you did. -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
Il Tue, 25 Feb 2014 22:02:01 +, mauro ha scritto: >> {'A': 1} | {'A': 2} >> >> I would propose at least four: >> >> {'A': 1} # choose the LHS {'A': 2} # choose the RHS {'A': (1,2)} >> # a resulting pair of both set(['A']) # you did set-ops, so you get a >> set > > The implementation should define if LHS or RHS and user should change > the order of operands depending on what he wants. > > Your example (as well as a many questions in stackoverflow.com) shows > that there is some need for these operations, that implemented in C in > python library will be by far more CPU and memory efficient than > implemented as you did. posting error, this entry was supposed to be a reply to Tim Chase's comment. -- https://mail.python.org/mailman/listinfo/python-list
Re: Intalling Python 2.6 on Mac OSX 10.9
On 25/02/2014 18:28, Robert Schmidt wrote: I am trying to install Python 2.6 because Pygame will only run on 2.6. The configure gives only warnings. make frameworkinstall gcc -c -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -IInclude -I./Include -DPy_BUILD_CORE -DSVNVERSION=\"`LC_ALL=C svnversion .`\" -o Modules/getbuildinfo.o ./Modules/getbuildinfo.c clang: error: no such file or directory: 'directory"' I need a hint. Am I foolish to try and install Pygame? Is that dead? This same question was answered on another thread 16 hours ago. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
Tim Chase wrote: > On 2014-02-25 14:40, Skip Montanaro wrote: >> What's the correct result of evaluating this expression? >> >> {'A': 1} | {'A': 2} >> >> I can see (at least) two possible "correct" answers. > > I would propose at least four: > > {'A': 1} # choose the LHS > {'A': 2} # choose the RHS > {'A': (1,2)} # a resulting pair of both > set(['A']) # you did set-ops, so you get a set > > If dicts were to support set ops, They do in 2.7 and 3.x. > the last one would be my preferred > result. > > I just had to perform set operations on a pair of dicts earlier this > week, shrugged, and did things the manual/explicit way: > > a_dict = dict(...) > b_dict = dict(...) > a_set = set(a_dict) > b_set = set(b_dict) > added_keys = b_set - a_set > removed_keys = a_set - b_set > same_keys = a_set & b_set > diff_keys = a_set ^ b_set > all_keys = a_set | b_set >>> a = dict.fromkeys("ab") >>> b = dict.fromkeys("bc") >>> a.viewkeys() - b.viewkeys() set(['a']) >>> a.viewkeys() & b.viewkeys() set(['b']) >>> a.viewkeys() ^ b.viewkeys() set(['a', 'c']) >>> a.viewkeys() | b.viewkeys() set(['a', 'c', 'b']) For 3.x replace viewkeys() with keys(). > It would save some space if I didn't have to duplicate all the keys > into sets (on the order of 10-100k small strings), instead being able > to directly perform the set-ops on the dicts. But otherwise, it was > pretty readable & straight-forward. > > -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re:intersection, union, difference, symmetric difference for dictionaries
mauro Wrote in message: > Dictionaries and sets share a few properties: > - Dictionaries keys are unique as well as sets items > - Dictionaries and sets are both unordered > - Dictionaries and sets are both accessed by key > - Dictionaries and sets are both mutables > > So I wonder why operations such us intersection, union, difference, > symmetric difference that are available for sets and are not available > for dictionaries without going via key dictviews. > I certainly wouldn't be able to guess what they should be defined to do, since there are several equally obnoxious possibilities. For instance, take union for example. What should be the result when you union two dicts that have the same key but different values for that key? -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
Peter Otten <__pete...@web.de> writes: > mauro wrote: > > > - Dictionaries and sets are both accessed by key > > but sets have no values Or rather, sets *only* have values. Dictionaries have keys, sets do not have keys. -- \ “If nature has made any one thing less susceptible than all | `\others of exclusive property, it is the action of the thinking | _o__) power called an idea” —Thomas Jefferson | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
On 2014-02-25 14:40, Skip Montanaro wrote: > What's the correct result of evaluating this expression? > > {'A': 1} | {'A': 2} > > I can see (at least) two possible "correct" answers. I would propose at least four: {'A': 1} # choose the LHS {'A': 2} # choose the RHS {'A': (1,2)} # a resulting pair of both set(['A']) # you did set-ops, so you get a set If dicts were to support set ops, the last one would be my preferred result. I just had to perform set operations on a pair of dicts earlier this week, shrugged, and did things the manual/explicit way: a_dict = dict(...) b_dict = dict(...) a_set = set(a_dict) b_set = set(b_dict) added_keys = b_set - a_set removed_keys = a_set - b_set same_keys = a_set & b_set diff_keys = a_set ^ b_set all_keys = a_set | b_set It would save some space if I didn't have to duplicate all the keys into sets (on the order of 10-100k small strings), instead being able to directly perform the set-ops on the dicts. But otherwise, it was pretty readable & straight-forward. -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
Peter Otten wrote: > the empty dict {2:"b"} Make that half-empty ;) -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
mauro wrote: > Dictionaries and sets share a few properties: > - Dictionaries keys are unique as well as sets items > - Dictionaries and sets are both unordered > - Dictionaries and sets are both accessed by key but sets have no values > - Dictionaries and sets are both mutables but frozensets also have the operations mentioned in the subject. > So I wonder why operations such us intersection, union, difference, > symmetric difference that are available for sets and are not available > for dictionaries without going via key dictviews. How would you define them? E. g. {1, 2} & {2, 3} == {2} but {1:"a", 2:"b", 3:"c"} & {2:"b", 3:"e", 4:"f"} == ??? The most obvious result is probably the empty dict {2:"b"}, i. e. a & b is defined as dict(a.items() & b.items()) Frankly, I don't do that a lot. So what's your use-case? -- https://mail.python.org/mailman/listinfo/python-list
Re: An example of Python in action!
I'm sorry, but I don't know much more than this. If you follow the link there is a description of how the animation was created under the video. On 25/02/2014 18:47, Skip Montanaro wrote: On Tue, Feb 25, 2014 at 12:07 PM, Timothy W. Grove wrote: Here is an example of Python being used with Maya for animation http://vimeo.com/72276442 Maya as in MayaVi, the 3D data visualizer built atop VTK? Skip -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
On Tue, Feb 25, 2014 at 2:32 PM, mauro wrote: > So I wonder why operations such us intersection, union, difference, > symmetric difference that are available for sets and are not available > for dictionaries without going via key dictviews. What's the correct result of evaluating this expression? {'A': 1} | {'A': 2} I can see (at least) two possible "correct" answers. Skip -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
On Tue, Feb 25, 2014 at 2:32 PM, mauro wrote: > > So I wonder why operations such us intersection, union, difference, > symmetric difference that are available for sets and are not available > for dictionaries without going via key dictviews. How would the set operations apply to the dictionary values? -- https://mail.python.org/mailman/listinfo/python-list
intersection, union, difference, symmetric difference for dictionaries
Dictionaries and sets share a few properties: - Dictionaries keys are unique as well as sets items - Dictionaries and sets are both unordered - Dictionaries and sets are both accessed by key - Dictionaries and sets are both mutables So I wonder why operations such us intersection, union, difference, symmetric difference that are available for sets and are not available for dictionaries without going via key dictviews. -- https://mail.python.org/mailman/listinfo/python-list
Re: An example of Python in action!
On Tue, Feb 25, 2014 at 1:52 PM, Robert Kern wrote: > Maya as in Maya, the 3D animation software from AutoDesk. Ugh. What an unfortunate almost-name-clash... S -- https://mail.python.org/mailman/listinfo/python-list
Re: An example of Python in action!
On 2014-02-25 18:47, Skip Montanaro wrote: On Tue, Feb 25, 2014 at 12:07 PM, Timothy W. Grove wrote: Here is an example of Python being used with Maya for animation http://vimeo.com/72276442 Maya as in MayaVi, the 3D data visualizer built atop VTK? Maya as in Maya, the 3D animation software from AutoDesk. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- https://mail.python.org/mailman/listinfo/python-list
First Brazilian programming MOOC with 10.000 enrolled
Python for Zombies [1] is the first MOOC in portuguese to teach programming. Today we have 10.000 enrolled in 1013 cities from Brazil. We started five months ago. The website is a Django application. [1] http://pycursos.com/python-para-zumbis/ -- https://mail.python.org/mailman/listinfo/python-list
Re: An example of Python in action!
On Tue, Feb 25, 2014 at 12:07 PM, Timothy W. Grove wrote: > Here is an example of Python being used with Maya for animation > http://vimeo.com/72276442 Maya as in MayaVi, the 3D data visualizer built atop VTK? Skip -- https://mail.python.org/mailman/listinfo/python-list
Intalling Python 2.6 on Mac OSX 10.9
I am trying to install Python 2.6 because Pygame will only run on 2.6. The configure gives only warnings. make frameworkinstall gcc -c -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -IInclude -I./Include -DPy_BUILD_CORE -DSVNVERSION=\"`LC_ALL=C svnversion .`\" -o Modules/getbuildinfo.o ./Modules/getbuildinfo.c clang: error: no such file or directory: 'directory"' I need a hint. Am I foolish to try and install Pygame? Is that dead? -- https://mail.python.org/mailman/listinfo/python-list
An example of Python in action!
Here is an example of Python being used with Maya for animation http://vimeo.com/72276442 (No prizes for guessing what sport and team I support!!!) Best regards, Tim Grove -- https://mail.python.org/mailman/listinfo/python-list
Re: ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'S SIZE 11.5 NEW IN BOX', '$49.99')'
On 2014-02-25 17:37, nowebdevmy...@gmail.com wrote: HI, I'm also getting this kind of error. This will show when I do the edit function http://screencast.com/t/hGSbe1vt and this when performing the delete "Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1" What confused me more is that my website works fine on my live server and will only throws error when running on my wampserver. It might have the same cause, but that's just a guess because you haven't provided much information. -- https://mail.python.org/mailman/listinfo/python-list
Re: ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'S SIZE 11.5 NEW IN BOX', '$49.99')'
HI, I'm also getting this kind of error. This will show when I do the edit function http://screencast.com/t/hGSbe1vt and this when performing the delete "Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1" What confused me more is that my website works fine on my live server and will only throws error when running on my wampserver. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python : parsing the command line options using optparse
On 25/02/2014 15:31, Ganesh Pal wrote: Hi Folks , Iam newbie to Python, Iam trying to use optparse module and write a script that will parse the command line options ..I had to use opt parse instead of argparse because by host Operating system is still using python 2.6 Do you have the needed permissions to simply drop the argparse code into the 2.6 stdlib? Could you use the third party docopt instead? It's on pypi and I think it's awesome :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Python : parsing the command line options using optparse
Ganesh Pal wrote: > Iam newbie to Python, Iam trying to use optparse module and write a script > that will parse the command line options ..I had to use opt parse instead > of argparse because by host Operating system is still using python 2.6 As you are just starting I recommend that you use argparse instead of optparse. > Questions (1) > > > #python python-5.py --path=/ifs/1.txt --operation=XOR --node=11 --log > -fixcrc >>> Looks like the dest variable stores it in a dictionary , It's an instance of optparse.Values. > >> print options.path_name ( gives the option entered in the command > line) > > >/ifs/1.txt > > > I wanted to store all the options in a list like > [/ifs/1.txt,XOR,11,log_file,fix_crc] > > please suggest on the same ? While you can create such a list with [getattr(options, name) for name in ["path_name", "operation_type", ...]] I don't see what the advantage over the default format would be. In fact you are making it harder to access a specific option that way. > Question(2) > Why does this program work only with - option and not - in the above > code ? > I think its not working when the type= 'choice' or its somethimf else ? > > > # python-5.py -p=/ifs/1.txt -q=XOR -f=1234 -n=1 -l If you are asking why short options don't work in conjunction with = -- I don't know, it is probably a design choice of the optparse author. argparse accepts short options with like -f=1234 > Question (3) > If I have really long metavar and the help looks very messy ,is there > a > way to make it look elegant. > > > Example : > > parser.add_option("-q", "--operation", action="store", > metavar="XOR|ADD|SET|MODIFY|RENAME|DELETE|KILL|", dest="operation_type", > default='SET', > > type='choice', choices=['XOR', 'ADD', 'SET' > |'MODIFY'|'RENAME'|'DELETE'|'KILL'], > > help = "The corruption operation on the object [default > : > %default]",) You can move the choices into the help. Example using argparse : parser.add_argument( "-q", "--operation", metavar="OP", default='SET', choices=['XOR', 'ADD', 'SET'], help="The corruption operation on the object [choose from %(choices)s; default: %(default)s]") This becomes -q OP, --operation OP The corruption operation on the object [choose from XOR, ADD, SET; default: SET] in the help. -- https://mail.python.org/mailman/listinfo/python-list
Python : parsing the command line options using optparse
Hi Folks , Iam newbie to Python, Iam trying to use optparse module and write a script that will parse the command line options ..I had to use opt parse instead of argparse because by host Operating system is still using python 2.6 Below is the simple program ( Feel free to correct the error ) and 3 quick questions on the same. /* sample Program "/ import optparse parser = optparse.OptionParser() parser.add_option("-p", "--path", action="store", metavar="/ifs/|/ifs/", dest="path_name", type="string", help = "The file or directory path of the object in /ifs",) parser.add_option("-q", "--operation", action="store", metavar="XOR|ADD|SET", dest="operation_type", default='SET', type='choice', choices=['XOR', 'ADD', 'SET'], help = "The corruption operation on the object [default : %default]",) parser.add_option("-f", "--offset", action="store", metavar="HEX", dest="offset_value", default=0x41306141, type="long", help= "The valid offset value [default : %default]" ) parser.add_option("-n", "--node", action="store",metavar="id", dest="node_value", default= 1, type='int', help = "The node id [default : %default]") parser.add_option("-l", "--log", action="store_true",dest="log_file", help = "log the isi_corrupt execution result ") parser.add_option("-c", "--fixcrc", action="store_true",dest="fix_crc", help = "The CRC fix of the corrupted objects ") # instruct optparse to parse the program's command line: (options, args) = parser.parse_args() print options.path_name Questions (1) #python python-5.py --path=/ifs/1.txt --operation=XOR --node=11 --log -fixcrc >> Looks like the dest variable stores it in a dictionary , >> print options.path_name ( gives the option entered in the command line) /ifs/1.txt I wanted to store all the options in a list like [/ifs/1.txt,XOR,11,log_file,fix_crc] please suggest on the same ? Question(2) Why does this program work only with - option and not - in the above code ? I think its not working when the type= 'choice' or its somethimf else ? # python-5.py -p=/ifs/1.txt -q=XOR -f=1234 -n=1 -l Usage: python-5.py [options] python-5.py: error: option -q: invalid choice: '=XOR' (choose from 'XOR', 'ADD', 'SET', 'MODIFY', 'RENAME', 'DELETE', 'KILL') This Works ( --) C:\Users\bahadg\Desktop>python python-5.py --path=/ifs/1.txt --operation=XOR -- offset=1234 --node=1 --log --fixcrc /ifs/1.txt Question (3) If I have really long metavar and the help looks very messy ,is there a way to make it look elegant. Example : parser.add_option("-q", "--operation", action="store", metavar="XOR|ADD|SET|MODIFY|RENAME|DELETE|KILL|", dest="operation_type", default='SET', type='choice', choices=['XOR', 'ADD', 'SET' |'MODIFY'|'RENAME'|'DELETE'|'KILL'], help = "The corruption operation on the object [default : %default]",) #python-5.py --help Usage: python-5.py [options] Options: -h, --helpshow this help message and exit -p /ifs/|/ifs/, --path=/ifs/|/ifs/ The file or directory path of the object in /ifs -q XOR|ADD|SET|MODIFY|RENAME|DELETE|KILL|, --operation=XOR|ADD|SET|MODIFY|RENA ME|DELETE|KILL| The corruption operation on the object [default : SET] -f HEX, --offset=HEX The valid offset value [default : 1093689665] -n id, --node=id The node id [default : 1] -l, --log log the isi_corrupt execution result -c, --fixcrc The CRC fix of the corrupted objects Thanks is advance !! -- https://mail.python.org/mailman/listinfo/python-list
Re: Install python 2 and 3 in the "wrong" order
On 16/02/2014 08:13, Nagy László Zsolt wrote: And apparently, py.exe does not work the way it should be. What does this mean? Have you raised an issue on the bug tracker? I would happily reinstall 3.3 to solve the problem, but before I do that I would like to check all other related settings. So that after I reinstall 3.3, I will exactly know what was happening. It might be a good idea to change the installer of the 2.x series to detect if 3.x is already installed, and handle assignments of py and pyw files gracefully. It might be a good idea but I can't see it happening as (at least as far as I'm concerned) 2.7 is past its sell by date. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Install python 2 and 3 in the "wrong" order
On Sunday, 16 February 2014 08:13:14 UTC, Nagy László Zsolt wrote: > > Though I don't see anything in the ActiveState builds (which are all > > I've ever used) to handle the #! type selection of the desired version. > > Just got done updating my 2.7, replacing 3.2 with 3.3, and then having to > > edit my path to make 2.7 primary... No "py.exe" > I need both 2.7 and 3.3. And apparently, py.exe does not work the way it > should be. Is the following any help http://www.perlmonks.org/?node_id=998428 -- https://mail.python.org/mailman/listinfo/python-list
Re: Python powerpoint automation using pywin32
On Tuesday, 25 February 2014 03:52:29 UTC, Jaydeep Patil wrote: > I need to use COM interface for PowerPoint generation. The following will get you started http://nbviewer.ipython.org/github/sanand0/ipython-notebooks/blob/master/Office.ipynb Then you'll need to interpret the Microsoft MSDN docs for anything else http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.aspx --Simon Kennedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Coding a simple state machine in python
Peter Otten <__pete...@web.de>: > Why have the function return a name? Why not just another function? As people have said, there are many ways to skin the cat. A function can represent a state if it is the only type of event the state machine must process. A regular expression parser would be an example. In the general case, a state machine is a matrix of M states by N types of event. Then, one natural manner of representing a state is a nested class: class Lackey: def __init__(self): lackey = self class Idle: def handle_ding(self): lackey.start_timer(10) lackey.set_state(Dinged) class Dinged: def handle_dong(self): lackey.cancel_timer() lackey.open_door() lackey.ask_for_name() lackey.start_timer(20) lackey.set_state(AwaitingName) def handle_timeout(self): lackey.open_door() lackey.shoo_visitor_away() lackey.set_state(Annoyed) # other state classes here... self.set_state(Idle) def set_state(self, state): log("Lackey(): New state: {}".format( id(self), state.__class__.__name__)) self.state = state() def handle_ding(self): self.state.handle_ding() def handle_dong(self): self.state.handle_dong() def handle_timeout(self): self.state.handle_timeout() def start_timer(self): # etc etc Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: SSH/Telnet program to Router/switch
Τη Τετάρτη, 19 Φεβρουαρίου 2014 10:45:53 π.μ. UTC+2, ο χρήστης Wojciech Łysiak έγραψε: > On 19.02.2014 09:14, Sujith S wrote: > > > Hi, > > > > > > I am new to programming and python. I am looking for a python script to do > > ssh/telnet to a network equipment ? I know tcl/perl does this using > > expect/send. > > > > > > Do we have expect available in python as well or need to use some other > > method ? > > > > Hello, > > If you are looking for a way to connect to your netdevices and then > > execute some shell commands (with output) via ssh then google for > > paramiko module for python. > > > > It works on windows and linux. > > > > -- > > BR, > > Wojtek Hello, What will benefit the OP to go ahead and use paramiko opposed to just use "Putty" or another perhaps even Chrome based ssh client? Is there an advantage to that? -- https://mail.python.org/mailman/listinfo/python-list
Re: Coding a simple state machine in python
William Ray Wing wrote: > > On Feb 24, 2014, at 8:30 PM, Ronaldo wrote: > >> How do I write a state machine in python? I have identified the states >> and the conditions. Is it possible to do simple a if-then-else sort of an >> algorithm? Below is some pseudo code: >> >> if state == "ABC": >> do_something() >> change state to DEF >> >> if state == "DEF" >> perform_the_next_function() >> ... >> >> I have a class to which certain values are passed from a GUI and the >> functions above have to make use of those variables. How do I go about >> doing this? I have the following algorithm: >> >> class TestClass(): >>def __init__(self, var1, var2): #var1 and var2 are received from a GUI >> self.var1 = var1 >> ... >>if state == "ABC" >> doSomething(var1, var2) >> .. >> >> Could someone point me in the right direction? Thank you! >> >> -- >> https://mail.python.org/mailman/listinfo/python-list > > And, to extend Tim's suggestion of a dictionary just a bit, note that > since Python functions are happy to pass function names as arguments, you > can use a dictionary to make a really nice compact dispatch table. That > is, function A does its thing, gets to a new state, and returns as one of > its return arguments the key into the dictionary that points to the next > function_name to be called based on that new state. > > Stackoverflow has a couple of compact examples here: > > http://stackoverflow.com/questions/715457/how-do-you-implement-a-dispatch- table-in-your-language-of-choice Why have the function return a name? Why not just another function? -- https://mail.python.org/mailman/listinfo/python-list
Re: Coding a simple state machine in python
alex23 wrote: > On 25/02/2014 1:27 PM, Tim Daneliuk wrote: >> On 02/24/2014 08:55 PM, William Ray Wing wrote: >>> On Feb 24, 2014, at 8:30 PM, Ronaldo wrote: How do I write a state machine in python? > >> >>> Stackoverflow has a couple of compact examples here: >> >> Now you're making it TOO easy Bill ;) > > No, the _easy_ solution is: > > https://pypi.python.org/pypi?%3Aaction=search&term=state++machine&submit=search Easy? By the time I have evaluated these I've written my own ;) -- https://mail.python.org/mailman/listinfo/python-list
Re: Python powerpoint automation using pywin32
On 25/02/2014 03:52, Jaydeep Patil wrote: On Monday, 24 February 2014 17:27:23 UTC+5:30, sffj...@gmail.com wrote: On Monday, 24 February 2014 11:35:08 UTC, Jaydeep Patil wrote: I need to create a new powerpoint presentation. I need to add images, paste some graphs, add texts, tables into powerpoint. Is any link or document available which help me to do this work more effectivey & faster. Always remember, PyPi is your friend. I've not used it but the following is available which works with Microsoft's XML based document types. It is not automation per se (and doesn't use pywin32) but a library for pptx document manipulation. https://pypi.python.org/pypi/python-pptx/ Docs are here https://python-pptx.readthedocs.org/en/latest/ --Simon Hi Simon, I need to use COM interface for PowerPoint generation. So let me know any related docs? Regards Jaydeep I don't need to read double spaced stuff so please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing it, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Coding a simple state machine in python
On 25/02/2014 05:19, alex23 wrote: On 25/02/2014 1:27 PM, Tim Daneliuk wrote: On 02/24/2014 08:55 PM, William Ray Wing wrote: On Feb 24, 2014, at 8:30 PM, Ronaldo wrote: How do I write a state machine in python? >> Stackoverflow has a couple of compact examples here: Now you're making it TOO easy Bill ;) No, the _easy_ solution is: https://pypi.python.org/pypi?%3Aaction=search&term=state++machine&submit=search Or several recipes on Activestate. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.5, bytes, and %-interpolation (aka PEP 461)
On 25/02/2014 08:07, wxjmfa...@gmail.com wrote: What is wrong by design will always stay wrong by design. Why are you making the statement that PEP 461 is wrong by design? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.5, bytes, and %-interpolation (aka PEP 461)
Le mardi 25 février 2014 00:55:36 UTC+1, Steven D'Aprano a écrit : > > > > However, you don't really want to be adding large numbers of byte strings > > together, due to efficiency. Better to use % interpolation to insert them > > all at once. Hence the push to add % to bytes in Python 3. > > >>> timeit.timeit("'abc' * 1000 + '\u20ac'") 2.3244550589543564 >>> timeit.timeit("x * 1000 + y", "x = 'abc'.encode('utf-8'); y = >>> '\u20ac'.encode('utf-8')") 0.9365105183684364 >>> timeit.timeit("'\u0153' + 'abc' * 1000 + '\u20ac'") 3.0469319226397715 >>> timeit.timeit("z + x * 1000 + y", "x = 'abc'.encode('utf-8'); y = >>> '\u20ac'.encode('utf-8'); z = '\u0153'.encode('utf-8')") 1.9215464486771339 >>> Interpolation will not help. What is wrong by design will always stay wrong by design. jmf >>> -- https://mail.python.org/mailman/listinfo/python-list