Eclipse, C, and Python
Hello Forum. I have installed Python comnpiler in Eclipse Classic for Windows. After a while I have installed the C compiler. However, somehow now when I try to run my code in Python it shows me for default Ant Run -->Ant Build I switched my workspace but still. Do you know how to solve this?.. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Distribution
Hi all, I am doing a simulation project using Python. In my project, I want to use some short of distribution to generate requests to a server. The request should have two distributions. One for request arrival rate (should be poisson) and another for request mix (i.e. out of the total requests defined in request arrival rate, how many requests are of which type). Example: Suppose the request rate is - 90 req/sec (generated using poisson distribution) at time t and we have 3 types of requests (i.e. r1, r2, r2). The request mix distribution output should be similar to: {r1 : 50 , r2 : 30 , r3 : 10} (i.e. out of 90 requests - 50 are of r1 type, 30 are of r2 type and 10 are of r3 type). As I an new to python distribution module, I am not getting how to code this situation. Please help me out for the same. Thanks in advance Prince -- http://mail.python.org/mailman/listinfo/python-list
Re: s_push parser stack overflow
On 20/03/2012 03:19, Артём Назаров wrote: Hi. Sorry of my english :-) code: print (((0)))" message from python is: s_push parser stack overflow Can i configure phyton to solve this problem without change MAXSTACK in " parser.c" and re-build the python? A quick look at parser.h tells me that it's a hard-coded limit: typedef struct { stackentry *s_top; /* Top entry */ stackentry s_base[MAXSTACK];/* Array of stack entries */ /* NB The stack grows down */ } stack; -- http://mail.python.org/mailman/listinfo/python-list
s_push parser stack overflow
Hi. Sorry of my english :-) code: print (((0)))" message from python is: s_push parser stack overflow Can i configure phyton to solve this problem without change MAXSTACK in " parser.c" and re-build the python? -- http://mail.python.org/mailman/listinfo/python-list
Re: Currying in Python
On 3/20/2012 0:20, Ian Kelly wrote: I hope you don't mind if I critique your code a bit! Not at all. Thank you for your time. On Fri, Mar 16, 2012 at 7:21 PM, Kiuhnm wrote: Here we go. ---> def genCur(f, unique = True, minArgs = -1): [...] I'll update my code following your corrections, but will keep "curr" :) Kiuhnm -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib.urlretrieve never returns???
On Mon, 19 Mar 2012 20:32:03 +0100, Laszlo Nagy wrote: > The pythonw.exe may not have the rights to access network resources. >>> Have you set a default timeout for sockets? >>> >>> import socket >>> socket.setdefaulttimeout(10) # 10 seconds > I have added pythonw.exe to allowed exceptions. Disabled firewall > completely. Set socket timeout to 10 seconds. Still nothing. > > urllib.urlretrieve does not return from call > > any other ideas? I'm sorry if I have missed something, or making suggestions you have already tried, but your original post describing the problem is missing from my news server. I gather you are running urlretrieve in a separate thread, inside a GUI? I have learned that whenever I have inexplicable behaviour in a function, I should check my assumptions. In this case, (1) are you sure you have the right urlretrieve, and (2) are you sure that your self.Log() method is working correctly? Just before the problematic call, do this: # was: fpath = urllib.urlretrieve(imgurl)[0] # becomes: print(urllib.__file__, urlretrieve) self.Log(urllib.__file__, urlretrieve) fpath = urllib.urlretrieve(imgurl)[0] and ensure that you haven't accidentally shadowed them with something unexpected. Does the output printed to the console match the output logged? What happens if you take the call to urlretrieve out of the thread and call it by hand? Run urllib.urlretrieve(imgurl) directly in the interactive interpreter. Does it still hang forever? When you say it "never" returns, do you mean *never* or do you mean "I gave up waiting after five minutes"? What happens if you leave it to run all day? Perhaps it returns after e.g. seven hours, which would be a mystery in itself, but at least you have perturbed the problem and have another data point. Maybe it isn't dead, just really slow. How big are the files you are trying to retrieve? Try retrieving a really small file. Then try retrieving a non-existent file. What happens if you call urlretrieve with a reporthook argument? Does it print anything? What happens if you try to browse to imgurl in your web browser? Are you sure the problem is with urlretrieve and not the source? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Currying in Python
I hope you don't mind if I critique your code a bit! On Fri, Mar 16, 2012 at 7:21 PM, Kiuhnm wrote: > Here we go. > > ---> > def genCur(f, unique = True, minArgs = -1): It is customary in Python for unsupplied arguments with no default to use the value None, not -1. That's what it exists for. > """ Generates a 'curried' version of a function. """ > def geng(curArgs, curKwargs): > def g(*args, **kwargs): > nonlocal f, curArgs, curKwargs, minArgs; # our STATIC data > > if len(args) or len(kwargs): Collections evaluate as true if they are not empty, so this could just be: if args or kwargs: > # Allocates data for the next 'g'. We don't want to modify our > # static data. > newArgs = curArgs[:]; > newKwargs = dict.copy(curKwargs); > > # Adds positional arguments. > newArgs += args; > > # Adds/updates keyword arguments. > if unique: > # We don't want repeated keyword arguments. > for k in kwargs.keys(): > if k in newKwargs: > raise(Exception("Repeated kw arg while unique = > True")); > newKwargs.update(kwargs); Since you're writing this for Python 3 (as evidenced by the use of the nonlocal keyword), you could take advantage here of the fact that Python 3 dictionary views behave like sets. Also, you should use a more specific exception type: if unique and not kwargs.keys().isdisjoint(newKwargs): raise ValueError("A repeated keyword argument was supplied") > # Checks whether it's time to evaluate f. > if minArgs >= 0 and minArgs <= len(newArgs) + len(newKwargs): With minArgs defaulting to None, that would be: if minArgs is not None and minArgs <= len(newArgs) + len(newKwargs): > return f(*newArgs, **newKwargs); # f has enough args > else: > return geng(newArgs, newKwargs); # f needs some more > args > else: > return f(*curArgs, **curKwargs); # the caller forced the > evaluation > return g; > return geng([], {}); > > def cur(f, minArgs = -1): > return genCur(f, True, minArgs); > > def curr(f, minArgs = -1): > return genCur(f, False, minArgs); The names "cur" and "curr" are terrible. Good names should describe what the function does without being too onerous to type, and the addition of the duplicate "r" is not an obvious mnemonic for remembering that the first one prohibits duplicate keyword arguments and the second one allows them. Why not more descriptive names like "curry" and "curry_unique"? That's all I've got. All in all, it's pretty decent for a Python newbie. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib.urlretrieve never returns???
On Monday, 19 March 2012 19:32:03 UTC, Laszlo Nagy wrote: > The pythonw.exe may not have the rights to access network resources. > >> Have you set a default timeout for sockets? > >> > >> import socket > >> socket.setdefaulttimeout(10) # 10 seconds > I have added pythonw.exe to allowed exceptions. Disabled firewall > completely. Set socket timeout to 10 seconds. Still nothing. > > urllib.urlretrieve does not return from call > > any other ideas? Maybe try using the reporthook option for urlretrieve, just to see if that does anything... If it constantly calls the hook or never calls it, that's one thing. Alternately, tcpdump/wireshark whatever, to see what the heck is going on with traffic - if any. hth Jon -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib.urlretrieve never returns???
The pythonw.exe may not have the rights to access network resources. Have you set a default timeout for sockets? import socket socket.setdefaulttimeout(10) # 10 seconds I have added pythonw.exe to allowed exceptions. Disabled firewall completely. Set socket timeout to 10 seconds. Still nothing. urllib.urlretrieve does not return from call any other ideas? -- http://mail.python.org/mailman/listinfo/python-list
Re: New learner of Python--any suggestion on studying it?
Hi, this might be of interest to you: http://www.udacity.com/overview/Course/cs101 All the best Wimm On 2012-03-19, yan xianming wrote: > Hello all, > > I'm a new learning of Python. > > > > Can someone give me some suggestion about it? > > thanks > xianming -- Wim. -- http://mail.python.org/mailman/listinfo/python-list
pypi and dependencies
When I publish something on Pypi, is there a way to make it fetch the list of dependencies needed by my project automatically? It would be nice to have it in the Pypi page, without having to look at the actual code.. Any other possible solution? -- http://mail.python.org/mailman/listinfo/python-list
Please recommend a open source for Python ACLs function
Hello Dear All: I would like to write some simple python test code with ACL(Access Control List) functions. Now simply I aim to use MAC address as ACL parameters, is there any good ACL open source recommended for using? Simple one is better. Any tips or suggestions welcomed and appreciated. Thank you. Kay -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
On Mon, 19 Mar 2012 12:44:53 +0100, Kiuhnm wrote: > On 3/18/2012 2:46, Steven D'Aprano wrote: >> On Sat, 17 Mar 2012 21:23:45 +0100, Kiuhnm wrote: >> >>> On 3/16/2012 14:03, Steven D'Aprano wrote: A one line routine is still a routine. There is nothing ungrammatical about "If you can: take the bus.", although it is non-idiomatic English. >>> >>> In another post you wrote >>> "Sorry, I was talking about the other sort, the ones who apply the >>> grammatical rules used by people in real life. You know the ones: >>> linguists." >>> >>> Then how do you know that there's nothing ungrammatical about "If you >>> can: take the bus" if people don't use it? >> >> Who says it is ungrammatical? > > You did. > You're not a prescriptivist, thus you're probably a descriptivist. > Beeing a descriptivist, you must agree on the fact that >"If ...: do this" > is ungrammatical, because nobody says that. I believe that you are misunderstanding the descriptivist position. There are many sentences which are never said, or perhaps only said once. Most non-trivial spoken or written sentences are unique. That doesn't make them wrong or erroneous because "nobody says them". Nobody says "hesitant teapots sleep artistically". It's a meaningless sentence, but it is grammatically correct: it obeys the same grammatical rule as "hungry dogs howl pitifully" or "devote saints suffer silently": ADJECTIVE NOUN VERB ADVERB. This pattern is common in English: nearly everyone uses it, and therefore any sentence matching the pattern is *grammatically* correct for English even if it is semantically meaningless. On the other hand, "pitifully dogs hungry howl" is incorrect because virtually no English speaker writes sentences using the rule ADVERB NOUN ADJECTIVE VERB, and on such rare times that somebody does, people will notice and declare that it is "wrong" or "doesn't make sense", or otherwise correct it. In my opinion, "If ...: do this" matches a grammatical pattern which I see very frequently. I've already given my reasons for this. > On the other hand, a > prescriptivist might accept that. BTW, I asked a few teachers of English > whether "If ...: do this" is correct or not and they, surprisingly, said > "no". What matters is not the authorities who say something is right or wrong, but their reasons for doing so. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: configobj validation
On 03/19/2012 12:59 PM, Andrea Crotti wrote: I seemed to remember that type validation and type conversion worked out of the box, but now I can't get it working anymore. Shouldn't this simple example actually fail the parsing (instead it parses perfectly port to a string)? sample.py: from configobj import ConfigObj conf = ConfigObj('sample.conf', configspec='sample.spec') sample.conf: port = some_string sample.spec: port = integer(0, 10) PS. using configobj 4.7.2 I now checked the repo and configobj seems also quite dead (2 years ago last version), it's a pity because it's a really nice library. Any other alternatives for validation/configuration systems otherwise? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
On 3/19/12 12:53 PM, Neil Cerutti wrote: I still think sentence fragments before a colon introducing a list often looks bad, and may be taken for an error. But it doesn't always look bad, and I didn't think about it enough. One of my English teachers suggested a rule that seems to accord (descriptively) with the uses the "look good" and "look bad" to me: don't use a colon to separate a transitive verb from its objects. -- 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 -- http://mail.python.org/mailman/listinfo/python-list
A debugging story.
I just spent two hours debugging a crucial, though fairly simple, program. As part of the processing of an admissions report, I use difflib to compare two csv files. I compare the current file with one from the immediate past. The file changes over time as new students are accepted, and current students change major and so forth. I next comb through the generated diff to find the actually changed fields, keeping a log of critical changes. I found I had not accounted for field names changing between runs of the admissions report, as recently happened when something had to be added to the report. I finally got it working and tested, and then was horrified when a slip of my finger caused me to have to revert to a previous version of the file from rcs. Two hours of work, down the bit-bucket! My horror abated when I found I was able to make the necessary changes again in roughly 30 seconds. This message brought to you by the Debugging is Mostly Comprehending Old Code and Testing Council. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
On Mon, 19 Mar 2012 15:33:51 +1100, Chris Angelico wrote: >> This is at least the second time you've alleged that assembly language >> is more readable than Python. I think you're a raving nutter, no >> offence Chris :-) > > None taken; guilty as charged. And unashamedly so. With that dealt with, > though: My calling assembly "readable" is a form of argument by drawing > to logical, but absurd, conclusion - by the given definition of > readability, assembly is readable, ergo the definition sucks. (That's a > term all logicians use, you know. Proper and formal jargon.) Which definition of readability are you using? Because I have given, if not a formal definition, at least a good explanation of what I consider to be the usual meaning of "readability" in the context of programming languages. I haven't seen anyone propose an alternative. Readability, as I see it, is a misnomer. What people actually mean by "Ruby is more readable than Forth" (say) is that Ruby is more comprehensible to some idealised non-expert reader. I also gave a list of characteristics of this idealised reader -- check the archives. I don't see how "assembly is readable" is the logical conclusion of my definition. It certainly is the logical conclusion if you make expert practitioners in the language as the judge of readability, but that's not my argument, that's yours. >> Assignment (name binding) is close to the absolute simplest thing you >> can do in a programming language. In Python, the syntax is intuitive to >> anyone who has gone through high school, or possibly even primary >> school, and been introduced to the equals sign. >> >> x = 1234 >> y = "Hello" > > Not quite. In mathematics, "x = 1234" is either a declaration of fact, > or a statement that can be either true or false. [snip differences between assignment and equality] Granted there are differences. Nevertheless, even mathematicians have a form of assignment, using almost the same notation many programming languages use: let c = 42 Sometimes the "let" is left out. The point is not that programming assignment and mathematical equality are identical, but that most people have been exposed to maths = in school and so can intuit the meaning of programming = . Admittedly not always *correctly* :) [...] >> Assembly has a very steep learning curve. Python has a shallow curve. > > Of course. But computer programming generally has a fairly stiff > learning curve; you have to get your head around all sorts of concepts > that simply do not exist anywhere else. Sure. That brings us to the perennial conflict between power/ expressibility versus readability/comprehensibility. Except for languages aimed purely as a teaching language for beginners, or perhaps an application scripting language, readability should not be the *only* aim in a language. The trick is to add as much power as you need without losing too much readability. The more powerful an abstraction or programming construct, the less non- experts will be able to intuit what it does. Or for that matter, the less likely they will be able to understand it even after explanations. I still have no idea what Haskell monads are. Contrariwise, the simpler and more comprehensible a tool is for non- experts, the less likely it will be interesting to experts. Either there will be too much syntactic sugar (e.g. "add 3 to x" instead of x += 3) or it simply won't do much ("x + 3" is understandable but not very interesting, and it doesn't help you talk to a database). Somewhere between those extremes of Forth and Hypertalk is a happy medium. It is my position that Python is somewhat closer to that peak than close neighbours like Ruby and Javascript, but I'm willing to accept that a certain amount of that is mere personal taste. Of course my personal taste is right and theirs is wrong. *wink* >> If all you have is a hammer, the instructions you get are easy to >> understand because there's not much you can do with it. How complicated >> can "hit the nail with the hammer" get? But the right measure is not >> the simplicity of the tasks you *can* do, but the comprehensibility of >> the tasks you *want* to do. > > Right, which is why NO language can be described as "readable" or "easy > to work with" unless you define a problem domain. SQL is an excellent > language... as long as you want to query a relational database. And so long as you stick to simple examples, it is relatively comprehensible: SELECT COLUMN2 FROM TABLE WHERE COLUMN1 = 42; But then you have stuff like this: SELECT * FROM ( SELECT RANK() OVER (ORDER BY age ASC) AS ranking, person_id, person_name, age FROM person ) foo WHERE ranking <= 10 Try asking your dear ol' granny to explain what that does. >> The measure of the readability of a language should not be obfuscated >> or badly written code, but good, idiomatic code written by an >> experienced practitioner in the art. Note that there is a delibera
Re: Message passing between python objects
J. Mwebaze wrote: > I am trying to learn about the interaction between python objects. One > thing i have often read is that objects interact by sending messages to > other objects to invoke corresponding methods. I am specifically > interested in tracing these messages and also probably log the messages > for further scrutiny. I would like to build a provenance kind of system. The term "message" occurs in various contexts in computing. You have probably encountered these http://en.wikipedia.org/wiki/Smalltalk#Messages http://en.wikipedia.org/wiki/Message_loop_in_Microsoft_Windows and are mixing the two meanings. However, methods in Python are ordinary functions that know about "their" instance. Given a = A() a.method(1, 2) and A.method(a, 1, 2) are equivalent, no animals are hurt and no messages passed. -- http://mail.python.org/mailman/listinfo/python-list
Re: New learner of Python--any suggestion on studying it?
On Mar 19, 2:30 am, yan xianming wrote: > Hello all, > > I'm a new learning of Python. > > Can someone give me some suggestion about it? > > thanks > xianming Once you have a few of the basics down (using the resources others have suggested), a good way to practice those skills is to visit Project Euler (http://projecteuler.net/) or The Python Challenge (http://www.pythonchallenge.com/). Project Euler is a site with math problems that can be best solved using basic programming skills. The first problem asks for the sum of all the multiples of 3 or 5 below 1000. The problems build in difficulty and in the programming skills you need. The Python Challenge (best completed using version 2.7 of Python) is hard to explain, but a lot of fun to do. Good luck! Brian -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: cmd2, an extenstion of cmd that parses its argument line
On Sunday 2012 March 18 22:11, anntzer@gmail.com wrote: > I would like to announce the first public release of cmd2, an extension of > the standard library's cmd with argument parsing, here: > https://github.com/anntzer/cmd2. There already is a cmd2 package at PyPI and has been for a long time. http://packages.python.org/cmd2/ -- I have seen the future and I am not in it. -- http://mail.python.org/mailman/listinfo/python-list
configobj validation
I seemed to remember that type validation and type conversion worked out of the box, but now I can't get it working anymore. Shouldn't this simple example actually fail the parsing (instead it parses perfectly port to a string)? sample.py: from configobj import ConfigObj conf = ConfigObj('sample.conf', configspec='sample.spec') sample.conf: port = some_string sample.spec: port = integer(0, 10) PS. using configobj 4.7.2 -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
On 2012-03-19, Steven D'Aprano wrote: > On Mon, 19 Mar 2012 11:26:10 +, Neil Cerutti wrote: > [...] >>> *A major style guide for general American writing and >>> publication: used by some as the 'Bible'. >> >> Thanks for the discussion and corrections. My apologies to >> Steven for pushing my apparnetly overly narrow view. There are >> plenty of valid use cases for a colon without an independent >> clause. > > No apology necessary, I like a good argument :) > > http://www.mindspring.com/~mfpatton/sketch.htm > > One observation that amuses me though... it seems to me that > the widespread practice of people writing colons following > sentence fragments isn't sufficient to convince you that this > is grammatical, but a self- declared authority prescribing it > as allowed is. That makes you a grammar prescriptivist :) There are certain uses of colon that are worse than others, in my mind. It's a matter of taste, and that's going to be impossible to find references for. My birthday cake had three kinds of frosting: chocolate, vanilla and raspberry. I checked only one reference before diving in (www.wsu.edu/~brians/errors/), but it's a guide that concentrates on presenting yourself well through widely acceptable grammar. It's not an exhaustive taxonomy of all valid usages. So I looked in the wrong place. I still think sentence fragments before a colon introducing a list often looks bad, and may be taken for an error. But it doesn't always look bad, and I didn't think about it enough. > We're-all-a-little-bit-prescriptivists-when-it-comes-to-grammar-ly y'rs, Yep: my clever usage is another's abomination. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Message passing between python objects
I am trying to learn about the interaction between python objects. One thing i have often read is that objects interact by sending messages to other objects to invoke corresponding methods. I am specifically interested in tracing these messages and also probably log the messages for further scrutiny. I would like to build a provenance kind of system. Regards -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
On Mon, 19 Mar 2012 12:15:07 +0100, Kiuhnm wrote: > On 3/18/2012 0:04, Michael Torrie wrote: >> On 03/17/2012 03:28 PM, Kiuhnm wrote: They are equally readable. The first one sets EAX to 3; the second displays all elements of x on the console. Assembly is readable on a very low level, but it's by nature verbose at a high level, and thus less readable (you can't eyeball a function and know exactly what it does, especially if that function spans more than a screenful of code). >>> >>> Welcome in the realm of trolling. >> >> Seems like you're the one trolling. > > At least I hope that ChrisA understood what I meant. I'll spell it out > for you trollmonger (is that even a word?): Sure, why not? A trollmonger would be someone who deals in the buying and selling of trolls. Presumably this would be meant figuratively, like an argument-monger (someone who starts and gets involved in arguments). > 1) I read Steve's posts but I found his answers inconsistent. I don't think they are, but I'm happy to either clarify or concede any points that are contradictory or inconsistent, if you tell me what they are. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
On Mon, 19 Mar 2012 11:26:10 +, Neil Cerutti wrote: [...] >> *A major style guide for general American writing and publication: used >> by some as the 'Bible'. > > Thanks for the discussion and corrections. My apologies to Steven for > pushing my apparnetly overly narrow view. There are plenty of valid use > cases for a colon without an independent clause. No apology necessary, I like a good argument :) http://www.mindspring.com/~mfpatton/sketch.htm One observation that amuses me though... it seems to me that the widespread practice of people writing colons following sentence fragments isn't sufficient to convince you that this is grammatical, but a self- declared authority prescribing it as allowed is. That makes you a grammar prescriptivist :) We're-all-a-little-bit-prescriptivists-when-it-comes-to-grammar-ly y'rs, -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
On 3/18/2012 2:46, Steven D'Aprano wrote: On Sat, 17 Mar 2012 21:23:45 +0100, Kiuhnm wrote: On 3/16/2012 14:03, Steven D'Aprano wrote: A one line routine is still a routine. There is nothing ungrammatical about "If you can: take the bus.", although it is non-idiomatic English. In another post you wrote "Sorry, I was talking about the other sort, the ones who apply the grammatical rules used by people in real life. You know the ones: linguists." Then how do you know that there's nothing ungrammatical about "If you can: take the bus" if people don't use it? Who says it is ungrammatical? You did. You're not a prescriptivist, thus you're probably a descriptivist. Beeing a descriptivist, you must agree on the fact that "If ...: do this" is ungrammatical, because nobody says that. On the other hand, a prescriptivist might accept that. BTW, I asked a few teachers of English whether "If ...: do this" is correct or not and they, surprisingly, said "no". Kiuhnm -- http://mail.python.org/mailman/listinfo/python-list
debugging ssl handshake failure
I have an HTTPS server written in python, based on ssl package. This application is running on 3 virtual machines which were created by clonning. The application works perfectly on 2 machines but on the third it doesn't. Instead of the normal "Server Hello" message it gives me an Alert Level: Fatal, Description: "Handshake failure" Anybody here has any idea what the problem could be? My main problem here is that I don't have any means to debug the problem. My next option is to look into ssl sources which I'm not really happy to do. Also anybody has any suggestion for debugging? Thanks, Ovidiu -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
On 3/18/2012 2:36, Steven D'Aprano wrote: On Sat, 17 Mar 2012 20:59:34 +0100, Kiuhnm wrote: Ok, so length and readability are orthogonal properties. Could you please explain to me in which way mov eax, 3 should be less readable than for i in x: print(i) ? "mov eax, 3" requires more domain-specific knowledge. It operates at a very low level, that of memory locations and bytes, rather than at a level which most people can reason about efficiently. English speakers would probably guess that "mov" was an abbreviation of "move", but what is being moved, and from where to where, for what purpose? They're also likely to flounder on the analogy of "moving" bytes. When you move a book from here to there, you leave a space in the row of books where there is no longer a book. (You might choose to move a second book into that gap, but first there is a gap.) But when you move bytes, you don't leave a gap. There are always bytes at every valid address. The average non-programmer is likely to have the wrong data model to understand what "mov eax, 3" does. In the second example, most English speakers would intuit that "print(i)" prints i, whatever i is. "for i in x" is more cryptic, but if it were written with less jargon-like names, such as "for item in list" or "for person in family" or similar, they would likely guess that it means to repeat the following instructions for each item in the set: "For each person at the table, place a plate, knife and fork." And even if the reader can't guess the meaning of the for-loop, it is a concept easy enough for most people to grasp given some explanations and examples. It's neither too low level (assembly language), nor too high level (monads, functors) but is at just the right level of abstraction versus concreteness for the average person to follow. Would you be so kind to give me your final definition of readability and /stick/ to it? You keep changing it every time I point out a flaw in it. Kiuhnm -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
On 2012-03-17, Terry Reedy wrote: > On 3/16/2012 9:08 AM, Neil Cerutti wrote: > >> A grammarian always uses complete sentence before a colon, even >> when introducing a list. > > The Chicago Manual of Style*, 13th edition, says "The colon is > used to mark a discontinuity of grammatical construction > greater than that indicated by the semicolon and less than that > indicated by the period." > > While most of the examples in that section have what would be a > complete sentence before the colon, not all do. Not in that > section is this, from the Table of Contents: "Documentation: > References, Notes, and Bibliographies". Here are a couple more > from their Library of Congress Cataloging in Publication data: > "Rev. ed. of: A manual of style." and "Bibliography: p.". And > in letters: "To:", "From:", and "Date:" > > *A major style guide for general American writing and > publication: used by some as the 'Bible'. Thanks for the discussion and corrections. My apologies to Steven for pushing my apparnetly overly narrow view. There are plenty of valid use cases for a colon without an independent clause. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
On 3/18/2012 0:04, Michael Torrie wrote: On 03/17/2012 03:28 PM, Kiuhnm wrote: They are equally readable. The first one sets EAX to 3; the second displays all elements of x on the console. Assembly is readable on a very low level, but it's by nature verbose at a high level, and thus less readable (you can't eyeball a function and know exactly what it does, especially if that function spans more than a screenful of code). Welcome in the realm of trolling. Seems like you're the one trolling. At least I hope that ChrisA understood what I meant. I'll spell it out for you trollmonger (is that even a word?): 1) I read Steve's posts but I found his answers inconsistent. 2) He accused me of misrepresenting his view and you called me a troll. 3) I suspect that you didn't follow the entire discussion or you'd have noticed the inconsistencies yourself... but I understand that calling someone you don't agree with a troll is easier. 4) ChrisA gave the right answer which was the point I was trying to make all along. 5) I could have said "I second that" or "I agree with you", but I thought that "Welcome to the realm of trolling" was more amusing. I thought that people who agree with me were supposed to be troll as well. But I should've consulted with you about that. Sorry. Kiuhnm -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct
On 3/19/2012 6:02, Dennis Lee Bieber wrote: On Mon, 19 Mar 2012 02:02:23 +0100, Kiuhnm declaimed the following in gmane.comp.python.general: Many ASM languages don't have structured control flow statements but only jmps, which are roughly equivalent to gotos. A good decompiler will need to analize the net of jmps and try to rewrite the code using structured control flow statements. The idea is to maximize readability, of course. Never met Sigma's Meta-Symbol Okay, the machine level code was limited to basic condition/jump... But a master of Meta-Symbol (I wasn't such -- not in a trimester college course) could create macros that would make it structured. You can do that in MASM (and others) as well. Kiuhnm -- http://mail.python.org/mailman/listinfo/python-list
Re: filter max from iterable for grouped element
On 19 Mrz., 09:45, Peter Otten <__pete...@web.de> wrote: > Christian wrote: > > as beginner in python , I struggle somewhat to filter out only the > > maximum in the values for and get hmax. > > h = {'abvjv': ('asyak', 0.9014230420411024), > > 'afqes': ('jarbm', 0.9327883839839753), > > 'aikdj': ('jarbm', 0.9503941616408824), > > 'ajbhn': ('jarbm', 0.9323583083061541), > > 'ajrje': ('jbhdj', 0.9825125732711598), > > 'anbrw': ('jarbm', 0.950801828672098)} > > > hmax = {'abvjv': ('asyak', 0.9014230420411024), > > 'ajrje': ('jbhdj', 0.9825125732711598), > > 'anbrw': ('jarbm', 0.950801828672098)} > > You can create an intermediate dict: > > >>> d = {} > >>> for k, (k2, v) in h.items(): > > ... d.setdefault(k2, []).append((v, k)) > ...>>> import pprint > >>> pprint.pprint(d) > > {'asyak': [(0.9014230420411024, 'abvjv')], > 'jarbm': [(0.9323583083061541, 'ajbhn'), > (0.950801828672098, 'anbrw'), > (0.9327883839839753, 'afqes'), > (0.9503941616408824, 'aikdj')], > 'jbhdj': [(0.9825125732711598, 'ajrje')]} > > Now find the maximum values: > > >>> for k, pairs in d.items(): > > ... v, k2 = max(pairs) > ... assert k2 not in hmax > ... hmax[k2] = k, v > ...>>> pprint.pprint(hmax) > > {'abvjv': ('asyak', 0.9014230420411024), > 'ajrje': ('jbhdj', 0.9825125732711598), > 'anbrw': ('jarbm', 0.950801828672098)} > > > Maybe it easier when i change the structure of h? > > Maybe. Here's one option: > > >>> pprint.pprint(data) > > [('jarbm', 0.9323583083061541, 'ajbhn'), > ('jarbm', 0.950801828672098, 'anbrw'), > ('jarbm', 0.9327883839839753, 'afqes'), > ('asyak', 0.9014230420411024, 'abvjv'), > ('jbhdj', 0.9825125732711598, 'ajrje'), > ('jarbm', 0.9503941616408824, 'aikdj')]>>> data.sort() > >>> from itertools import groupby > >>> def last(items): > > ... for item in items: pass > ... return item > ...>>> dmax = [last(group) for key, group in groupby(data, key=lambda item: > item[0])] > >>> pprint.pprint(dmax) > > [('asyak', 0.9014230420411024, 'abvjv'), > ('jarbm', 0.950801828672098, 'anbrw'), > ('jbhdj', 0.9825125732711598, 'ajrje')] Thanks a lot. -- http://mail.python.org/mailman/listinfo/python-list
Re: filter max from iterable for grouped element
Christian wrote: > as beginner in python , I struggle somewhat to filter out only the > maximum in the values for and get hmax. > h = {'abvjv': ('asyak', 0.9014230420411024), > 'afqes': ('jarbm', 0.9327883839839753), > 'aikdj': ('jarbm', 0.9503941616408824), > 'ajbhn': ('jarbm', 0.9323583083061541), > 'ajrje': ('jbhdj', 0.9825125732711598), > 'anbrw': ('jarbm', 0.950801828672098)} > > > hmax = {'abvjv': ('asyak', 0.9014230420411024), > 'ajrje': ('jbhdj', 0.9825125732711598), > 'anbrw': ('jarbm', 0.950801828672098)} You can create an intermediate dict: >>> d = {} >>> for k, (k2, v) in h.items(): ... d.setdefault(k2, []).append((v, k)) ... >>> import pprint >>> pprint.pprint(d) {'asyak': [(0.9014230420411024, 'abvjv')], 'jarbm': [(0.9323583083061541, 'ajbhn'), (0.950801828672098, 'anbrw'), (0.9327883839839753, 'afqes'), (0.9503941616408824, 'aikdj')], 'jbhdj': [(0.9825125732711598, 'ajrje')]} Now find the maximum values: >>> for k, pairs in d.items(): ... v, k2 = max(pairs) ... assert k2 not in hmax ... hmax[k2] = k, v ... >>> pprint.pprint(hmax) {'abvjv': ('asyak', 0.9014230420411024), 'ajrje': ('jbhdj', 0.9825125732711598), 'anbrw': ('jarbm', 0.950801828672098)} > Maybe it easier when i change the structure of h? Maybe. Here's one option: >>> pprint.pprint(data) [('jarbm', 0.9323583083061541, 'ajbhn'), ('jarbm', 0.950801828672098, 'anbrw'), ('jarbm', 0.9327883839839753, 'afqes'), ('asyak', 0.9014230420411024, 'abvjv'), ('jbhdj', 0.9825125732711598, 'ajrje'), ('jarbm', 0.9503941616408824, 'aikdj')] >>> data.sort() >>> from itertools import groupby >>> def last(items): ... for item in items: pass ... return item ... >>> dmax = [last(group) for key, group in groupby(data, key=lambda item: item[0])] >>> pprint.pprint(dmax) [('asyak', 0.9014230420411024, 'abvjv'), ('jarbm', 0.950801828672098, 'anbrw'), ('jbhdj', 0.9825125732711598, 'ajrje')] -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib.urlretrieve never returns???
On 2012-03-17 19:18, Christian Heimes wrote: Am 17.03.2012 15:13, schrieb Laszlo Nagy: See attached example code. I have a program that calls exactly the same code, and here is the strange thing about it: * Program is started as "start.py", e.g. with an open console. In this case, the program works! * Program is started as "start.pyw", e.g. with no open console under Windows 7 64bit - the program does not work! The pythonw.exe may not have the rights to access network resources. Have you set a default timeout for sockets? import socket socket.setdefaulttimeout(10) # 10 seconds A pyw Python doesn't have stdout, stderr or stdin. Any attempt to write to them (e.g. print statement, default exception logger) can cause an exception. Yes, that is why I started the app with wx.PySimpleApp(redirect=True) so stdout is redirected into a window. Unfortunately, nothing is logged. I'm going to turn off the firewall and start as admin today. That might be the solution. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: cmd2, an extenstion of cmd that parses its argument line
There already is a module named cmd2: http://pypi.python.org/pypi/cmd2 -- Devin On Mon, Mar 19, 2012 at 1:11 AM, wrote: > Dear all, > > I would like to announce the first public release of cmd2, an extension of > the standard library's cmd with argument parsing, here: > https://github.com/anntzer/cmd2. > > Cmd2 is an extension built around the excellent cmd module of the standard > library. Cmd allows one to build simple custom shells using ``do_*`` > methods, > taking care in particular of the REPL loop and the interactive help. > However, > no facility is given for parsing the argument line (do_* methods are > passed the > rest of the line as a single string argument). > > With Cmd2, ``do_*`` methods are type-annotated, either using Python 3's > function annotation syntax, or with an ad-hoc ``annotate`` decorator, > allowing > the dispatcher to parse the argument list for them. > > Antony Lee > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: New learner of Python--any suggestion on studying it?
On 19.3.2012 8:30, yan xianming wrote: Hello all, I'm a new learning of Python. Can someone give me some suggestion about it? thanks xianming The best textbooks on Python that I have come across are: Learning Python by Mark Lutz, O'Reilly, http://oreilly.com, ISBN 978-0-596-15806-4 Programming Python by Mark Lutz, O'Reilly, http://oreilly.com, ISBN 978-0-596-15810-1 regards, Antti "Andy" Ylikoski Helsinki, Finland, the EU -- http://mail.python.org/mailman/listinfo/python-list
filter max from iterable for grouped element
Hi, as beginner in python , I struggle somewhat to filter out only the maximum in the values for and get hmax. Maybe it easier when i change the structure of h? Many thanks in advance Christian h = {'abvjv': ('asyak', 0.9014230420411024), 'afqes': ('jarbm', 0.9327883839839753), 'aikdj': ('jarbm', 0.9503941616408824), 'ajbhn': ('jarbm', 0.9323583083061541), 'ajrje': ('jbhdj', 0.9825125732711598), 'anbrw': ('jarbm', 0.950801828672098)} hmax = {'abvjv': ('asyak', 0.9014230420411024), 'ajrje': ('jbhdj', 0.9825125732711598), 'anbrw': ('jarbm', 0.950801828672098)} -- http://mail.python.org/mailman/listinfo/python-list
Re: New learner of Python--any suggestion on studying it?
On Sun, Mar 18, 2012 at 11:30 PM, yan xianming wrote: > Hello all, > > I'm a new learning of Python. > > Can someone give me some suggestion about it? http://docs.python.org/tutorial/index.html http://wiki.python.org/moin/BeginnersGuide/NonProgrammers http://wiki.python.org/moin/BeginnersGuide/Programmers http://www.quora.com/How-can-I-learn-to-program-in-Python Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list