Re: "Exception ... in ignored" Messages
Ami Tavory wrote: > Hi, > > Running the unit tests for some generator code, prints, as a side > effect, > numerous messages of the form: > > ... > Exception NameError: "global name 'l' is not defined" in _dagpype_internal_fn_act at 0x9d4c500> ignored > Exception AttributeError: "'NoneType' object has no attribute 'close'" in > ignored > Exception AttributeError: "'NoneType' object has no attribute 'close'" in > ignored > ... > > The tests otherwise run fine. > > Is there any way to catch the point where such a message originates, and > print a traceback? I find it difficult to debug otherwise. I've tried > running Python with -W error, catching warnings with context managers, and > so forth, but without any success. >>> def g(): ... try: ... yield 42 ... finally: ... 1/0 ... >>> for item in g(): ... break ... Exception ZeroDivisionError: 'integer division or modulo by zero' in ignored Can you exhaust the generator? >>> for item in g(): ... pass ... Traceback (most recent call last): File "", line 1, in File "", line 5, in g ZeroDivisionError: integer division or modulo by zero Explicitly closing the generator seems to work, too: >>> x = g() >>> next(x) 42 >>> x.close() Traceback (most recent call last): File "", line 1, in File "", line 5, in g ZeroDivisionError: integer division or modulo by zero -- http://mail.python.org/mailman/listinfo/python-list
Re: string.replace doesn't removes ":"
On 13 fév, 21:24, 8 Dihedral wrote: > Rick Johnson於 2013年2月14日星期四UTC+8上午12時34分11秒寫道: > > > > > > > > > On Wednesday, February 13, 2013 1:10:14 AM UTC-6, jmfauth wrote: > > > > >>> d = {ord('a'): 'A', ord('b'): '2', ord('c'): 'C'} > > > > >>> 'abcdefgabc'.translate(d) > > > > 'A2CdefgA2C' > > > > >>> def jmTranslate(s, table): > > > > ... table = {ord(k):table[k] for k in table} > > > > ... return s.translate(table) > > > > ... > > > > >>> d = {'a': 'A', 'b': '2', 'c': 'C'} > > > > >>> jmTranslate('abcdefgabc', d) > > > > 'A2CdefgA2C' > > > > >>> d = {'a': None, 'b': None, 'c': None} > > > > >>> jmTranslate('abcdefgabc', d) > > > > 'defg' > > > > >>> d = {'a': '€', 'b': '', 'c': ''} > > > > >>> jmTranslate('abcdefgabc', d) > > > > '€defg€' > > In python the variables of value types, and the variables of lists and > dictionaries are passed to functions somewhat different. > > This should be noticed by any serious programmer in python. - The purpose of my quick and dirty fct was to show it's possible to create a text replacement fct which is using exclusively text / strings via a dict. (Even if in my exemple, I'm using - and can use - None as an empty string !) You are right. It is also arguable, that beeing forced to have to use a number in order to replace a character, may not be a so good idea. This should be noticed by any serious language designer. More seriously. .translate() is a very nice and underestimated method. jmf -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested feature: slice syntax within tuples (or even more generally)?
On Wed, 13 Feb 2013 21:54:43 -0800, stephenwlin wrote: >> I believe the idea of slice literals has been rejected. >> >> > That's too bad...do you have a link to prior discussion on this and what > the reasoning was for rejection? http://osdir.com/ml/python.python-3000.devel/2006-05/msg00686.html http://mail.python.org/pipermail/python-list/2001-August/094909.html E.g.: if x: pass Is that intended as "if slice(x, None, None)" with a missing colon, or "if x" with colon supplied? With the addition of one extra letter, you can use slice notation to return slice objects: class SlicerAndDicer: def __getitem__(self, item): return item s = SlicerAndDicer() And some examples: py> s[2::5] slice(2, None, 5) py> s[::-1] slice(None, None, -1) py> s[3, 4] (3, 4) py> s[3, 4:6] (3, slice(4, 6, None)) py> s[7::, 9] (slice(7, None, None), 9) I feel all giddy inside... By the way, Go-lang also has slices, but they're more like views into an array than Python's slice objects. http://blog.golang.org/2011/01/go-slices-usage-and-internals.html This is not germane to your question, I just found it interesting reading. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested feature: slice syntax within tuples (or even more generally)?
> > > >> I believe the idea of slice literals has been rejected. > > >> > > >> > > > That's too bad...do you have a link to prior discussion on this and what > > > the reasoning was for rejection? There doesn't seem to be any particular > > > downside and things would be more consistent with slice syntax allowed > > > anywhere. > > > > There's *always* downside to new syntax. The question is, does the > > benefit exceed the downside? > > > Fair enough points w.r.t with the costs of implementation, etc. I just meant that, from my perspective, it seems like a simplification of the grammar rather than making it more complex, since it just makes ':' work the same way outside of [] as within it, instead of treating [] as a special case. I'm aware there could be some ambiguities with dictionary construction but it should be pretty easy to resolve with precedence rules. As for making the language more complicated to learn: to be honest, the fact that ':' was treated specially in [] made things more confusing to me until I realized there was a special grammar specifically for that case (since this is not something I would expect coming from other languages). That there would be specific grammar for this case would make more sense if there was something about the __getitem__/__setitem__ protocol that inherently required it, but there isn't really: you're just passing an object to __getitem__ just like you can pass an object to any function, so why would you parse expressions differently in the former case versus the latter? Obviously, this depends on one's individual intuition though, so maybe I'm in the minority here in finding it weird. > > > > What are the benefits of syntactic sugar for slice objects? > > > > Personally, there's not much difference to my eye between: > > > > > > S = slice > > S(1, 20, 3) > > > > versus > > > > (1:20:3) > > > > so I'm skeptical that the benefit is much greater than the cost, as low > > as that cost may be. But if there's no difference, then why have ':' work specially for '[]' operations at all instead of requiring the user to build slice objects manually all the time? It obviously is a convenient and simpler syntax, and there doesn't seem to be any real reason for the artificial restriction that this happens inside '[]' (and in a shallow manner, so no nested slices or slices within tuples) only. > > > > > > > It would be helpful in other cases as well other than the one linked to, > > > since there's good reason to be able to succinctly create and reuse the > > > same indexer object multiple times without having to convert everything > > > into slice() calls. > > > > I don't quite understand this argument. If you mean that you can do this: > > > > s = (1:2) # Like slice(1, 2). > > print alist[s] > > print blist[s] # reuse the slice object > > print clist[s] > > > > > > you can replace the line s = (1:2) to a call to slice, and still reuse > > the slice object. So I don't understand what the syntactic sugar gains > > you. > > > Yes, but you can't just directly use what you wrote within '[]' outside of it, and there doesn't seem to be any real technical reason for this except for historical evolution of the language. Obviously isn't not that hard to convert everything to call slice() manually but it can get verbose quickly for complex multidimensional slices cases (which are common in numpy, which is why Travis Oliphant wants this feature as well...) You can do something hackish like make a dummy object that returns class Indexer: def __getitem__(self, obj): return obj I = Indexer() s = I[1:2,..,3:4:-1,::-1] but that seems that seems mostly to highlight the fact that this is an artificial problem to begin with...'[]' just translates to a function call anyway (more or less), so why treat it differently? Thanks, -Stephen -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested feature: slice syntax within tuples (or even more generally)?
On Thursday, February 14, 2013 3:03:50 AM UTC-5, Steven D'Aprano wrote: > On Wed, 13 Feb 2013 21:54:43 -0800, stephenwlin wrote: > > > > >> I believe the idea of slice literals has been rejected. > > >> > > >> > > > That's too bad...do you have a link to prior discussion on this and what > > > the reasoning was for rejection? > > > > http://osdir.com/ml/python.python-3000.devel/2006-05/msg00686.html > > http://mail.python.org/pipermail/python-list/2001-August/094909.html > > > > E.g.: > > > > if x: > > pass > > > > > > Is that intended as "if slice(x, None, None)" with a missing colon, or > > "if x" with colon supplied? I don't mean to argue with Guido, but unless I'm missing something, the former would be a syntax error and the latter would not be, so even if it might be ambiguous in isolation it wouldn't be in context. Isn't this something that could be resolved without requiring a mathematically more complex parser than Python already requires? (i.e. one that corresponds to a more complex minimal automaton). Also, you could easily restrict that ':' cannot be in top-level expressions, so have to be enclosed with either () or [] (so the latter because just a specific case of a more general rule.) > > > > With the addition of one extra letter, you can use slice notation to > > return slice objects: > > > > class SlicerAndDicer: > > def __getitem__(self, item): > > return item > > > > s = SlicerAndDicer() > > > > > > And some examples: > > > > py> s[2::5] > > slice(2, None, 5) > > py> s[::-1] > > slice(None, None, -1) > > py> s[3, 4] > > (3, 4) > > py> s[3, 4:6] > > (3, slice(4, 6, None)) > > py> s[7::, 9] > > (slice(7, None, None), 9) > Hah, yes. I basically wrote that exact example in my reply to Steven at the same time you replied. numpy.s_ is similar (although I think it does some extra work for odd reasons). Anyway this is an okay workaround, but it just seems to highlight the fact that the restriction of using ':' within [] is arbitrary to begin with, since all you're doing is wrapping a function call. Right now, everything which is parsed within f() is also parsed within f[], but the latter is parsing more things just by virtue of the fact that that it's a [] instead of (). To be honest, this feels like more of an artifact of historical evolution than anything else. It just doesn't make much sense create a special syntax for parsing expressions into objects in one particular context but not others when there's nothing special about the underlying object protocol that requires it to be handled separately (and perhaps this was not always the case...I've not been with Python long enough to know the particulars of how this was implemented in the past...) Anyway, thanks for the feedback! - Stephen -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested feature: slice syntax within tuples (or even more generally)?
> Hah, yes. I basically wrote that exact example in my reply to Steven at the > same time you replied. numpy.s_ is similar (although I think it does some > extra work for odd reasons). Oops, this is silly in retrospect...sorry, wasn't looking at the From: line carefully enough and didn't realize I was responding to you again. -- http://mail.python.org/mailman/listinfo/python-list
Re: Statistics...help with numpy/scipy install
On 02/13/2013 09:38 PM, Rex Macey wrote: I am sure I have python installed. I have been running it. in command line the window title is c:\python33\python.exe. The first line begins Python 3.3.0. Later in the line is the string "64 bit ] on Win32". Thus it appears I am trying to run a 32bit numpy with a 64bit python. (Seems like a big ole 64 bit python should be able to swallow a little 32 bitty numpy). Is there a 64bit numpy? If not why not? Can someone get on this? Seriously, I'm under the impression that I need the 64 bit python because I have a 64 bit OS. I can't answer the Numpy aspects, but I can tell you about 32bit versus 64bit. A 32 bit OS can only handle 32 bit applications. It's conceivable to build a 32bit OS that will load and run 64bit apps, but it's probably impractical, and I don't know of anybody who has tried. A 64bit OS can and does load both 32bit apps and 64bit apps. But once it has loaded the app, the entire process has to be of the same "bittedness". For Windows, that means any DLL's loaded from a 64bit process have to be 64bit, and any DLL's loaded from a 32bit process must be 32bit. A python library may consist entirely of Python code, in which case it would work for either 32bit or 64bit Python installation. But if the library includes DLL's (which Numpy certainly would) then there have to be separate versions of those DLL's. Now, that library installation package may decide to include both sets of DLL's, and just install the appropriate ones at installation time. But that choice is entirely up to the library author. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Statistics...help with numpy/scipy install
On 14 February 2013 05:29, Terry Reedy wrote: > On 2/13/2013 9:38 PM, Rex Macey wrote: >> >> I am sure I have python installed. I have been running it. in command >> line the window title is c:\python33\python.exe. The first line >> begins Python 3.3.0. Later in the line is the string "64 bit ] >> on Win32". I don't know why you feel the need to paraphrase this information rather than simply paste the interpreter message into the email. The latter would be more useful for others trying to help understand your problem. >> Thus it appears I am trying to run a 32bit numpy with a 64bit python. >> (Seems like a big ole 64 bit python should be able to swallow a >> little 32 bitty numpy). Is there a 64bit numpy? If not why not? Because numpy/scipy make extensive use of Python's underlying binary interfaces. These are incompatible between 32 and 64 bit Python. > Ask the numpy people. I am surprised since a reason to be using 64 rather > than 32 bit python is to have objects larger than 2 gigabytes and memory > larger than 4 gigabytes. Numerical/scientific programming is relatively > likely to need such. Yes but most people who are doing that sort of thing would just compile their own numpy/scipy and probably wouldn't be using Windows for the their main computations anyway. Numpy does work on 64 bit Python but official binaries are not distributed via the sourceforge page. Unofficial binaries are available here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy >> someone get on this? Seriously, I'm under the impression that I need >> the 64 bit python because I have a 64 bit OS. I don't know about Windows 8 but I've used 32 bit Python on 64 bit XP no problem. My impression was that 64 bit Windows (unlike OSX and most Linux distros) ships with 32 bit duplicates of all its libraries so that it can run 32 bit applications without modification. My Windows usage significantly predates Windows 8, though so this may have changed some time ago. Oscar -- http://mail.python.org/mailman/listinfo/python-list
any chance for contracts and invariants in Python?
This PEP seems to be gathering dust: http://www.python.org/dev/peps/pep-0316/ I was thinking the other day, would contracts and invariants not be better than unit tests? That is, they could do what unit tests do and more, bc they run at execution time and not just at development time? -- http://mail.python.org/mailman/listinfo/python-list
Re: Awsome Python - chained exceptions
Am 13.02.2013 um 17:14 schrieb Rick Johnson: Q1: How could a line in the "try" block ever be considered offensive? Because it throws an error? try: rrick.go_and_fuck_yourself() finally: rrick.get_lost() See, wasn't that difficult, was it? :D Are you serious? No, I just couldn't resist this invitation even though I'm making a fool of myself responding to flamers/trolls... *le sigh* Uli -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested feature: slice syntax within tuples (or even more generally)?
stephenw...@gmail.com wrote: > Would it be feasible to modify the Python grammar to allow ':' to > generate slice objects everywhere rather than just indexers and > top-level tuples of indexers? > Would this be a dict with a slice as key or value, or a set with a slice with a step?: {1:2:3} You can't just allow ':' to generate slice objects everwhere without introducing ambiguity, so your proposal would have to be to allow slice objects in wider but still restricted contexts. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
how to right the regular expression ?
my tv.txt is : http://202.177.192.119/radio5 香港电台第五台(可于Totem/VLC/MPlayer播放) http://202.177.192.119/radio35 香港电台第五台(DAB版,可于Totem/VLC/MPlayer播放) http://202.177.192.119/radiopth 香港电台普通话台(可于Totem/VLC/MPlayer播放) http://202.177.192.119/radio31 香港电台普通话台(DAB版,可于Totem/VLC/MPlayer播放) octoshape:rthk.ch1 香港电台第一台(粤) octoshape:rthk.ch2 香港电台第二台(粤) octoshape:rthk.ch6 香港电台普通话台 octoshape:rthk.ch3 香港电台第三台(英) what i want to get the result is 1group is http://202.177.192.119/radio5 2group is 香港电台第五台 3group is (可于Totem/VLC/MPlayer播放) 1group is http://202.177.192.119/radio35 2group is 香港电台第五台 3group is (DAB版,可于Totem/VLC/MPlayer播放) 1group is http://202.177.192.119/radiopth 2group is 香港电台普通话台 3group is (可于Totem/VLC/MPlayer播放) 1group is http://202.177.192.119/radio31 2group is 香港电台普通话台 3group is (DAB版,可于Totem/VLC/MPlayer播放) 1group is octoshape:rthk.ch1 2group is 香港电台第一台 3group is (粤) 1group is octoshape:rthk.ch2 2group is 香港电台第二台 3group is (粤) 1group is octoshape:rthk.ch6 2group is 香港电台普通话台 3group is none 1group is octoshape:rthk.ch3 2group is 香港电台第三台 3group is (英) here is my code: # -*- coding: utf-8 -*- import re rfile=open("tv.txt","r") pat='([a-z].+?\s)(.+)(\(.+\))' for line in rfile.readlines(): Match=re.match(pat,line) print "1group is ",Match.group(1),"2group is ",Match.group(2),"3group is ",Match.group(3) rfile.close() the output is : 1group is http://202.177.192.119/radio5 2group is 香港电台第五台 3group is (可于Totem/VLC/MPlayer播放) 1group is http://202.177.192.119/radio35 2group is 香港电台第五台 3group is (DAB版,可于Totem/VLC/MPlayer播放) 1group is http://202.177.192.119/radiopth 2group is 香港电台普通话台 3group is (可于Totem/VLC/MPlayer播放) 1group is http://202.177.192.119/radio31 2group is 香港电台普通话台 3group is (DAB版,可于Totem/VLC/MPlayer播放) 1group is octoshape:rthk.ch1 2group is 香港电台第一台 3group is (粤) 1group is octoshape:rthk.ch2 2group is 香港电台第二台 3group is (粤) 1group is Traceback (most recent call last): File "tv.py", line 7, in print "1group is ",Match.group(1),"2group is ",Match.group(2),"3group is ",Match.group(3) AttributeError: 'NoneType' object has no attribute 'group' how to revise my code to get the output? -- http://mail.python.org/mailman/listinfo/python-list
ISLAM and the AIM of LIFE
ISLAM and the AIM of LIFE What is your purpose in life? What is the rationale behind our life? Why do we live in this life? These questions frequently intrigue people who try to find accurate answers. People provide different answers to these questions. Some people believe the purpose of life is to accumulate wealth. But one may wonder: What is the purpose of life after one has collected colossal amounts of money? What then? What will the purpose be once money is gathered? If the purpose of life is to gain money, there will be no purpose after becoming wealthy. And in fact, here lies the problem of some disbelievers or misbelievers at some stage of their life, when collecting money is the target of their life. When they have collected the money they dreamt of, their life loses its purpose. They suffer from the panic of nothingness and they live in tension and restlessness. Can Wealth Be an Aim? We often hear of a millionaire committing suicide, sometimes, not the millionaire himself but his wife, son, or daughter. The question that poses itself is: Can wealth bring happiness to one’s life? In most cases the answer is NO. Is the purpose of collecting wealth a standing purpose? As we know, the five-year old child does not look for wealth: a toy for him is equal to a million dollars. The eighteen-year old adolescent does not dream of wealth because he is busy with more important things. The ninety-year old man does not care about money; he is worried more about his health. This proves that wealth cannot be a standing purpose in all the stages of the individual's life. Wealth can do little to bring happiness to a disbeliever, because he/ she is not sure about his fate. A disbeliever does not know the purpose of life. And if he has a purpose, this purpose is doomed to be temporary or self destructive. What is the use of wealth to a disbeliever if he feels scared of the end and skeptical of everything. A disbeliever may gain a lot of money, but will surely lose himself. Worshipping Allah as an Aim On the contrary, faith in Allah gives the believer the purpose of life that he needs. In Islam, the purpose of life is to worship Allah. The term "Worship" covers all acts of obedience to Allah. The Islamic purpose of life is a standing purpose. The true Muslim sticks to this purpose throughout all the stages of his life, whether he is a child, adolescent, adult, or an old man. Worshipping Allah makes life purposeful and meaningful, especially within the framework of Islam. According to Islam this worldly life is just a short stage of our life. Then there is the other life. The boundary between the first and second life is the death stage, which is a transitory stage to the second life. The type of life in the second stage a person deserves depends on his deeds in the first life. At the end of the death stage comes the day of judgment. On this day, Allah rewards or punishes people according to their deeds in the first life. The First Life as an Examination So, Islam looks at the first life as an examination of man. The death stage is similar to a rest period after the test, i. e. after the first life. The Day of Judgment is similar to the day of announcing the results of the examinees. The second life is the time when each examinee enjoys or suffers from the outcome of his behavior during the test period. In Islam, the line of life is clear, simple, and logical: the first life, death, the Day of Judgment, and then the second life. With this clear line of life, the Muslim has a clear purpose in life. The Muslim knows he is created by Allah. Muslims know they are going to spend some years in this first life, during which they have to obey God, because God will question them and hold them responsible for their public or private deeds, because Allah knows about all the deeds of all people. The Muslim knows that his deeds in the first life will determine the type of second life they will live in. The Muslim knows that this first life is a very short one, one hundred years, more or less, whereas the second life is an eternal one. The Eternity of the Second Life The concept of the eternity of the second life has a tremendous effect on a Muslims during their first life, because Muslims believe that their first life determines the shape of their second life. In addition, this determines the shape of their second life and this determination will be through the Judgment of Allah, the All just and Almighty. With this belief in the second life and the Day of Judgment, the Muslim's life becomes purposeful and meaningful. Moreover, the Muslim's standing purpose is to go to Paradise in the second life. In other words, the Muslim's permanent purpose is to obey Allah, to submit to Allah, to carry out His orders, and to keep in continues contact with Him through prayers (five times a day), through fasting (one month a year), through charity (as often as possible), and through pilgrimage (once in one's life). The Need for a Permanent Purp
Re: how to right the regular expression ?
On 2013-02-14 14:13, python wrote: my tv.txt is : http://202.177.192.119/radio5 香港电台第五台(可于Totem/VLC/MPlayer播放) http://202.177.192.119/radio35 香港电台第五台(DAB版,可于Totem/VLC/MPlayer播放) http://202.177.192.119/radiopth 香港电台普通话台(可于Totem/VLC/MPlayer播放) http://202.177.192.119/radio31 香港电台普通话台(DAB版,可于Totem/VLC/MPlayer播放) octoshape:rthk.ch1 香港电台第一台(粤) octoshape:rthk.ch2 香港电台第二台(粤) octoshape:rthk.ch6 香港电台普通话台 octoshape:rthk.ch3 香港电台第三台(英) what i want to get the result is 1group is http://202.177.192.119/radio5 2group is 香港电台第五台 3group is (可于Totem/VLC/MPlayer播放) 1group is http://202.177.192.119/radio35 2group is 香港电台第五台 3group is (DAB版,可于Totem/VLC/MPlayer播放) 1group is http://202.177.192.119/radiopth 2group is 香港电台普通话台 3group is (可于Totem/VLC/MPlayer播放) 1group is http://202.177.192.119/radio31 2group is 香港电台普通话台 3group is (DAB版,可于Totem/VLC/MPlayer播放) 1group is octoshape:rthk.ch1 2group is 香港电台第一台 3group is (粤) 1group is octoshape:rthk.ch2 2group is 香港电台第二台 3group is (粤) 1group is octoshape:rthk.ch6 2group is 香港电台普通话台 3group is none 1group is octoshape:rthk.ch3 2group is 香港电台第三台 3group is (英) > here is my code: # -*- coding: utf-8 -*- import re rfile=open("tv.txt","r") pat='([a-z].+?\s)(.+)(\(.+\))' for line in rfile.readlines(): Match=re.match(pat,line) print "1group is ",Match.group(1),"2group is ",Match.group(2),"3group is ",Match.group(3) rfile.close() the output is : 1group is http://202.177.192.119/radio5 2group is 香港电台第五台 3group is (可于Totem/VLC/MPlayer播放) 1group is http://202.177.192.119/radio35 2group is 香港电台第五台 3group is (DAB版,可于Totem/VLC/MPlayer播放) 1group is http://202.177.192.119/radiopth 2group is 香港电台普通话台 3group is (可于Totem/VLC/MPlayer播放) 1group is http://202.177.192.119/radio31 2group is 香港电台普通话台 3group is (DAB版,可于Totem/VLC/MPlayer播放) 1group is octoshape:rthk.ch1 2group is 香港电台第一台 3group is (粤) 1group is octoshape:rthk.ch2 2group is 香港电台第二台 3group is (粤) 1group is Traceback (most recent call last): File "tv.py", line 7, in print "1group is ",Match.group(1),"2group is ",Match.group(2),"3group is ",Match.group(3) AttributeError: 'NoneType' object has no attribute 'group' how to revise my code to get the output? The problem is that the regex makes '(\(.+\))' mandatory, but example 7 doesn't match it. You can make it optional by wrapping it in a non-capturing group (?:...), like this: pat = r'([a-z].+?\s)(.+)(?:(\(.+\)))?' Also, it's highly recommended that you use raw string literals (r'...') when writing regex patterns and replacements. -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested feature: slice syntax within tuples (or even more generally)?
> > You can't just allow ':' to generate slice objects everwhere without > > introducing ambiguity, so your proposal would have to be to allow slice > > objects in wider but still restricted contexts. Yeah, I mentioned that in a follow-up. I'm pretty sure of just allowing it within [] and () would work, though, and still be a pretty consistent/simple grammar. This would also remove Steven's (i.e. Guido's) objection that about if x: This would still preserves the main benefit of allowing you to succinctly create slices in any context you need an expression in, because you can always add () around any expression. -Stephen -- http://mail.python.org/mailman/listinfo/python-list
Re: Simulate Keyboard keypress Delay
On Wednesday, February 13, 2013 11:47:36 AM DaGeek247 wrote: > I am using the windows api feature getasynckeystate() to check the status of > every key pressed; like this; > > #always checking > while(True): > #iterate through list of ascii codes > for num in range(0,127): > #if ascii code key is being pressed > if win32api.GetAsyncKeyState(num): > #do stuff > > This works great, almost. The issue that comes up now is that every time i > press a key, the code grabs two or three key presses. > > So i tried making sure that repeated keys weren't pressed repeatedly; > > #always checking > while(True): > #iterate through list of ascii codes > for num in range(0,127): > #if ascii code key is being pressed > if win32api.GetAsyncKeyState(num): > if oldkeychar == num: > #don't do stuff > else: > #do stuff > > this works great, but It won't record stuff like 'look' or 'suffer' because > it doesn't record repeated keys. So I try doing a delay instead; > > #always checking > while(True): > #iterate through list of ascii codes > for num in range(0,127): > #if ascii code key is being pressed > if win32api.GetAsyncKeyState(num): > if oldkeychar == num: > if crrenttime > (time.time() - .5) > #do stuff because key has been repeated, but not because > it was held down else: > #don't do stuff because key is pressed to soon > else: > #do stuff because key is not repeated > currenttime = time.time() > > this almost works, but I end recording some double keypresses, and missing > others. Does anybody have any suggestions? this will only work on a windows machine. It is from C++ runtime lib msvcrt.dll in py module import msvcrt while 1: ch = msvcrt.getch() ## returns one char if ch == 'Y' : # do stuff or break break print "%d (%r)" % (ch, ch) # also, kbhit() # returns true if char is available # also, ungetch(ch) # undo char ch jd inqvista.com -- http://mail.python.org/mailman/listinfo/python-list
OpenCV and WIFI IP Camera Issue
Hey, Iv installed OpenCV on my windows machine. I can successfully view the camera stream from my laptop so the installation was successful. However when i edited the code adding in the address of my IP camera like so import cv2 cv2.namedWindow("preview") vc = cv2.VideoCapture('http://192.168.1.72:1025/videostream.cgiUSERNAMEANDPASSWORD') if vc.isOpened(): # try to get the first frame rval, frame = vc.read() else: rval = False while rval: cv2.imshow("preview", frame) rval, frame = vc.read() key = cv2.waitKey(20) if key == 27: # exit on ESC break When run, python tries to open the window to display the camera feed then closes before displaying the feed. Anyone have any ideas why? I read somewhere that there is an issue with this been run on windows? Any insight would be appreciated! Im all googled out. Thanks, Sam -- http://mail.python.org/mailman/listinfo/python-list
Re: any chance for contracts and invariants in Python?
I don't know anything about the status of this PEP or why it hasn't been implemented, but here's what strikes me as obviously complex: Doesn't one need to traverse the entire class hierarchy on every function call? So if I have class A: def foo(self): return 1 class B(A): "inv: True" def foo(self): "post: __return__ == 2" return 2 Now, I have f = B().foo f() . What does Python do? If your answer is 1. Look up class of f 2. Check its invariant (succeeds) 3. Execute the function 4. Check post conditions of f (succeeds) 5. return 2 Then what will I get if I run any of the following programs: A.foo.__doc__ = 'inv: __return__ == 1' f() def _foo(self): 'post: __return__ == 3' A.foo = _foo f() A.__doc__ = 'inv: False' f() So any implementation has to choose one of the following: 1. Ignore invariants and postconditions of inherited classes - defeats the purpose. 2. Only respect definitions in classes and methods in the original definition, which would be unpythonic 3. Only respect the "original" definitions, for some value of original. Simarily, this would break monkey patching. 4. Update all subclasses whenever something changes. 5. Traverse the entire class hierarchy for every method call. Which option should be picked? Additionally, the reference implementation is not actually a fork of cpython (or a metaclass), but a Python script that - as far as I understand - I have to call manually to start using contracts. - Philipp On 14.02.2013 12:42, mrk...@gmail.com wrote: > > This PEP seems to be gathering dust: > > http://www.python.org/dev/peps/pep-0316/ > > I was thinking the other day, would contracts and invariants not be better > than unit tests? That is, they could do what unit tests do and more, bc they > run at execution time and not just at development time? > signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: First attempt at a Python prog (Chess)
On 2013-02-14 06:05:13 +, Tim Roberts said: Chris Hinsley wrote: New to Python, which I really like BTW. First serious prog. Hope you like it. I know it needs a 'can't move if your King would be put into check' test. But the weighted value of the King piece does a surprising emergent job. It looks a little like a C program ported line-by-line to Python. For example, in Python, there's no reason not to keep the board as an 8x8 array instead of a 64-element list. That by itself would make the code easier to read. It would also let you replace this: for row in range(8): for col in range(8): with the more Pythonic: for row in board: for cell in row: I would probably replace the piece_type function with a map that maps the piece number directly to the piece Is a Python list as fast as a bytearray ? I didn't copy a C prog BTW ! Yep, after I posted the code I started thinking about how to do that sort of thing :) Thanks, for the advice. Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: any chance for contracts and invariants in Python?
On Thu, Feb 14, 2013 at 10:03 AM, Philipp Hagemeister wrote: > So any implementation has to choose one of the following: > > 1. Ignore invariants and postconditions of inherited classes - defeats > the purpose. > 2. Only respect definitions in classes and methods in the original > definition, which would be unpythonic > 3. Only respect the "original" definitions, for some value of original. > Simarily, this would break monkey patching. > 4. Update all subclasses whenever something changes. > 5. Traverse the entire class hierarchy for every method call. > > Which option should be picked? #5, with the expectation that like assertions the entire machinery would be turned off when the -O flag is passed, or perhaps even requiring a special flag to enable in the first place. Contracts and invariants would only be used in development work, not in production code. -- http://mail.python.org/mailman/listinfo/python-list
Re: OpenCV and WIFI IP Camera Issue
On 2013-02-14 17:25, Sam Berry wrote: Hey, Iv installed OpenCV on my windows machine. I can successfully view the > camera stream from my laptop so the installation was successful. > However when i edited the code adding in the address of my IP camera > like so import cv2 cv2.namedWindow("preview") vc = cv2.VideoCapture('http://192.168.1.72:1025/videostream.cgiUSERNAMEANDPASSWORD') if vc.isOpened(): # try to get the first frame rval, frame = vc.read() else: rval = False while rval: cv2.imshow("preview", frame) rval, frame = vc.read() key = cv2.waitKey(20) if key == 27: # exit on ESC break When run, python tries to open the window to display the camera feed > then closes before displaying the feed. Anyone have any ideas why? I read somewhere that there is an issue with this been run on windows? Any insight would be appreciated! Im all googled out. I wonder whether you should be waiting for the key and _then_ reading the next frame. -- http://mail.python.org/mailman/listinfo/python-list
Re: any chance for contracts and invariants in Python?
On 2013-02-14 18:05, Ian Kelly wrote: On Thu, Feb 14, 2013 at 10:03 AM, Philipp Hagemeister wrote: So any implementation has to choose one of the following: 1. Ignore invariants and postconditions of inherited classes - defeats the purpose. 2. Only respect definitions in classes and methods in the original definition, which would be unpythonic 3. Only respect the "original" definitions, for some value of original. Simarily, this would break monkey patching. 4. Update all subclasses whenever something changes. 5. Traverse the entire class hierarchy for every method call. Which option should be picked? #5, with the expectation that like assertions the entire machinery would be turned off when the -O flag is passed, or perhaps even requiring a special flag to enable in the first place. Contracts and invariants would only be used in development work, not in production code. Maybe what it needs is a decorator that parses the docstrings, creates functions to do the checks, and then wraps them around the functions. -- http://mail.python.org/mailman/listinfo/python-list
[no subject]
using ubuntu 12.10 i am trying to run a python block, namely OP25, in GNU Radio Companion v3.6.3-35-g4435082f. i get the following error: Executing: "/home/matt/op25_grc.py" Imported legacy fsk4 Using Volk machine: ssse3_32 Traceback (most recent call last): File "/home/matt/op25_grc.py", line 493, in tb = op25_grc() File "/home/matt/op25_grc.py", line 231, in __init__ self.wxgui_fftsink2_0_0.set_callback(wxgui_fftsink2_0_0_callback) File "/usr/local/lib/python2.7/dist-packages/gnuradio/gr/hier_block2.py", line 54, in __getattr__ return getattr(self._hb, name) AttributeError: 'gr_hier_block2_sptr' object has no attribute 'set_callback' i cannot find any sort of solution on the web anywhere. any sort of help will be much appreciated. thanks in advance.-- http://mail.python.org/mailman/listinfo/python-list
Re: First attempt at a Python prog (Chess)
On Thu, Feb 14, 2013 at 10:48 AM, Chris Hinsley wrote: > Is a Python list as fast as a bytearray ? I didn't copy a C prog BTW ! >>> from timeit import Timer >>> t1 = Timer("board[36] = board[20]; board[20] = ' '", "board = >>> bytearray('RNBQKBNR >>> rnbqkbnr')") >>> min(t1.repeat(10)) 0.1678651895701826 >>> t2 = Timer("board[3][4] = board[1][4]; board[1][4] = ' '", "board = >>> [list('RNBQKBNR'), ['P'] * 8] + [[' ']*8 for i in range(4)] + [['p'] * 8, >>> list('rnbqkbnr')]") >>> min(t2.repeat(10)) 0.2080088391122672 Natively, it looks like the bytearray is about 19% faster for moving a piece from one square to another. Those array offsets aren't calculated for free, though. Look what happens when we have to do the math: >>> t3 = Timer("board[r1*8+c1] = board[r2*8+c2]; board[r2*8+c2] = ' '", "board >>> = bytearray('RNBQKBNR >>> rnbqkbnr'); r1 = 3; r2 = 1; c1 = c2 = 4") >>> min(t3.repeat(10)) 0.314191887516472 >>> t4 = Timer("board[r1][c1] = board[r2][c2]; board[r2][c2] = ' '", "board = >>> [list('RNBQKBNR'), ['P'] * 8] + [[' ']*8 for i in range(4)] + [['p'] * 8, >>> list('rnbqkbnr')]; r1 = 3; r2 = 1; c1 = c2 = 4") >>> min(t4.repeat(10)) 0.24427881197186707 That said, the philosophy of Python focuses more on readability than on speed. The goalpost for speed in a Python program is that it be "fast enough". If you have more stringent speed requirements than that, then Python may not be the right tool for the job. -- http://mail.python.org/mailman/listinfo/python-list
Re: any chance for contracts and invariants in Python?
On 02/14/2013 10:05 AM, Ian Kelly wrote: On Thu, Feb 14, 2013 at 10:03 AM, Philipp Hagemeister wrote: So any implementation has to choose one of the following: 1. Ignore invariants and postconditions of inherited classes - defeats the purpose. 2. Only respect definitions in classes and methods in the original definition, which would be unpythonic 3. Only respect the "original" definitions, for some value of original. Simarily, this would break monkey patching. 4. Update all subclasses whenever something changes. 5. Traverse the entire class hierarchy for every method call. Which option should be picked? #5, with the expectation that like assertions the entire machinery would be turned off when the -O flag is passed, or perhaps even requiring a special flag to enable in the first place. Contracts and invariants would only be used in development work, not in production code. I was under the impression that the real power of contracts was when they are /not/ turned off -- the errors we don't catch in development are the serious ones. ;) -- ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re:
Please post the code, or a link to the code... Also, what version of python are you running this code over? *Matt Jones* On Thu, Feb 14, 2013 at 12:26 PM, wrote: > using ubuntu 12.10 i am trying to run a python block, namely OP25, in > GNU Radio Companion v3.6.3-35-g4435082f. i get the following error: > > Executing: "/home/matt/op25_grc.py" > > Imported legacy fsk4 > Using Volk machine: ssse3_32 > Traceback (most recent call last): > File "/home/matt/op25_grc.py", line 493, in > tb = op25_grc() > File "/home/matt/op25_grc.py", line 231, in __init__ > self.wxgui_fftsink2_0_0.set_callback(wxgui_fftsink2_0_0_callback) > File "/usr/local/lib/python2.7/dist-packages/gnuradio/gr/hier_block2.py", > line 54, in __getattr__ > return getattr(self._hb, name) > AttributeError: 'gr_hier_block2_sptr' object has no attribute > 'set_callback' > > i cannot find any sort of solution on the web anywhere. any sort of help > will be much appreciated. thanks in advance. > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested feature: slice syntax within tuples (or even more generally)?
On Thu, Feb 14, 2013 at 1:03 AM, Steven D'Aprano wrote: > E.g.: > > if x: > pass > > > Is that intended as "if slice(x, None, None)" with a missing colon, or > "if x" with colon supplied? That's not ambiguous, because the former is simply invalid syntax. However, consider the following. if 1: 2: That could be either a one-line if statement where the condition is 1 and the body is slice(2, None), or it could be the beginning of a multi-line if block where the condition is slice(1, 2). If the parser sees that, should it expect the next line to be indented or not? If it relies on indentation to determine this, then it loses some ability to warn the user of incorrect indentation. Then we have dictionary literals: {1:2:3} Should that be read as dict([(slice(1, 2), 3)]) or dict([(1, slice(2, 3))])? Or even set([slice(1, 2, 3)])? -- http://mail.python.org/mailman/listinfo/python-list
[no subject]
Hello All, I am a newbie to python language. I need your help in implementation of Binary tree in python. I have a count of nodes and I need to draw a binary tree. Suppose if count is 5 then tree will look like 1 / \ / \ 2 3 / \ -- http://mail.python.org/mailman/listinfo/python-list
Binary tree implementation
Hello All, I am a newbie to python language. I need your help in implementation of Binary tree in python. I have a count of nodes and I need to draw a binary tree. Suppose if count is 5 then tree will look like 1 / \ / \ 2 3 / \ /\ 4 5. Does anybody have code for this? Or any hint? PS: Sorry for previous mail !! Thank you :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Binary tree implementation
On 02/14/2013 11:18 AM, Megha Agrawal wrote: Hello All, I am a newbie to python language. I need your help in implementation of Binary tree in python. I have a count of nodes and I need to draw a binary tree. Suppose if count is 5 then tree will look like 1 / \ / \ 2 3 / \ /\ 4 5. Does anybody have code for this? Or any hint? I'm confused! Do you need to *implement* a binary tree or *draw* a binary tree. You say both, but those are very different things. Hint: If you want quality (volunteer) help, please put more time into the quality of your question.As it is stated, we really don't know what you want help with. Gary Herron PS: Sorry for previous mail !! Thank you :) -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 -- http://mail.python.org/mailman/listinfo/python-list
Peter Otten
From: Peter Otten <__pete...@web.de> To: python-list@python.org Cc: Date: Thu, 14 Feb 2013 09:00:58 +0100 Subject: Re: "Exception ... in ignored" Messages Ami Tavory wrote: > Hi, > > Running the unit tests for some generator code, prints, as a side > effect, > numerous messages of the form: > > ... > Exception NameError: "global name 'l' is not defined" in _dagpype_internal_fn_act at 0x9d4c500> ignored > Exception AttributeError: "'NoneType' object has no attribute 'close'" in > ignored > Exception AttributeError: "'NoneType' object has no attribute 'close'" in > ignored > ... > > The tests otherwise run fine. > > Is there any way to catch the point where such a message originates, and > print a traceback? I find it difficult to debug otherwise. I've tried > running Python with -W error, catching warnings with context managers, and > so forth, but without any success. >>> def g(): ... try: ... yield 42 ... finally: ... 1/0 ... >>> for item in g(): ... break ... Exception ZeroDivisionError: 'integer division or modulo by zero' in ignored Can you exhaust the generator? >>> for item in g(): ... pass ... Traceback (most recent call last): File "", line 1, in File "", line 5, in g ZeroDivisionError: integer division or modulo by zero Explicitly closing the generator seems to work, too: >>> x = g() >>> next(x) 42 >>> x.close() Traceback (most recent call last): File "", line 1, in File "", line 5, in g ZeroDivisionError: integer division or modulo by zero - - - Hi Peter, Thanks for your answer! So basically the thing is that, as you've shown, if you exhaust a generator or force-close it, an exception is indeed thrown. However, in this were the case then unittest would identify it as a problem, and I could relatively easily get a traceback and see from where it's originating. However, the unittests are passing fine (except for the pesky messages), so it's something else. I'm starting to think that what's happening is something like this: I have a cascade of generator objects (some hold on to others), and the unittests check both the exhaustion case and the non-exhaustion case (both cases are valid use cases). *Later on*, after the tests finish, the garbage collector starts tearing down the generator cascade, but in a different order. Some generators, while closing down, are attempting to close down other generators that no longer exist. So, notwithstanding your correct answer - I'm still stumped about finding out how to get rid of these annoying messages. Thanks, Ami -- http://mail.python.org/mailman/listinfo/python-list
Fwd: Re:
Sending back to the maillist *Matt Jones* -- Forwarded message -- From: Date: Thu, Feb 14, 2013 at 1:42 PM Subject: Re: Re: To: Matt Jones thanks for replying Matt. I am using version 2.7.3. im not sure if this is right but here is the code from "/usr/local/lib/python2.7/dist-packages/gnuradio/gr/hier_block2.py" # Copyright 2006,2007 Free Software Foundation, Inc. # # This file is part of GNU Radio # # GNU Radio is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3, or (at your option) # any later version. # # GNU Radio is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with GNU Radio; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. # from gnuradio_core import hier_block2_swig try: import pmt except ImportError: from gruel import pmt # # This hack forces a 'has-a' relationship to look like an 'is-a' one. # # It allows Python classes to subclass this one, while passing through # method calls to the C++ class shared pointer from SWIG. # # It also allows us to intercept method calls if needed # class hier_block2(object): """ Python wrapper around the C++ hierarchical block implementation. Provides convenience functions and allows proper Python subclassing. """ def __init__(self, name, input_signature, output_signature): """ Create a hierarchical block with a given name and I/O signatures. """ self._hb = hier_block2_swig(name, input_signature, output_signature) def __getattr__(self, name): """ Pass-through member requests to the C++ object. """ if not hasattr(self, "_hb"): raise RuntimeError("hier_block2: invalid state--did you forget to call gr.hier_block2.__init__ in a derived class?") return getattr(self._hb, name) def connect(self, *points): """ Connect two or more block endpoints. An endpoint is either a (block, port) tuple or a block instance. In the latter case, the port number is assumed to be zero. To connect the hierarchical block external inputs or outputs to internal block inputs or outputs, use 'self' in the connect call. If multiple arguments are provided, connect will attempt to wire them in series, interpreting the endpoints as inputs or outputs as appropriate. """ if len (points) < 1: raise ValueError, ("connect requires at least one endpoint; %d provided." % (len (points),)) else: if len(points) == 1: self._hb.primitive_connect(points[0].to_basic_block()) else: for i in range (1, len (points)): self._connect(points[i-1], points[i]) def _connect(self, src, dst): (src_block, src_port) = self._coerce_endpoint(src) (dst_block, dst_port) = self._coerce_endpoint(dst) self._hb.primitive_connect(src_block.to_basic_block(), src_port, dst_block.to_basic_block(), dst_port) def _coerce_endpoint(self, endp): if hasattr(endp, 'to_basic_block'): return (endp, 0) else: if hasattr(endp, "__getitem__") and len(endp) == 2: return endp # Assume user put (block, port) else: raise ValueError("unable to coerce endpoint") def disconnect(self, *points): """ Disconnect two endpoints in the flowgraph. To disconnect the hierarchical block external inputs or outputs to internal block inputs or outputs, use 'self' in the connect call. If more than two arguments are provided, they are disconnected successively. """ if len (points) < 1: raise ValueError, ("disconnect requires at least one endpoint; %d provided." % (len (points),)) else: if len (points) == 1: self._hb.primitive_disconnect(points[0].to_basic_block()) else: for i in range (1, len (points)): self._disconnect(points[i-1], points[i]) def _disconnect(self, src, dst): (src_block, src_port) = self._coerce_endpoint(src) (dst_block, dst_port) = self._coerce_endpoint(dst) self._hb.primitive_disconnect(src_block.to_basic_block(), src_port, dst_block.to_basic_block(), dst_port) def msg_connect(self, src, srcport, dst, dstport): self.primitive_msg_connect(src.to_basic_block(), srcport, dst.to_basic_block(), dst
Lib to generate XML/JSON[P] output from a DTD/XSD/JSON Schema/etc
Hi, I've searched both this group and the web but was unable to find an answer, sorry if it has already been answered, it seems such a common problem that I’m sure someone has asked before. We have a WebServices platform that must reply in XML, JSON, or JSONP. Having to convert between these formats is a really pain in the neck. What I’d like to do is, given some schema representation, that could be a DTD, XSD or whatever and a python dictionary with the values for each node, generate the output in either XML, JSON or JSONP. For instance, if the XSD would be: http://www.w3.org/2001/XMLSchema";> And given the following dict: { “foo”: “bar”, “hello”: “world”, “choice”: “B”, “callback”: “process_server_reply” } Be able to generate either this XML: Bar World B Or this JSON: { "foo": "bar", "hello": "world", "choice": "B" } Or this JSONP: process_server_reply({"foo": "bar","hello": "world","choice": "B"}); Which library/technique would you guys recommend for this kind of scenario? Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: First attempt at a Python prog (Chess)
Hi Chris On Wednesday, 13 February 2013 23:25:09 UTC, Chris Hinsley wrote: > New to Python, which I really like BTW. Welcome aboard! But aren't you supposed to be writing Forth? ;-) Cheers Jon N -- http://mail.python.org/mailman/listinfo/python-list
AttributeError: 'gr_hier_block2_sptr' object has no attribute 'set_callback'
I am using ubuntu 12.10 and python version 2.7.3. i run the following command in terminal: matt@matt-Inspiron-1525:~$ python -m trace --count -C . op25_grc.py Here is the output with an error: Imported legacy fsk4 Using Volk machine: ssse3_32 Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main "__main__", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/usr/lib/python2.7/trace.py", line 819, in main() File "/usr/lib/python2.7/trace.py", line 807, in main t.runctx(code, globs, globs) File "/usr/lib/python2.7/trace.py", line 513, in runctx exec cmd in globals, locals File "op25_grc.py", line 493, in tb = op25_grc() File "op25_grc.py", line 231, in __init__ self.wxgui_fftsink2_0_0.set_callback(wxgui_fftsink2_0_0_callback) File "/usr/local/lib/python2.7/dist-packages/gnuradio/gr/hier_block2.py", line 54, in __getattr__ return getattr(self._hb, name) AttributeError: 'gr_hier_block2_sptr' object has no attribute 'set_callback' here is the code for "hier_block2_.py": # Copyright 2006,2007 Free Software Foundation, Inc. # # This file is part of GNU Radio # # GNU Radio is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3, or (at your option) # any later version. # # GNU Radio is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with GNU Radio; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. # from gnuradio_core import hier_block2_swig try: import pmt except ImportError: from gruel import pmt # # This hack forces a 'has-a' relationship to look like an 'is-a' one. # # It allows Python classes to subclass this one, while passing through # method calls to the C++ class shared pointer from SWIG. # # It also allows us to intercept method calls if needed # class hier_block2(object): """ Python wrapper around the C++ hierarchical block implementation. Provides convenience functions and allows proper Python subclassing. """ def __init__(self, name, input_signature, output_signature): """ Create a hierarchical block with a given name and I/O signatures. """ self._hb = hier_block2_swig(name, input_signature, output_signature) def __getattr__(self, name): """ Pass-through member requests to the C++ object. """ if not hasattr(self, "_hb"): raise RuntimeError("hier_block2: invalid state--did you forget to call gr.hier_block2.__init__ in a derived class?") return getattr(self._hb, name) def connect(self, *points): """ Connect two or more block endpoints. An endpoint is either a (block, port) tuple or a block instance. In the latter case, the port number is assumed to be zero. To connect the hierarchical block external inputs or outputs to internal block inputs or outputs, use 'self' in the connect call. If multiple arguments are provided, connect will attempt to wire them in series, interpreting the endpoints as inputs or outputs as appropriate. """ if len (points) < 1: raise ValueError, ("connect requires at least one endpoint; %d provided." % (len (points),)) else: if len(points) == 1: self._hb.primitive_connect(points[0].to_basic_block()) else: for i in range (1, len (points)): self._connect(points[i-1], points[i]) def _connect(self, src, dst): (src_block, src_port) = self._coerce_endpoint(src) (dst_block, dst_port) = self._coerce_endpoint(dst) self._hb.primitive_connect(src_block.to_basic_block(), src_port, dst_block.to_basic_block(), dst_port) def _coerce_endpoint(self, endp): if hasattr(endp, 'to_basic_block'): return (endp, 0) else: if hasattr(endp, "__getitem__") and len(endp) == 2: return endp # Assume user put (block, port) else: raise ValueError("unable to coerce endpoint") def disconnect(self, *points): """ Disconnect two endpoints in the flowgraph. To disconnect the hierarchical block external inputs or outputs to internal block inputs or outputs, use 'self' in the connect call. If more than two arguments are provided, they are disconnected successively. """ if len (points) < 1: raise ValueError, ("disconnect requires at least one endpoint; %d provided." % (len (points),)) else: if len (points) == 1: self._hb.primitive_disconnect(points[0].to_basic_block()) else: for i in range (1, len (points)): self._disconnect(points[i-1], points[i]) def _disconnect(self, src, dst): (src_block, src_port) = self._coerce_endpoint(src) (dst_block, dst_port) = self._coerce_endpoint(dst) self._hb.primitive_disconnect(src_block.to_basic_block(), src_port, dst_block.to_basic_block(), dst_port) def msg_connect(self, src, srcport, dst, dstport): self.pri
Re: AttributeError: 'gr_hier_block2_sptr' object has no attribute 'set_callback'
On 02/14/2013 04:16 PM, md...@nycap.rr.com wrote: I am using ubuntu 12.10 and python version 2.7.3. i run the following command in terminal: def connect(self, *points): """ Connect two or more block endpoints. An endpoint is either a (block, port) tuple or a block instance. In the latter case, the port number is assumed to be zero. To connect the hierarchical block external inputs or outputs to internal block inputs or outputs, use 'self' in the connect call. If multiple arguments are provided, connect will attempt to wire them in series, interpreting the endpoints as inputs or outputs as appropriate. """ if len (points) < 1: raise ValueError, ("connect requires at least one endpoint; %d provided." % (len (points),)) else: if len(points) == 1: self._hb.primitive_connect(points[0].to_basic_block()) else: for i in range (1, len (points)): self._connect(points[i-1], points[i]) def _connect(self, src, dst): (src_block, src_port) = self._coerce_endpoint(src) (dst_block, dst_port) = self._coerce_endpoint(dst) self._hb.primitive_connect(src_block.to_basic_block(), src_port, dst_block.to_basic_block(), dst_port) For those of us using text-based email, the program in this message is totally unreadable. This is a text mailing-list, so please put your email program in text mode, or you'll lose much of your audience. Why are you showing us the source to a file from gnuradio library module, instead of your own code? -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Python trademark under attack -- the PSF needs your help
Hello all, The Python Software Foundation is the organisation which protects and manages the "boring" bits of keeping a big open source project alive: the legal and contractual parts, funding for projects, trademarks and copyrights. If you are based in Europe, or know somebody who uses Python in Europe, the PSF needs your help. There is a company in the UK who has applied to trademark the name "Python" and are claiming the *exclusive* right to use the word "Python" for software, servers, and web services over the entire European Union. You can read more about this here: http://pyfound.blogspot.com/2013/02/python-trademark-at-risk-in-europe-we.html If you have documentation of European user groups, trade associations, books, conferences, scans of job advertisements for Python programmers, software that uses some variation of "Python" in the name, etc. your evidence will be helpful in defeating this attempted grab of the Python name. You can also testify to the fact that when you read or hear of the name "Python" in relation to computers and the Internet, you think of Python the programming language. Thank you. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested feature: slice syntax within tuples (or even more generally)?
On Thursday, February 14, 2013 1:58:06 PM UTC-5, Ian wrote: > > That's not ambiguous, because the former is simply invalid syntax. > > However, consider the following. > > > > if 1: 2: > > > > That could be either a one-line if statement where the condition is 1 > > and the body is slice(2, None), or it could be the beginning of a > > multi-line if block where the condition is slice(1, 2). If the parser > > sees that, should it expect the next line to be indented or not? If > > it relies on indentation to determine this, then it loses some ability > > to warn the user of incorrect indentation. > > > > Then we have dictionary literals: > > > > {1:2:3} > > > > Should that be read as dict([(slice(1, 2), 3)]) or dict([(1, slice(2, > > 3))])? Or even set([slice(1, 2, 3)])? > Restricting this to within the top level of ()-enclosed expressions would be sufficient to eliminate all ambiguities, though, right? Basically all that needs to change is for expressions within '()' to be parsed identically as are currently parsed in '[]'. -Stephen -- http://mail.python.org/mailman/listinfo/python-list
Re: First attempt at a Python prog (Chess)
On 2013-02-14 21:14:03 +, jkn said: Hi Chris On Wednesday, 13 February 2013 23:25:09 UTC, Chris Hinsley wrote: New to Python, which I really like BTW. Welcome aboard! But aren't you supposed to be writing Forth? ;-) Cheers Jon N Well, I'm experimenting with other things too ! :) I might yet even have another bash at Lisp... Chris -- http://mail.python.org/mailman/listinfo/python-list
[ANN] pypiserver 1.1.0 - minimal private pypi server
Hi, I've just uploaded pypiserver 1.1.0 to the python package index. pypiserver is a minimal PyPI compatible server. It can be used to serve a set of packages and eggs to easy_install or pip. pypiserver is easy to install (i.e. just 'pip install pypiserver'). It doesn't have any external dependencies. http://pypi.python.org/pypi/pypiserver/ should contain enough information to easily get you started running your own PyPI server in a few minutes. The code is available on github: https://github.com/schmir/pypiserver Changes in version 1.1.0 - implement multi-root support (one can now specify multiple package roots) - normalize pkgnames, handle underscore like minus - sort files by their version, not alphabetically - upgrade embedded bottle to 0.11.6 - upgrade waitress to 0.8.2 in the standalone script - merge vsajip's support for verify, doc_upload and remove_pkg -- Cheers Ralf -- http://mail.python.org/mailman/listinfo/python-list
Re: AttributeError: 'gr_hier_block2_sptr' object has no attribute 'set_callback'
On Thu, Feb 14, 2013, at 04:39 PM, Dave Angel wrote: [... snip] > For those of us using text-based email, the program in this message is > totally unreadable. This is a text mailing-list, so please put your > email program in text mode, or you'll lose much of your audience. For those of us not using not using text-based email, it looked just as bad (if not worse). -- http://mail.python.org/mailman/listinfo/python-list
How would you do this?
I want to make a guess the number game (Which i have), but i want to make the computer play the game against itself. How would i do this? -- http://mail.python.org/mailman/listinfo/python-list
Re: How would you do this?
On 14 February 2013 23:34, eli m wrote: > I want to make a guess the number game (Which i have), but i want to make the > computer play the game against itself. How would i do this? Your question would make more sense if you would show your program and also explain how you would like the output to look when the computer played itself. Oscar -- http://mail.python.org/mailman/listinfo/python-list
Re: Awsome Python - chained exceptions
On Feb 14, 5:00 pm, Ian Kelly wrote: > 2. If you're going to criticize someone for their spelling, at least > be sure to spell correctly the name of the person you are addressing. > You've consistently misspelled Steven's surname in several posts that > I've noticed. The correct spelling conflicts with his intuition of how it should be spelled. Expect a DeApranoWart post any day now. -- http://mail.python.org/mailman/listinfo/python-list
Re: How would you do this?
On Thursday, February 14, 2013 4:09:37 PM UTC-8, Oscar Benjamin wrote: > On 14 February 2013 23:34, eli m wrote: > > > I want to make a guess the number game (Which i have), but i want to make > > the computer play the game against itself. How would i do this? > > > > Your question would make more sense if you would show your program and > > also explain how you would like the output to look when the computer > > played itself. > > > > > > Oscar This is my code: #Guess the number game import random run = 0 while run == 0: print ("I am thinking of a number between 1 and 100") num = random.randint(1, 100) num = int(num) guesses = 0 guessestaken = 0 while guesses == 0: try: guess = raw_input("Your guess:") guess = int(guess) guessestaken = (guessestaken) + 1 guessestaken = int(guessestaken) if guess == (num): print 'Correct! It took you', int(guessestaken), 'guesses!' playagain = raw_input("Do you want to play again?") if playagain == "yes": guesses = 1 if playagain == "no": run = 1 if guess > num: print ("My number is lower") if guess < num: print ("My number is higher") except TypeError, err: print ("Not a valid number") I would like it to show the computer guessing the numbers. -- http://mail.python.org/mailman/listinfo/python-list
Re:Re: how to right the regular expression ?
the regex--- pat = r'([a-z].+?\s)(.+)(?:(\(.+\)))?' ,do not work at all. >>> rfile.close() >>> import re >>> rfile=open("tv.txt","r") >>> pat1 = r'([a-z].+?\s)(.+)((\(.+\)))?' >>> for line in rfile.readlines(): ... Match=re.match(pat1,line) ... print "1group is ",Match.group(1),"2group is ",Match.group(2),"3group is ",Match.group(3) ... 1group is http://202.177.192.119/radio5 2group is 香港电台第五台(可于Totem/VLC/MPlayer播放) 3group is None 1group is http://202.177.192.119/radio35 2group is 香港电台第五台(DAB版,可于Totem/VLC/MPlayer播放) 3group is None 1group is http://202.177.192.119/radiopth 2group is 香港电台普通话台(可于Totem/VLC/MPlayer播放) 3group is None 1group is http://202.177.192.119/radio31 2group is 香港电台普通话台(DAB版,可于Totem/VLC/MPlayer播放) 3group is None 1group is octoshape:rthk.ch1 2group is 香港电台第一台(粤) 3group is None 1group is octoshape:rthk.ch2 2group is 香港电台第二台(粤) 3group is None 1group is octoshape:rthk.ch6 2group is 香港电台普通话台 3group is None 1group is octoshape:rthk.ch3 2group is 香港电台第三台(英) 3group is None >>> rfile.close() >>> import re >>> rfile=open("tv.txt","r") >>> pat2 = r'([a-z].+?\s)(.+?)((\(.+\)))?' >>> for line in rfile.readlines(): ... Match=re.match(pat1,line) ... print "1group is ",Match.group(1),"2group is ",Match.group(2),"3group is ",Match.group(3) ... 1group is http://202.177.192.119/radio5 2group is 香港电台第五台(可于Totem/VLC/MPlayer播放) 3group is None 1group is http://202.177.192.119/radio35 2group is 香港电台第五台(DAB版,可于Totem/VLC/MPlayer播放) 3group is None 1group is http://202.177.192.119/radiopth 2group is 香港电台普通话台(可于Totem/VLC/MPlayer播放) 3group is None 1group is http://202.177.192.119/radio31 2group is 香港电台普通话台(DAB版,可于Totem/VLC/MPlayer播放) 3group is None 1group is octoshape:rthk.ch1 2group is 香港电台第一台(粤) 3group is None 1group is octoshape:rthk.ch2 2group is 香港电台第二台(粤) 3group is None 1group is octoshape:rthk.ch6 2group is 香港电台普通话台 3group is None 1group is octoshape:rthk.ch3 2group is 香港电台第三台(英) 3group is None 在 2013-02-14 23:43:42,MRAB 写道: >On 2013-02-14 14:13, python wrote: >> my tv.txt is : >> http://202.177.192.119/radio5 香港电台第五台(可于Totem/VLC/MPlayer播放) >> http://202.177.192.119/radio35 香港电台第五台(DAB版,可于Totem/VLC/MPlayer播放) >> http://202.177.192.119/radiopth 香港电台普通话台(可于Totem/VLC/MPlayer播放) >> http://202.177.192.119/radio31 香港电台普通话台(DAB版,可于Totem/VLC/MPlayer播放) >> octoshape:rthk.ch1 香港电台第一台(粤) >> octoshape:rthk.ch2 香港电台第二台(粤) >> octoshape:rthk.ch6 香港电台普通话台 >> octoshape:rthk.ch3 香港电台第三台(英) >> >> what i want to get the result is >> 1group is http://202.177.192.119/radio5 2group is 香港电台第五台 3group is >> (可于Totem/VLC/MPlayer播放) >> 1group is http://202.177.192.119/radio35 2group is 香港电台第五台 3group is >> (DAB版,可于Totem/VLC/MPlayer播放) >> 1group is http://202.177.192.119/radiopth 2group is 香港电台普通话台 3group is >> (可于Totem/VLC/MPlayer播放) >> 1group is http://202.177.192.119/radio31 2group is 香港电台普通话台 3group is >> (DAB版,可于Totem/VLC/MPlayer播放) >> 1group is octoshape:rthk.ch1 2group is 香港电台第一台 3group is (粤) >> 1group is octoshape:rthk.ch2 2group is 香港电台第二台 3group is (粤) >> 1group is octoshape:rthk.ch6 2group is 香港电台普通话台 3group is none >> 1group is octoshape:rthk.ch3 2group is 香港电台第三台 3group is (英) > > >> here is my code: >> # -*- coding: utf-8 -*- >> import re >> rfile=open("tv.txt","r") >> pat=r'([a-z].+?\s)(.+)(\(.+\))' >> for line in rfile.readlines(): >> Match=re.match(pat,line) >> print "1group is ",Match.group(1),"2group is >> ",Match.group(2),"3group is ",Match.group(3) >> rfile.close() >> >> the output is : >> 1group is http://202.177.192.119/radio5 2group is 香港电台第五台 >> 3group is (可于Totem/VLC/MPlayer播放) >> 1group is http://202.177.192.119/radio35 2group is 香港电台第五台 >> 3group is (DAB版,可于Totem/VLC/MPlayer播放) >> 1group is http://202.177.192.119/radiopth 2group is 香港电台普通话台 >> 3group is (可于Totem/VLC/MPlayer播放) >> 1group is http://202.177.192.119/radio31 2group is 香港电台普通话台 >> 3group is (DAB版,可于Totem/VLC/MPlayer播放) >> 1group is octoshape:rthk.ch1 2group is 香港电台第一台 3group is (粤) >> 1group is octoshape:rthk.ch2 2group is 香港电台第二台 3group is (粤) >> 1group is >> Traceback (most recent call last): >>File "tv.py", line 7, in >> print "1group is ",Match.group(1),"2group is ",Match.group(2),"3group >> is ",Match.group(3) >> AttributeError: 'NoneType' object has no attribute 'group' >> >> how to revise my code to get the output? >> >The problem is that the regex makes '(\(.+\))' mandatory, but example 7 >doesn't match it. > >You can make it optional by wrapping it in a non-capturing group >(?:...), like this: > >pat = r'([a-z].+?\s)(.+)(?:(\(.+\)))?' > >Also, it's highly recommended that you use raw string literals >(r'...') when writing regex patterns and replacements. > >-- >http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: how to right the regular expression ?
On 2013-02-15 00:32, python wrote: the regex--- pat = r'([a-z].+?\s)(.+?)((\(.+\)))?$' ,do not work at all. [snip] Sorry, that should be: pat1 = r'([a-z].+?\s)(.+?)((\(.+\)))?$' Group 2 should've been lazy "(.+?)", and because of that it should've forced matching the end of the line with "$". -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested feature: slice syntax within tuples (or even more generally)?
On Thursday, February 14, 2013 4:01:39 PM UTC-6, steph...@gmail.com wrote: > On Thursday, February 14, 2013 1:58:06 PM UTC-5, Ian wrote: > > [snip: quote noise!] > Dude! Please trim this quote noise from your posts. I know Google's quoting mechanism is buggy, but dammit man YOU'RE A PROGRAMER! There is no excuse for not trimming excessive newlines. As to your slicing request. Anybody who knows me KNOWS that i love consistency! So i'm all for applying a slicing syntax consistently, however, i don't think your approach is the correct approach. To get you going in the correct direction: Ruby uses the "s..e" and "s...e" (where "s" represents the start of the range and "e" represents the end of a range) as syntactic sugar for Range.new(s, e). Two dots create an /inclusive/ range and three dots create an /exclusive/ range. Anyway, enough tutorials, read the doc: http://www.ruby-doc.org/core-1.9.3/Range.html Now, i am not suggesting that python should adopt the /exact/ syntax of Ruby, however, i /am/ suggesting that Ruby is more consistent with the range object than Python. In Ruby: ...you can slice arrays with the range: rb> a = [1,2,3,4,5] rb> a[0..-1] [1,2,3,4,5] rb> a[0...-1] [1,2,3,4] ...you can create a range of integers : rb> r = 1..10 rb> r.to_a() [1,2,3,4,5,6,7,8,9] ...you can create a range of chars: rb> r = "a".."d" rb> r.to_a() ["a", "b", "c", "d"] ...you can use range in a loop: rb> for x in 0...5;puts "#{x}th iteration";end 0th iteration 1th iteration 2th iteration 3th iteration 4th iteration ...but most importantly, you can do all these things in a consistent manner using a consistent syntax! Python however has the stupid slice function and then sequence indexing, and no consistency between the two! Plus, the for loop uses the range function to create "lazy iterators" instead of employing a consistent "range" syntax. Consistent syntax and consistent application are the biggest issues with Python ranges as they exist today. That's the starting point. -- http://mail.python.org/mailman/listinfo/python-list
Re: any chance for contracts and invariants in Python?
See the python extension called "Vigil": https://github.com/munificent/vigil . mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Awsome Python - chained exceptions
On Thursday, February 14, 2013 6:01:51 AM UTC-6, Ulrich Eckhardt wrote: > [...] > > try: > rrick.go_and_[edit]_yourself() > finally: > rrick.get_lost() Oops, you forgot to catch "FloatingPointError" and so your code choked in the try block -- typical newbie mistake. -- http://mail.python.org/mailman/listinfo/python-list
Re: First attempt at a Python prog (Chess)
On Thursday, February 14, 2013 11:48:10 AM UTC-6, Chris Hinsley wrote: > Is a Python list as fast as a bytearray? Why would you care about that now? Are you running this code on the Xerox Alto? Excuse me for the sarcasm but your post title has perplexed me: "First attempt at a Python prog (Chess)" Okay, but how does that translate to: "The fastest, most efficient, most brain fricked python code ever released in the form of a game, that just happens to look an awful lot like C source"? http://en.wikipedia.org/wiki/Optimization_%28computer_science%29#When_to_optimize Why bother to use Python if what you really want to write is C code? If you want to write good code (not just python), you need to write code that is maintainable. Yes i KNOW, this is just some stupid chess game, but i can assure you that this style of code is only going to harm your evolution. This code is obfuscated at best and BF'ed at worst. And forget about the algorithms for now, the first problems to address are superficial. First of all your naming conventions suck. You've used the "interface" style for every function in this game so i can't /easily/ eyeball parse the /real/ interface functions from the helper functions -- and i'm not going to even try, because i don't read ugly code! Try to learn the Python style guide as soon as you can (In particular pay attention to naming conventions): http://www.python.org/dev/peps/pep-0008/ Secondly this game could benefit from some OOP paradigm (not sure if are familiar with OOP or not???). But don't go bat-crazy with OOP! You don't need an object to represent /every/ single piece on the board (That would be nuts!). You need just enough OOP to encapsulate the data and create a proper interface. A good litmus test is based on the "three little bears": "Papa bears bed is too hard" A hard utilization of paradigms wields too little OOP and therefore ends up being too difficult (aka: "hard") to maintain because there is no logical interface; just a massive collection of functions stuffed into global space until BF reaches critical mass and you're forced to do a complete re-write! (Of course sometimes you don't need OOP at all, just interface) "Mama bears bed is too soft" A soft utilization of paradigms wields too much OOP whereby you are surrounded by big FAT objects which are smothering you to death, and they smell because they cannot properly wash themselves between the rolls of fat. "but baby bears is just right" Ahhh, the blissful comfort of a paradigm utilization that is "just right". This is where your code should be, you want a level of OOP usage that is "just right" for the occasion; not any more, not any less. ## START EXAMPLE CODE ## class GameBoard(???): def __init__(self): self.board = self._createBoard() def __str__(self): """Override:""" # return a string represention of the board # suitable for writing to stdout def _createBoard(self): """Internal:""" self.board = [blah] def make_move(self, piece, vector): """Interface: move a game piece based on vector""" # Find and move the piece. Whether the pieces # are objects or not doesn't matter. class GamePiece(object): def __init__(self, typename, color): self.typeName = typeName self.color = color self.captureFlag = self._computeFlag() def main(): board = Board() playing = True while playing is not False i = input('PieceName - MoveVec:') n, v = parse(i) result = board.make_move(n, v) if result == 'GameOver': playing = False else: # clear the stdout str(board) if __name__ == '__main__: main() ## END EXAMPLE CODE ## And now you have the added benefit of exporting the objects for use elsewhere. -- http://mail.python.org/mailman/listinfo/python-list
Re: Awsome Python - chained exceptions
On Fri, Feb 15, 2013 at 1:56 PM, Rick Johnson wrote: > On Thursday, February 14, 2013 6:01:51 AM UTC-6, Ulrich Eckhardt wrote: >> [...] >> >> try: >> rrick.go_and_[edit]_yourself() >> finally: >> rrick.get_lost() > > Oops, you forgot to catch "FloatingPointError" and so your code choked in the > try block -- typical newbie mistake. And yet it is still a perfect example of how a line of code inside a 'try' block can indeed be offensive. This has nothing to do with exceptions, and everything to do with societal practices and acceptable language. The fact that you edited it out of your quote shows just how offensive the expression is. :) May I ring your schoolbell? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Lib to generate XML/JSON[P] output from a DTD/XSD/JSON Schema/etc
Acácio Centeno writes: > Hi, I've searched both this group and the web but was unable to find an > answer, sorry if it has already been answered, it seems such a common problem > that I am sure someone has asked before. > > We have a WebServices platform that must reply in XML, JSON, or JSONP. Having > to convert between these formats is a really pain in the neck. > > What I would like to do is, given some schema representation, that could be a > DTD, XSD or whatever and a python dictionary with the values for each node, > generate the output in either XML, JSON or JSONP. You could have a look at the PyPI packages "dm.zope.rpc" and "dm.zope.rpc.wsdl_suds". They provide a middleware to support protocol independent web services (for the "Zope" application server). Together, they support XML-RPC, JSON-RPC and WSDL decribed SOAP web services. As you are likely not using Zope, you probably cannot use these packages directly but you may get some ideas how to create such a middleware for your web framework. Python (from 2.6 on) has "json" support. Thus converting a dict to "json" is simple ("json.dumps"). "dm.zope.rpc.wsdl_suds" abuses "suds" to parse the WSDL and generate appropriate SOAP responses from a dict. Alternatively, you might use "PyXB" for that. You could also have a look at "Spyne" (formerly known (among others) as "rpclib"). I think (but am not sure) that it targets your use case for the "twisted" environment. -- http://mail.python.org/mailman/listinfo/python-list
Re: Awsome Python - chained exceptions
On Friday, February 15, 2013 12:18:17 AM UTC-6, Chris Angelico wrote: > And yet it is still a perfect example of how a line of > code inside a 'try' block can indeed be offensive. Oh nice try, but we are not fooled by your straw-man. My exact statement that provoked this whole thing was: """ Q1: How could a line in the "try" block ever be considered offensive? Because it throws an error? Are you serious? """ If you notice, the first sentence is rhetorical. "How could a line in the "try" block ever be considered offensive?" My suggestion of "offensive" does not imply ignorance on /my/ part, but it does not necessarily imply ignorance on your part either. Then, in the second sentence, I offer a possible answer to the first question in the form of another question (asked on your behalf): "Because it throws and error?" Then in my last sentence, i ask another question (in a sarcastic manner) that negates the answer you might have given, "Are you serious?" This negation means that /i/ do not find ANY line in a try block to be "offensive". In effect, you could reduce the paragraph to this: "A line of code in the try block that throws an error is NOT offensive (to me)." As you can see from this break-down, /i/ never suggested that ANY line in ANY block was "offensive", it was /you/ (by proxy) who suggested it. Now ain't that just a pickle! ;-). > This has nothing to do with exceptions, and everything to > do with societal practices and acceptable language. But "offensive" is very subjective my friend! I curse quite frequently (especially when i am frustrated). To me, words are merely expressions, and when i'm angry i will express myself accordingly. However, there are many people who cannot deal with the feelings and images that they experience when hearing certain words. And a good argument could be made for "limiting strong emotional expressions in the company of strangers" -- even /if/ for nothing more than "good manners". It was for the later reason that i edited this word. And besides, i could toss out curse words all day if my only intent was to sensationalize the moment for the sake of a few rubber-neckers. Anybody can employ the curse for quick attention of fellow fools, however, /real/ intelligence is required to draw a witty abstract relationship between two superficially unrelated entities or ideas (especially when one entity is tangible and the other is intangible). > The fact that you edited it out of your quote shows just > how offensive the expression is. :) So you present "a curse word that i edited" versus "a rhetorical question i made on your behalf", and you claim to have defeated me? Ha, classic straw-man! > May I ring your schoolbell? Sure, but only if you use your head as the hammer. -- http://mail.python.org/mailman/listinfo/python-list