From hidura at gmail.com Fri Oct 1 00:33:36 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Fri, 01 Oct 2010 04:33:36 +0000 Subject: Problems with wsgi Python3 In-Reply-To: <90e6ba53b492f430e40491862e7a@google.com> Message-ID: Now, i' m sure that the system it's uploading the file but still it's give me empty the information. I am considerating 2 crazy solutions what i want to share with you for listen your opinions: 1) Consist in translate to Python2.5 the area what receives the request and execute the area what begin the process with Python3.1 and wait to the other finish with the processing to read a file in where the other part write the result. 2) It's less crazy than the 1 and consist in strip the cpEnv["wsgi.input"].read() and take the information and begin the reading line by line in order to insert the information in the corresponding areas. Waiting for your opinions and very happy with your help. Diego Hidalgo. On Sep 30, 2010 11:56pm, hidura at gmail.com wrote: > Ppl, thankyou Diez and Thomas for your answers i did it, but it present > me a problem with the solution what you give me Thomas this is the code: > ValueError: Invalid boundary in multipart form: '' > On Sep 30, 2010 6:16pm, hidura at gmail.com wrote: > > I still receive nothing, here it's the code of the form maybe there > it's the problem: > > > > > > > > > > > > > > > > > > On Sep 30, 2010 4:55pm, "Diez B. Roggisch" deets at web.de> wrote: > > > Thomas Jollans thomas at jollybox.de> writes: > > > > > > > > > > > > > On Thursday 30 September 2010, it occurred to hidura at gmail.com to > exclaim: > > > > > > >> What mean this > > > > > > >> -----------------------------743346150198628700241600224--\r? > > > > > > > > > > > > > > it looks like a MIME boundary. In this context most likely from a > > > > > > > multipart/form-data transmission. > > > > > > > > > > > > yep, as one can see in the headers below. > > > > > > > > > > > > Additonally, it looks to me as if the form you are submitting is > > > > > > empty. The content-length of just 61 matches barely the boundary. > > > > > > > > > > > > Use something like > > > > > > > > > > > > pdict = cgi.parse_header(environ["CONTENT_TYPE"])[1] > > > > > > cgi.parse_multipart(environ["wsgi.input"], pdict) > > > > > > > > > > > > to properly parse the request. But then of course actually upload > > > > > > something. > > > > > > > > > > > > Diez > > > > > > > > > > > > > > > > > > > > > > > > > >> > > > > > > >> On Sep 30, 2010 2:38pm, hidura at gmail.com wrote: > > > > > > >> > Sorry, for the last mail, here it's what you asked: > > > > > > >> > > > > > > > >> > {'CONTENT_LENGTH': '61', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'CONTENT_TYPE': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'multipart/form-data; > > > > > > >> > > boundary=---------------------------8905735096173894531259794847', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'DOCUMENT_ROOT': > > > > > > >> > [Thu Sep 30 13:35:07 2010] > [error] '/home/hidura/webapps/karinapp/Suite', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'GATEWAY_INTERFACE': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'CGI/1.1', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT': > > > > > > >> > [Thu Sep 30 13:35:07 2010] > > > > > > >> > [error] > > > > > > >> > > 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', [Thu > > > > > > >> > Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_CHARSET': > > > > > > >> > [Thu Sep 30 13:35:07 2010] > [error] 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_ENCODING': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'gzip,deflate', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_LANGUAGE': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'es-do,en-us;q=0.7,en;q=0.3', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_CONNECTION': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'close', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_HOST': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_REFERER': > > > > > > >> > [Thu Sep 30 13:35:07 2010] > > > > > > >> > [error] 'http://hidura.webfactional.com/?md=btdump', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_USER_AGENT': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'Mozilla/5.0 (X11; U; Linux > x86_64; > > > > > > >> > en-US; rv:1.9.2.10) Gecko/20100915 Ubuntu/10.04 (lucid) > Firefox/3.6.10', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_X_FORWARDED_FOR': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '190.94.122.180', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'PATH_INFO': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'QUERY_STRING': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_ADDR': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_PORT': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '58742', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_METHOD': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'POST', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_URI': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_FILENAME': > > > > > > >> > [Thu Sep 30 13:35:07 2010] > > > > > > >> > [error] '/home/hidura/webapps/karinapp/Suite/Gate.py', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_NAME': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADDR': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADMIN': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '[no address given]', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_NAME': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PORT': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '80', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PROTOCOL': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP/1.0', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SIGNATURE': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SOFTWARE': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'Apache/2.2.15 (Unix) > mod_wsgi/3.3 > > > > > > >> > Python/3.1', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.application_group': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'web152.webfaction.com| > /gate.py', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.callable_object': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'application', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.handler_script': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.input_chunked': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '0', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_host': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_port': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '51543', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.process_group': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.request_handler': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi-script', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.script_reloading': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '1', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.version': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] (3, 3), > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.errors': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] , > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.file_wrapper': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] , > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.input': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] , > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multiprocess': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] False, > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multithread': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] True, > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.run_once': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] False, > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.url_scheme': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'http', > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.version': > > > > > > >> > [Thu Sep 30 13:35:07 2010] [error] (1, 1)} > > > > > > >> > > > > > > > >> > On Sep 30, 2010 1:56pm, "Diez B. Roggisch" deets at web.de> wrote: > > > > > > >> > > *sigh* > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > AGAIN, please do *not* reply to me personally. Reply to the ML > or NG > > > > > > >> > > > > > > > >> > you are posting in. I'm beginning to believe that it's a waste > of time to > > > > > > >> > answer you since you seem not able to follow even the most > simple of > > > > > > >> > advice and rules. > > > > > > >> > > > > > > > >> > > And read the answers you get thoroughly, you did not give all > the > > > > > > >> > > > > > > > >> > information I asked you for. > > > > > > >> > > > > > > > >> > > On Sep 30, 2010, at 7:08 PM, hidura at gmail.com wrote: > > > > > > >> > > > The output is: > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > -----------------------------110550484811701713451664404475--\r > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > No more i don 't know what that means or what do with this. > > > > > > >> > > > > > > > > > >> > > > On Sep 30, 2010 11:55am, "Diez B. Roggisch" deets at web.de> > wrote: > > > > > > >> > > > > hidura at gmail.com writes: > > > > > > >> > > > > > Hello list, i had seriously troubles with the connection > between > > > > > > >> > > > > > > > >> > a form and the > > > > > > >> > > > > > > > >> > > > > > wsgi, i' ve made an application on Python3 and was > running > > > > > > >> > > > > > > > >> > perfectly but when i > > > > > > >> > > > > > > > >> > > > > > try to use the to pass the data this can't be see on the > server, > > > > > > >> > > > > > > > >> > so what > > > > > > >> > > > > > > > >> > > > > > is your recommendation?, i am open to all the ideas less > leave to > > > > > > >> > > > > > > > >> > Python2 i > > > > > > >> > > > > > > > >> > > > > > can't all the project was write on Python3, i was > looking into > > > > > > >> > > > > > > > >> > the PEP 444 > > > > > > >> > > > > > > > >> > > > > > proposal too. > > > > > > >> > > > > > > > > > > > >> > > > > > > > > > > > >> > > > > > > > > > > > >> > > > > > > > > > > > >> > > > > > > > > > > > >> > > > > > > > > > > > >> > > > > > > > > > > > >> > > > > > Here is the code what i used to take the data: > > > > > > >> > > > > > > > > > > > >> > > > > > > > > > > > >> > > > > > > > > > > > >> > > > > > > > > > > > >> > > > > > > > > > > > >> > > > > > > > > > > > >> > > > > > > > > > > > >> > > > > > > print(urllib.parse.parse_qs(environ['wsgi.input'].read(int(enviro > > > > > > >> > > > > > n > > > > > > >> > > > > > > > > > > > >> > > > > > > > > > > > >> > > > > > > > > > > > >> > > > > > ['CONTENT_LENGTH'])).decode())) > > > > > > >> > > > > > > > > > > >> > > > > What is the ouptut of this? What does > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > import pprint > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > pprint.pprint(environ) > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > give you? > > > > > > >> > > > > > > > > > > >> > > > > > and here it's what the os.environ.item() prints to me: > > > > > > >> > > > > That's irrelevant. The WSGI-environ is what is needed. > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > Diez > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > -- > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > -- > > > > > > http://mail.python.org/mailman/listinfo/python-list > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rNOSPAMon at flownet.com Fri Oct 1 01:37:17 2010 From: rNOSPAMon at flownet.com (RG) Date: Thu, 30 Sep 2010 22:37:17 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> <87tyl63cag.fsf@mail.geddis.org> Message-ID: In article <87tyl63cag.fsf at mail.geddis.org>, Don Geddis wrote: > Keith Thompson wrote on Thu, 30 Sep 2010: > > RG writes: > >> You're missing a lot of context. I'm not trying to criticize C, just to > >> refute a false claim that was made about it. > > Can you cite the article that made this false claim, and exactly what > > the false claim was? > > http://groups.google.com/group/comp.lang.lisp/msg/431925448da59481 > > Message-ID: > <0497e39d-6bd1-429d-a86f-f4c89babe1a4 at u31g2000pru.googlegroups.com> > From: TheFlyingDutchman > Newsgroups: comp.lang.lisp > > [...] > in C I can have a function maximum(int a, int b) that will always > work. Never blow up, and never give an invalid answer. If someone > tries to call it incorrectly it is a compile error. > [...] > > ______________________________________________________________________________ > _ > Don Geddis http://don.geddis.org/ > don at geddis.org Thanks, Don. rg From rustompmody at gmail.com Fri Oct 1 01:42:45 2010 From: rustompmody at gmail.com (rustom) Date: Thu, 30 Sep 2010 22:42:45 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> <87tyl63cag.fsf@mail.geddis.org> Message-ID: <13ac95a0-c9f5-4f45-a94b-27d917ee4220@w15g2000pro.googlegroups.com> Some points that seem to be missed (or Ive missed them?) 1. A dichotomy is being made between 'static' languages like C and 'dynamic' languages like python/lisp. This dichotomy was valid 30 years ago, not today. In Haskell for example - static checking is stronger than in C/C++ -- its very hard if not impossible to core dump haskell except through memory exhaustion - dynamic-ness is almost that of python/lisp -- on can write significant haskell programs without type-declaring a single variable/ function Much more mainstream, C# is almost as 'managed' as dynamic languages and has efficiency comparable to C. 2. The dichotomy above misses a more pervasive dichotomy -- hardware vs software -- as real today as 30 years ago. To see this let us lift the discussion from that of *languages* C vs Python/Lisp to philosophies: -- C-philosophy: the purpose of type-checking is to maximize (runtime) efficiency -- Lisp-philosophy: the purpose of type-checking is zero-errors (aka seg-faults) via continuous checks at all levels. If one is honest (and not polemical :-) ) it would admitted that both sides are needed in different contexts. Now Dijkstra pointed (40 years ago) in Discipline of Programming that this unfortunate dilemma arises due to lack of hardware support. I am unable to reproduce the elegance and succinctness of his language but the argument is as follows: Let us say that for a typical profile of a computer we have for every one instruction of the pathological one typified by the maximum function, a trillion 'normal' instructions. This is what he calls a very-skew test -- an if-then-else that checks this would go the if-way way one trillion times for one else-way. It is natural for a programmer to feel the pinch of these trillion checks and (be inclined to) throw them away. If however the check was put into hardware there would be no such dilemma. If every arithmetic operation was always checked for overflow *by hardware* even languages committed to efficiency like C could trap on errors with no extra cost. Likewise Lisp/python-like languages could easily be made more efficient. The diff arises from the fact that software costs per use whereas hardware costs per installation -- a transistor, unlike an if, does not cost any more if its used once or a trillion times. In short the problem is not C vs Lisp/Python but architectures like Intel wherein: 1. an overflow bit harmlessly set by a compare operation is indistinguishable from one set by a signed arithmetic operation -- almost certainly a problem 2. An into instruction (interrupt on overflow) must be inserted into the software stream rather than raised as a hardware interrupt. From rNOSPAMon at flownet.com Fri Oct 1 01:49:24 2010 From: rNOSPAMon at flownet.com (RG) Date: Thu, 30 Sep 2010 22:49:24 -0700 Subject: "Strong typing vs. strong testing" References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: In article , Seebs wrote: > On 2010-09-30, RG wrote: > > That gives (what I would consider to be) false positives, e.g.: > > > [ron at mighty:~]$ cat foo.c > > > void foo(long x) {} > > > int main() { foo(1); } > > [ron at mighty:~]$ gcc -Wconversion foo.c > > foo.c: In function ???main???: > > foo.c:4: warning: passing argument 1 of ???foo??? with different width due > > to prototype > > But it's *not* a false positive. The compiler is not claiming that the > conversion couldn't be done -- it's just telling you that there is a > change of type going on. Again, you can't have it both ways. Either a warning is a "compiler error" according to the claim at issue (see below) or it is not. If it is, then this is a false positive. If it is not, then my previous example refutes the claim. > If you don't want that message, it is certainly possible to write code > which won't get it, and which will reliably work everywhere. Of course it's possible. It's *possible*, with enough effort, to write correct code in any programming language. What does that have to do with anything? > > So you have to choose your compiler > > (and flags) first, and then I get to construct my example. If my > > example has *either* an error that the compiler doesn't catch *or* a > > non-error that it does catch then I win. > > Those goal posts are sorta red shifted at this point. At this point I would like to quote a wise man who once said: > May I suggest that, if you don't want to use words and terminology > precisely, perhaps computer programming is not for you? Red shifted? > You're redefining "error" and "non-error" so as to demand that a statically > typed language offer you the same semantics of errors and non-errors that > dynamically typed languages have. That's cheating, though. The claim > is about C, not about what people who are expecting a dynamically typed > language would like C to be like. The claim is: http://groups.google.com/group/comp.lang.lisp/msg/431925448da59481 Message-ID: <0497e39d-6bd1-429d-a86f-f4c89babe1a4 at u31g2000pru.googlegroups.com> From: TheFlyingDutchman Newsgroups: comp.lang.lisp [...] in C I can have a function maximum(int a, int b) that will always work. Never blow up, and never give an invalid answer. If someone tries to call it incorrectly it is a compile error. [...] The truth of this claim hinges on the definitions of "work", "never blow up", "invalid", "call incorrectly" and "compile error." Define these however you like, the result will be that the claim is either false or vacuous. rg From arnodel at gmail.com Fri Oct 1 02:28:28 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 01 Oct 2010 07:28:28 +0100 Subject: discussion References: <31a08825-bb72-4e9f-8710-a39fe2bc9216@u31g2000pru.googlegroups.com> <4ca547ed$0$1647$742ec2ed@news.sonic.net> Message-ID: <87iq1ml94j.fsf@gmail.com> John Nagle writes: > On 9/30/2010 7:12 PM, Geo_subodh wrote: >> please send me the simple python code that uses input number greater >> than3 digits(>3 digits) and checks whether the number is palindrome >> or not. > > def ispalin(s) : > s = str(s) > n = len(s) / 2 > return(s[:n] == s[::-1][:n]) return s.startswith(s[n:][::-1]) You'll save valuable time when deploying your palindrome checking system and it has to check trillions of palindromes an hour :) -- Arnaud From zzbbaadd at aol.com Fri Oct 1 02:28:42 2010 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Thu, 30 Sep 2010 23:28:42 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> <87tyl63cag.fsf@mail.geddis.org> Message-ID: > > ? ? ? ? in C I can have a function maximum(int a, int b) that will always > > ? ? ? ? work. Never blow up, and never give an invalid answer. If someone > > ? ? ? ? tries to call it incorrectly it is a compile error. > > I would agree that the third sentence is arguably wrong, simply > because there's no such thing (outside #error) of a mandate to stop > compiling. ?However, my understanding was that the dispute was over > the second sentence, and that's certainly correct. > Why do you consider the term "compile error" a "mandate to stop compiling"? What do you say to refer to the situation when you have a statement in your program that the compiler finds is an error? And is it really material whether the compiler flagged an error and stopped, or flagged an error and looked for additional errors??? From zzbbaadd at aol.com Fri Oct 1 02:46:05 2010 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Thu, 30 Sep 2010 23:46:05 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> <87tyl63cag.fsf@mail.geddis.org> Message-ID: On Sep 30, 10:37?pm, RG wrote: > In article <87tyl63cag.... at mail.geddis.org>, > ?Don Geddis wrote: > > > > > > > Keith Thompson wrote on Thu, 30 Sep 2010: > > > RG writes: > > >> You're missing a lot of context. ?I'm not trying to criticize C, just to > > >> refute a false claim that was made about it. > > > Can you cite the article that made this false claim, and exactly what > > > the false claim was? > > >http://groups.google.com/group/comp.lang.lisp/msg/431925448da59481 > > > ? ? ? ? Message-ID: > > ? ? ? ? <0497e39d-6bd1-429d-a86f-f4c89babe... at u31g2000pru.googlegroups.com> > > ? ? ? ? From: TheFlyingDutchman > > ? ? ? ? Newsgroups: comp.lang.lisp > > > ? ? ? ? [...] > > ? ? ? ? in C I can have a function maximum(int a, int b) that will always > > ? ? ? ? work. Never blow up, and never give an invalid answer. If someone > > ? ? ? ? tries to call it incorrectly it is a compile error. > > ? ? ? ? [...] > > > ___________________________________________________________________________?___ > > _ > > Don Geddis ? ? ? ? ? ? ? ? ?http://don.geddis.org/? ? ? ? ? ? ? > > d... at geddis.org > > Thanks, Don. > > rg- Thanks from me as well, Don. I was worried that people would start to believe that the original statement was what you said it was: "I'm not even saying it's a flaw in the language. All I'm saying is that the original claim -- that any error in a C program will be caught by the compiler -- is false, and more specifically, that it can be demonstrated to be false without appeal to unknown run-time input." From spam+lisp_dot_linux at gmail.com Fri Oct 1 03:32:28 2010 From: spam+lisp_dot_linux at gmail.com (Antony) Date: Fri, 01 Oct 2010 00:32:28 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> Message-ID: On 9/30/2010 9:06 AM, Seebs wrote: > > At $dayjob, they give us months between feature complete and shipping, Lucky you -Antony From bruno.desthuilliers at gmail.com Fri Oct 1 03:42:34 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Fri, 1 Oct 2010 00:42:34 -0700 (PDT) Subject: if the else short form References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> <20100930132231.6f51b2a6@geekmail.INVALID> Message-ID: <16a5c344-b6fb-4da1-b07b-b4168bdda2f7@x42g2000yqx.googlegroups.com> On 30 sep, 19:22, Andreas Waldenburger wrote: > On Thu, 30 Sep 2010 03:42:29 -0700 (PDT) > > "bruno.desthuilli... at gmail.com" wrote: > > On 29 sep, 19:20, Seebs wrote: > > > On 2010-09-29, Tracubik wrote: > > > > button = gtk.Button(("False,", "True,")[fill==True]) > > > > Oh, what a nasty idiom. > > > Well, it's not very different from dict-based dispatch , which is the > > core of OO polymorphic dispatch in quite a few dynamic OOPLs. > > > Anyway, it's a common Python idiom and one that's not specially hard > > to grasp so I don't see any legibility problem here. > > But it does violate the "explicit is better than implicit" tenet, don't > you think? Why so ? The doc clearly states that booleans are integers with True == 1 and False == 0, so there's nothing implicit here. From joel.hedlund at gmail.com Fri Oct 1 04:03:34 2010 From: joel.hedlund at gmail.com (Joel Hedlund) Date: Fri, 1 Oct 2010 01:03:34 -0700 (PDT) Subject: gedit 'External Tools' plugin hashlib weirdness References: <9b96e07d-ee84-4cb2-ab1b-06bc01868aab@p26g2000yqb.googlegroups.com> Message-ID: <92f3b795-709e-4ba0-8518-e604af576cdc@a19g2000yql.googlegroups.com> I apparently replied to soon. Removing /usr/lib/python2.4 from PYTHONPATH did not solve the problem. I think I may have had a launcher-started gedit running somewhere in the background while testing. Any subsequent terminal-launches would then just create new windows for the existing (non-bugged) process, rather than starting a new process and tripping the bug (and by bug I mean configuration error on my part, most likely). However, I went further along the sys.path diff and found a path to a second python2.6 installation. Apparently, this one shipped with a standalone middleware client for distributed computing, and was insinuated into my PYTHONPATH via a call to its startup script in my .bashrc. Removing the call to the startup script solved the problem again (!) I still can't explain the traceback though. But fwiw, this solution made the problem stay solved past a reboot, so I have high hopes this time. /Joel From pjb at informatimago.com Fri Oct 1 05:09:09 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Fri, 01 Oct 2010 11:09:09 +0200 Subject: "Strong typing vs. strong testing" References: <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xr5gbxfry.fsf@ruckus.brouhaha.com> Message-ID: <8762xmmg96.fsf@kuiper.lan.informatimago.com> Gene writes: > The FA or TM dichotomy is more painful to contemplate than you say. > Making appropriate simplifications for input, any modern computer is a > FA with 2^(a few trillion) states. Consequently, the gestalt of > computer science seems to be to take it on faith that at some very > large number of states, the FA behavior makes a transition to TM > behavior for all possible practical purposes (and I mean all). So > what is it--really--that's trivial to analyze? And what is > impossible? I'm sorry this is drifting OT and will stop here. Don't worry, this thread is becoming interesting at least. -- __Pascal Bourguignon__ http://www.informatimago.com/ From steve at REMOVE-THIS-cybersource.com.au Fri Oct 1 05:14:13 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Oct 2010 09:14:13 GMT Subject: discussion References: <31a08825-bb72-4e9f-8710-a39fe2bc9216@u31g2000pru.googlegroups.com> Message-ID: <4ca5a664$0$11112$c3e8da3@news.astraweb.com> On Thu, 30 Sep 2010 19:12:06 -0700, Geo_subodh wrote: > please send me the simple python code that uses input number greater > than3 digits(>3 digits) and checks whether the number is palindrome or > not. def is_palindrome_or_not(n): """Checks whether the input number n is a palindrome or not.""" if n >= 100: return n is "palindrome" or n is not "palindrome" else: raise ValueError("n must be a positive number with 3+ digits") -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Oct 1 05:21:24 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Oct 2010 09:21:24 GMT Subject: Having problem with subclass References: <5fce1fb4-3fc1-47cc-a588-b335b7516846@c10g2000yqh.googlegroups.com> Message-ID: <4ca5a814$0$11112$c3e8da3@news.astraweb.com> On Thu, 30 Sep 2010 18:54:00 -0700, tekion wrote: > When I move Bclass to A.py, it works. Is there some restriction in > python that sub classing a class has be in the same file as the class > you're are sub classing? Thanks. Others have already solved your main problem (you need to refer to A.Aclass rather than just Aclass), but I'd like to make another comment. Unlike Java, Python programmers rarely see the need to have one class per file, especially if they are small classes. Generally subclasses will be small -- you might only change a handful of methods. I'd even go say as to say that the Java (anti-)pattern of placing each and every class into its own file is actively frowned upon by Python programmers. By all means arrange your classes into separate modules if that is the most natural way to arrange them, but don't artificially break apart related classes into separate modules. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Oct 1 05:24:22 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Oct 2010 09:24:22 GMT Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> <8gk6o2Fc8aU2@mid.individual.net> Message-ID: <4ca5a8c6$0$11112$c3e8da3@news.astraweb.com> On Thu, 30 Sep 2010 21:27:03 +0000, Seebs wrote: > On 2010-09-30, Ian Collins wrote: >> Which is why agile practices such as TDD have an edge. If it compiles >> *and* passes all its tests, it must be right. > > So far as I know, that actually just means that the test suite is > insufficient. +1 QOTW Now can we (by which I mean *you*) stop cross-posting C talk to multiple newsgroups that don't have anything to do with C? Thank you. -- Steven From nick_keighley_nospam at hotmail.com Fri Oct 1 05:32:14 2010 From: nick_keighley_nospam at hotmail.com (Nick Keighley) Date: Fri, 1 Oct 2010 02:32:14 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> Message-ID: On 27 Sep, 18:46, namekuseijin wrote: > Fact is: ?almost all user data from the external words comes into > programs as strings. ?No typesystem or compiler handles this fact all > that graceful... snobol? From pjb at informatimago.com Fri Oct 1 05:33:26 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Fri, 01 Oct 2010 11:33:26 +0200 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> <87tyl63cag.fsf@mail.geddis.org> Message-ID: <87wrq2l0k9.fsf@kuiper.lan.informatimago.com> Seebs writes: > On 2010-10-01, Don Geddis wrote: >> in C I can have a function maximum(int a, int b) that will always >> work. Never blow up, and never give an invalid answer. If someone >> tries to call it incorrectly it is a compile error. > > I would agree that the third sentence is arguably wrong, simply > because there's no such thing (outside #error) of a mandate to stop > compiling. However, my understanding was that the dispute was over > the second sentence, and that's certainly correct. > > The obvious simple maximum() in C will not raise an exception nor return > something which isn't an int in any program which is not on its face > invalid in the call. This is by definite contrast with several of the > interpreted languages, This has nothing to do with the fact that these languages have implementations using the interpreter pattern instead of a compiler. Matter of fact, most Common Lisp implementations just do not have any interpreter! (Which doesn't prevent them to have a REPL). > where a function or subroutine like that cannot > specify that its argument must be some kind of integer. This is correct, but this is not a characteristic of dynamic programming languages. There are dynamic programming languages where you can declare the type of the parameters, to allow for static checking. For example in Common Lisp (where these declarations are advisory, so the compiler is free to take them into account or not, depending on what it can infer from its own side, so any problem here is just a warning: the program can always handle the problems at run-time). -- __Pascal Bourguignon__ http://www.informatimago.com/ From pjb at informatimago.com Fri Oct 1 05:56:24 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Fri, 01 Oct 2010 11:56:24 +0200 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> <87tyl63cag.fsf@mail.geddis.org> <13ac95a0-c9f5-4f45-a94b-27d917ee4220@w15g2000pro.googlegroups.com> Message-ID: <87sk0qkzhz.fsf@kuiper.lan.informatimago.com> rustom writes: > Some points that seem to be missed (or Ive missed them?) > > 1. A dichotomy is being made between 'static' languages like C and > 'dynamic' languages like python/lisp. This dichotomy was valid 30 > years ago, not today. In Haskell for example > > - static checking is stronger than in C/C++ -- its very hard if not > impossible to core dump haskell except through memory exhaustion > > - dynamic-ness is almost that of python/lisp -- on can write > significant haskell programs without type-declaring a single variable/ > function You're confunding type strongness with the requirement that the programmer should declare the types, and with the time when the types are checked. http://en.wikipedia.org/wiki/Comparison_of_programming_languages#Type_systems type strong static explicit Ada type strong static implicit Haskell type weak static explicit C type weak static implicit ? type strong dynamic explicit (*) type strong dynamic implicit Common Lisp type weak dynamic explicit Objective-C type weak dynamic implicit JavaScript (*) Usually languages provide explicit typing as an option, but can deal with implicit typing, when they're dynamic. There are also a few languages with no type checking, such as assembler or Forth. > Much more mainstream, C# is almost as 'managed' as dynamic languages > and has efficiency comparable to C. Nothing extraordinary here. Common Lisp is more efficient than C. http://www.lrde.epita.fr/~didier/research/verna.06.ecoop.pdf http://portal.acm.org/citation.cfm?id=1144168 Actually, it's hard to find a language that has no compiler generating faster code than C... > 2. The dichotomy above misses a more pervasive dichotomy -- hardware > vs software -- as real today as 30 years ago. > > To see this let us lift the discussion from that of *languages* C vs > Python/Lisp to philosophies: > -- C-philosophy: the purpose of type-checking is to maximize (runtime) > efficiency > -- Lisp-philosophy: the purpose of type-checking is zero-errors (aka > seg-faults) via continuous checks at all levels. > > If one is honest (and not polemical :-) ) it would admitted that both > sides are needed in different contexts. > > Now Dijkstra pointed (40 years ago) in Discipline of Programming that > this unfortunate dilemma arises due to lack of hardware support. I am > unable to reproduce the elegance and succinctness of his language but > the argument is as follows: > > Let us say that for a typical profile of a computer we have for every > one instruction of the pathological one typified by the maximum > function, a trillion 'normal' instructions. This is what he calls a > very-skew test -- an if-then-else that checks this would go the if-way > way one trillion times for one else-way. It is natural for a > programmer to feel the pinch of these trillion checks and (be inclined > to) throw them away. > > If however the check was put into hardware there would be no such > dilemma. If every arithmetic operation was always checked for overflow > *by hardware* even languages committed to efficiency like C could trap > on errors with no extra cost. > Likewise Lisp/python-like languages could easily be made more > efficient. > > The diff arises from the fact that software costs per use whereas > hardware costs per installation -- a transistor, unlike an if, does > not cost any more if its used once or a trillion times. > > In short the problem is not C vs Lisp/Python but architectures like > Intel wherein: > > 1. an overflow bit harmlessly set by a compare operation is > indistinguishable from one set by a signed arithmetic operation -- > almost certainly a problem > > 2. An into instruction (interrupt on overflow) must be inserted into > the software stream rather than raised as a hardware interrupt. Hence the use of virtual machine: when your machine doesn't do what you want, you have to write your own. When Intel will realize that 99% of its users are running VM, perhaps they'll start to wonder what they're making wrong... -- __Pascal Bourguignon__ http://www.informatimago.com/ From pjb at informatimago.com Fri Oct 1 06:02:31 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Fri, 01 Oct 2010 12:02:31 +0200 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> <8gk6o2Fc8aU2@mid.individual.net> Message-ID: <87lj6ikz7s.fsf@kuiper.lan.informatimago.com> Seebs writes: > On 2010-09-30, Ian Collins wrote: >> Which is why agile practices such as TDD have an edge. If it compiles >> *and* passes all its tests, it must be right. > > So far as I know, that actually just means that the test suite is > insufficient. :) > > Based on my experience thus far, anyway, I am pretty sure it's essentially > not what happens that the tests and code are both correct, and it is usually > the case either that the tests fail or that there are not enough tests. It also shows that for languages such as C, you cannot limit the unit tests to the types declared for the function, but that you should try all the possible values of the language. Which basically, is the same as with dynamically typed programming language, only now, some unit tests will fail early, when trying to compile them while others will give wrong results later. static dynamic compiler detects wrong type fail at compile fails at run-time (with exception explaining this is the wrong type) compiler passes wrong type wrong result fails at run-time (the programmer (with exception spends hours explaining this is finding the the wrong type) problem) compiler passes correct type wrong result wrong result (normal bug to be corrected) compiler passes correct type correct result correct result -- __Pascal Bourguignon__ http://www.informatimago.com/ From Antoon.Pardon at rece.vub.ac.be Fri Oct 1 06:07:13 2010 From: Antoon.Pardon at rece.vub.ac.be (Antoon Pardon) Date: Fri, 1 Oct 2010 12:07:13 +0200 Subject: if the else short form In-Reply-To: <877hi44w53.fsf@xemacs.org> References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> <877hi44w53.fsf@xemacs.org> Message-ID: <20101001100712.GA2144@rcpc42.vub.ac.be> On Wed, Sep 29, 2010 at 01:38:48PM +0200, Hrvoje Niksic wrote: > Tracubik writes: > > > Hi all, > > I'm studying PyGTK tutorial and i've found this strange form: > > > > button = gtk.Button(("False,", "True,")[fill==True]) > > > > the label of button is True if fill==True, is False otherwise. > > The tutorial likely predates if/else expression syntax introduced in > 2.5, which would be spelled as: > > button = gtk.Button("True" if fill else "False") > > BTW adding "==True" to a boolean value is redundant and can even break > for logically true values that don't compare equal to True (such as the > number 10 or the string "foo"). But leaving it out can also break things. If for some reason a variable can have a boolean or a numeric value, that doesn't mean the coder wants to treat 0 the same as False or any non-zero number the same as True. -- Antoon Pardon From Antoon.Pardon at rece.vub.ac.be Fri Oct 1 06:09:46 2010 From: Antoon.Pardon at rece.vub.ac.be (Antoon Pardon) Date: Fri, 1 Oct 2010 12:09:46 +0200 Subject: if the else short form In-Reply-To: References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> <877hi44w53.fsf@xemacs.org> Message-ID: <20101001100946.GB2144@rcpc42.vub.ac.be> On Wed, Sep 29, 2010 at 05:58:16AM -0700, bruno.desthuilliers at gmail.com wrote: > On 29 sep, 13:38, Hrvoje Niksic wrote: > > Tracubik writes: > > > > > button = gtk.Button(("False,", "True,")[fill==True]) > > (snip) > > > BTW adding "==True" to a boolean value is redundant and can even break > > for logically true values that don't compare equal to True (such as the > > number 10 or the string "foo"). > > Note that if fill is actually an int outside the (0, 1) domain, it > will break too. The correct test would be: > > ("False,", "True,")[bool(fill)]) That is assuming the original coder would want the argument "True," in such cases. You don't know that. -- Antoon Pardon From peter.bienstman at gmail.com Fri Oct 1 06:16:47 2010 From: peter.bienstman at gmail.com (pbienst) Date: Fri, 1 Oct 2010 03:16:47 -0700 (PDT) Subject: C API: Getting PyObject by name References: <3ed9a977-b77f-4f2a-b62c-bae97e2f3339@x42g2000yqx.googlegroups.com> Message-ID: Here is what I tried, but it prints out '-1': PyObject* obj = PyRun_String("1", Py_single_input, PyEval_GetGlobals(), PyEval_GetLocals()); long d = PyLong_AsLong(obj); printf("long:%ld\n", d); Py_DECREF(obj); Peter On Sep 30, 9:24?pm, Thomas Jollans wrote: > On Thursday 30 September 2010, it occurred to pbienst to exclaim: > > > Hi, > > > I'm embedding Python in a C app. > > > Say I do the following: > > > ? PyRun_SimpleString("a = 1") > > > Is there then a way to get access to the PyObject corresponding to a, > > only making use in C of the fact that it's called "a"? > > > I've searched through the API docs, but I couldn't really find what I > > was looking for. > > No. Not as such. But you could use PyRun_String, or PyRun_StringFlags. You > could then access the globals object, but I ask you, why would you want to > bind the object to a name in the first place? Use the fact that PyRun_String > returns a reference to the result of an expression! From aotto1968 at users.sourceforge.net Fri Oct 1 06:54:32 2010 From: aotto1968 at users.sourceforge.net (Andreas Otto) Date: Fri, 01 Oct 2010 12:54:32 +0200 Subject: ANNOUNCE - NHI1 / PLMK / libmsgque - Work-Package-II Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Dear User, ANNOUNCE: Work-Package-II ============================ libmsgque: Application-Server-Toolkit for C, C++, JAVA, C#, TCL, PERL, PYTHON, VB.NET PLMK: Programming-Language-Microkernel NHI1: Non-Human-Intelligence #1 SUMMARY ======= After six month research workshop with bicycling through the 'Black Forrest', 'Vosges', 'Switzerland' / 'French' and 'Italy' Alps ... I'm back to serve for "Work Package II" of NHI1 Read More At ============ http://nhi1.berlios.de/theLink/wp2.htm mfg Andreas Otto (aotto1968) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.15 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJMpb3oAAoJEGTcPijNG3/AzuMH/jU2HKpDL56Imlx25ztWR/Jl wESKLLj8vBgiFWDUprxpBYF5CHGblXCMfk1CowfnjJ7TiuLKMNhTv/W3V/9gCYbb C9wNZ6lpl9NYBnfD5QuR6vJsPK9pYY0nhcCh3W1jHOXZ/vlafGhvQETFZp32ukXz JTWx1LxB4NNxfuXBH5pRnDM9olAVMzndjr/+5QtmM3tQIOKV59wUJWn+1wz+N4Ol ZwrqYEi355sdFqWdANqlWx5aihInfM25HPZj60lF7lTHWAItJFZDAgjzd55I04wO S+hvlL18jyTJaJGy/otdYEj3IdVJvc/UzMcOiz9UBSThvhbmTf1OIYr2X9zyGRM= =gWr2 -----END PGP SIGNATURE----- From barthelemy at crans.org Fri Oct 1 07:00:10 2010 From: barthelemy at crans.org (=?ISO-8859-1?Q?S=E9bastien_Barth=E9lemy?=) Date: Fri, 1 Oct 2010 13:00:10 +0200 Subject: __file__ is sometimes absolute, sometimes relative Message-ID: Hello, I use a data file that lies on disk in the same directory that the module which makes use of it. The data file is checked in the repository and gets installed by the distutils ``package_data`` directive, so it is in place both during development and after and install. In my program, I need to find the absolute path to this data file. I could think of 3 ways to do this: 1. using the __path__ property in the module 2. using __file__ property in the module 3. using __file__ and os.getcwd() in the module The first option does not work, because __path__ is initialised after the module is loaded (apparently). Solution 2 works, but behaves differently when ran from python or from a doctest file. The path in __file__ is absolute if the program is ran directly by ``python``, and relative if it is ran by ``python -m doctest``. Solution 3 works. However if there is a better way to do this, please let me know. I could not find anything documenting what the proper value for __file__ should be. Maybe my problem with solution 2 is a bug in doctest or runpy? I put up a simple example exhibiting the problem. Here are the results on my mac (using python from macport) I get the same results using python 2.6, 2.7 and 3.1 $ python2.6 test.py /Users/seb/Devel/arboris-python/src/pyfile /Users/seb/Devel/arboris-python/src/pyfile/mod.pyc /Users/seb/Devel/arboris-python/src/pyfile /Users/seb/Devel/arboris-python/src/pyfile $ python2.6 -m doctest test.txt ********************************************************************** File "test.txt", line 5, in test.txt Failed example: print mod.__file__ Expected: /Users/seb/Devel/arboris-python/src/pyfile/mod.pyc Got: mod.pyc ********************************************************************** File "test.txt", line 7, in test.txt Failed example: print(mod.whereami) Expected: /Users/seb/Devel/arboris-python/src/pyfile Got: ********************************************************************** File "test.txt", line 9, in test.txt Failed example: print(mod.whereami2) Expected: /Users/seb/Devel/arboris-python/src/pyfile Got: /Users/seb/Devel/arboris-python/src/pyfile/ ********************************************************************** 1 items had failures: 3 of 6 in test.txt ***Test Failed*** 3 failures. Cheers Sebastian -------------- next part -------------- >>> import os >>> print(os.getcwd()) /Users/seb/Devel/arboris-python/src/pyfile >>> import mod >>> print(mod.__file__) /Users/seb/Devel/arboris-python/src/pyfile/mod.pyc >>> print(mod.whereami) /Users/seb/Devel/arboris-python/src/pyfile >>> print(mod.whereami2) /Users/seb/Devel/arboris-python/src/pyfile -------------- next part -------------- A non-text attachment was scrubbed... Name: mod.py Type: application/octet-stream Size: 193 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: test.py Type: application/octet-stream Size: 101 bytes Desc: not available URL: From lists at cheimes.de Fri Oct 1 07:47:14 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 01 Oct 2010 13:47:14 +0200 Subject: __file__ is sometimes absolute, sometimes relative In-Reply-To: References: Message-ID: Am 01.10.2010 13:00, schrieb S?bastien Barth?lemy: > Hello, > > I use a data file that lies on disk in the same directory that the > module which makes use of it. > > The data file is checked in the repository and gets installed by > the distutils ``package_data`` directive, so it is in place both > during development and after and install. > > In my program, I need to find the absolute path to this data file. > > I could think of 3 ways to do this: > 1. using the __path__ property in the module > 2. using __file__ property in the module > 3. using __file__ and os.getcwd() in the module Use the abspath function of the os.path module: HERE = os.path.dirname(os.path.abspath(__file__)) Christian From fuzzyman at gmail.com Fri Oct 1 08:12:51 2010 From: fuzzyman at gmail.com (Fuzzyman) Date: Fri, 1 Oct 2010 05:12:51 -0700 (PDT) Subject: namespace hacking question References: Message-ID: <302c25ba-2df6-4ecd-b11e-d12afd65df5b@a19g2000yql.googlegroups.com> On Sep 30, 6:07?pm, kj wrote: > This is a recurrent situation: I want to initialize a whole bunch > of local variables in a uniform way, but after initialization, I > need to do different things with the various variables. > > What I end up doing is using a dict: > > d = dict() > for v in ('spam', 'ham', 'eggs'): > ? ? d[v] = init(v) > > foo(d['spam']) > bar(d['ham']) > baz(d['eggs']) > > This is fine, but I'd like to get rid of the tedium of typing all > those extra d['...']s. > > I.e., what I would *like* to do is something closer to this: > > d = locals() > for v in ('spam', 'ham', 'eggs'): > ? ? d[v] = init(v) > > foo(spam) > bar(ham) > baz(eggs) > > ...but this results in errors like "NameError: global name 'spam' is > not defined". > > But the problem is deeper than the fact that the error above would > suggest, because even this fails: > > spam = ham = eggs = None > d = locals() > for v in ('spam', 'ham', 'eggs'): > ? ? d[v] = init(v) > > foo(spam) # calls foo(None) > bar(ham) ?# calls bar(None) > baz(eggs) # calls baz(None) > > In other words, setting the value of locals()['x'] does not set > the value of the local variable x. > > I also tried a hack using eval: > > for v in ('spam', 'ham', 'eggs'): > ? ? eval "%s = init('%s')" % (v, v) > > but the "=" sign in the eval string resulted in a "SyntaxError: > invalid syntax". > > Is there any way to use a loop to set a whole bunch of local > variables (and later refer to these variables by their individual > names)? > One way: import sys module = sys.modules[__name__] for entry in ('spam', 'eggs', 'ham'): setattr(module, entry, 'some value') Michael Foord -- http://www.voidspace.org.uk/ From bc at freeuk.com Fri Oct 1 08:23:31 2010 From: bc at freeuk.com (BartC) Date: Fri, 1 Oct 2010 13:23:31 +0100 Subject: "Strong typing vs. strong testing" In-Reply-To: <87sk0qkzhz.fsf@kuiper.lan.informatimago.com> References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com><0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com><9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com><996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com><07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com><0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> <87tyl63cag.fsf@mail.geddis.org><13ac95a0-c9f5-4f45-a94b-27d917ee4220@w15g2000pro.googlegroups.com> <87sk0qkzhz.fsf@kuiper.lan.informatimago.com> Message-ID: "Pascal J. Bourguignon" wrote in message news:87sk0qkzhz.fsf at kuiper.lan.informatimago.com... > rustom writes: >> Much more mainstream, C# is almost as 'managed' as dynamic languages >> and has efficiency comparable to C. > > Nothing extraordinary here. Common Lisp is more efficient than C. > http://www.lrde.epita.fr/~didier/research/verna.06.ecoop.pdf > http://portal.acm.org/citation.cfm?id=1144168 It seems that to make Lisp fast, you have to introduce static typing. Which is not much different to writing in C, other than the syntax. > Actually, it's hard to find a language that has no compiler generating > faster code than C... But those implementers have to try very hard to beat C. Meanwhile C can be plenty fast without doing anything special. > When Intel will realize that 99% of its users are running VM Which one? -- Bartc From Antoon.Pardon at rece.vub.ac.be Fri Oct 1 08:56:52 2010 From: Antoon.Pardon at rece.vub.ac.be (Antoon Pardon) Date: Fri, 1 Oct 2010 14:56:52 +0200 Subject: sequence multiplied by -1 In-Reply-To: References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> <7x4odcc426.fsf@ruckus.brouhaha.com> <20100930121043.GD2272@rcpc42.vub.ac.be> Message-ID: <20101001125652.GC2144@rcpc42.vub.ac.be> On Thu, Sep 30, 2010 at 07:02:40AM -0700, Emile van Sebille wrote: > On 9/30/2010 5:10 AM Antoon Pardon said... > >On Sun, Sep 26, 2010 at 03:20:18PM +0000, Grant Edwards wrote: > >>On 2010-09-26, Paul Rubin wrote: > >>>Steven D'Aprano writes: > >>>>There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", > >> > >>>Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"? > >> > >>Because > >> > >>3 * "spam" == "spam" + "spam" + "spam" > >> > >>Just like > >> > >>3 * 6 = 6 + 6 + 6 > >> > >>So now I suppose "+" for string concatenation is a bad thing. > > > >Well I find it an unfortunate choice. The problem is, that it is not that > >unusual to want some class to have the possibility of both addition and > >concatenation. But since we only one symbol for both operations, you will > >have to loose some consistency over this. > > > > Which is actually a good thing for a class that wants to have both > concatenation and addition Why? What is good about losing consistency? It is in this case necessary but that doesn't make it good. Think about the following possibility. Someone provides you with a library of functions that act on sequences. They rely on the fact that '+' concatenates. Someone else provides you with a library of functions that act on numbers. They rely on the fact that '+' provides addition. Now however you write your sequence like numbers or number like sequences one of those libraries will be useless for it. > -- which would it do with only one > symbol? But why limit ourselves to one symbol for different kind of operations, to begin with? -- Antoon Pardon From rui.maciel at gmail.com Fri Oct 1 09:12:43 2010 From: rui.maciel at gmail.com (Rui Maciel) Date: Fri, 01 Oct 2010 14:12:43 +0100 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> Message-ID: <4ca5de4b$0$23409$a729d347@news.telepac.pt> namekuseijin wrote: >> in C I can have a function maximum(int a, int b) that will always >> work. Never blow up, and never give an invalid answer. If someone >> tries to call it incorrectly it is a compile error. >> In a dynamic typed language maximum(a, b) can be called with incorrect >> datatypes. Even if I make it so it can handle many types as you did >> above, it could still be inadvertantly called with a file handle for a >> parameter or some other type not provided for. So does Eckel and >> others, when they are writing their dynamically typed code advocate >> just letting the function blow up or give a bogus answer, or do they >> check for valid types passed? If they are checking for valid types it >> would seem that any benefits gained by not specifying type are lost by >> checking for type. And if they don't check for type it would seem that >> their code's error handling is poor. > > that is a lie. > > Compilation only makes sure that values provided at compilation-time > are of the right datatype. > > What happens though is that in the real world, pretty much all > computation depends on user provided values at runtime. See where are > we heading? You are confusing two completely different and independent concepts, which is a language's typing sytem and input validation. TheFlyingDutchman pointed out the typical problems associated with weakly typed languages while you tried to contradict him by complaining about input sanity issues. The thing is, input sanity issues are perfectly independent of a language's typing system. Therefore, arguing about the need to perform sanity checks on programs written on language X or Y does nothing to tackle the issues related to passing a variable/object of the "wrong" type as a parameter to some function. Rui Maciel From pjb at informatimago.com Fri Oct 1 09:33:02 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Fri, 01 Oct 2010 15:33:02 +0200 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> <87tyl63cag.fsf@mail.geddis.org> <13ac95a0-c9f5-4f45-a94b-27d917ee4220@w15g2000pro.googlegroups.com> <87sk0qkzhz.fsf@kuiper.lan.informatimago.com> Message-ID: <87zkuyjawh.fsf@kuiper.lan.informatimago.com> "BartC" writes: > "Pascal J. Bourguignon" wrote in message > news:87sk0qkzhz.fsf at kuiper.lan.informatimago.com... >> rustom writes: > >>> Much more mainstream, C# is almost as 'managed' as dynamic languages >>> and has efficiency comparable to C. >> >> Nothing extraordinary here. Common Lisp is more efficient than C. >> http://www.lrde.epita.fr/~didier/research/verna.06.ecoop.pdf >> http://portal.acm.org/citation.cfm?id=1144168 > > It seems that to make Lisp fast, you have to introduce static > typing. Which is not much different to writing in C, other than the > syntax. > >> Actually, it's hard to find a language that has no compiler generating >> faster code than C... > > But those implementers have to try very hard to beat C. Meanwhile C > can be plenty fast without doing anything special. > >> When Intel will realize that 99% of its users are running VM > > Which one? Any implementation of a controlled environment is a virtual machine. Sometimes it is explicitely defined, such as in clisp, parot or jvm, but more often it is implicit, such as in sbcl, or worse, developed in an ad-hoc way in applications (eg. written in C++). -- __Pascal Bourguignon__ http://www.informatimago.com/ From rui.maciel at gmail.com Fri Oct 1 09:38:35 2010 From: rui.maciel at gmail.com (Rui Maciel) Date: Fri, 01 Oct 2010 14:38:35 +0100 Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: <4ca5e45c$0$23412$a729d347@news.telepac.pt> George Neuner wrote: > That's true. But it is a situation where the conversion to SI units > loses precision and therefore probably shouldn't be done. > I don't care to check it ... the fact that the SI unit involves 12 > decimal places whereas the imperial unit involves 3 tells me the > conversion probably shouldn't be done in a program that wants > accuracy. Your comment is absurd for multiple reasons. As we are focusing on the computational aspect of this issue then I will only say this: If we are dealing with a computer representation of numbers then, as long as the numeric data type provides enough precision, it is perfectly irrelevant if a decimal representation of a certain number involves 12 or 3 decimal places. The only precision issues which affect a calculation is the ones arising from a) the ability to exactly represent a certain number in a specific representation and b) the precision errors produced by arithmetic operations. Rui Maciel From wizzardx at gmail.com Fri Oct 1 09:43:12 2010 From: wizzardx at gmail.com (David) Date: Fri, 1 Oct 2010 15:43:12 +0200 Subject: Fwd: Python becoming orphaned over ssh In-Reply-To: References: <4ca36e44$0$1584$742ec2ed@news.sonic.net> <91cdb1f0-5db1-4566-9899-386a7f06104d@y31g2000vbt.googlegroups.com> Message-ID: (Sending again to the list, I mailed Jean-Paul off-list by mistake, sorry). On Thu, Sep 30, 2010 at 4:01 PM, Jean-Paul Calderone wrote: > You can fix this by resetting the signal disposition of SIGPIPE for > the ping process: > > ? ?#!/usr/bin/python > ? ?import signal > > ? ?def reset(): > ? ? ? ?signal.signal(signal.SIGPIPE, signal.SIG_DFL) > > ? ?from subprocess import check_call > ? ?check_call(['ping', 'www.google.com'], preexec_fn=reset) > > Very likely the subprocess module should be resetting the disposition > of signals that Python itself has fiddled with (and resetting any > other unusual state that the child is going to inherit, but nothing > else comes immediately to mind). > -- Thanks, that works for me. Also ?thanks to Gregory (Python developer) for fixing it so quickly (don't want to litter the bug tracker with thanks). Small annoyance: Though it's fixed with ping, wget still has the problem. However, I compared the two script versions again (test.sh, and test.py) for wget, and actually bash has the same problem as python, so I assume it's a wget bug this time (I'll go report the bug to them next). Is it that unusual to run scripts over non-interactive SSH, and then interrupt with Ctrl+C? :-). So I guess for now I need to keep my previous workaround for now, rather than switching to the preexec_fn syntax. Also, I don't 100% follow that explanation about the pipes. I read a bit more over here: http://en.wikipedia.org/wiki/SIGPIPE And it seems like SIGPIPE would apply in a case like this: ping www.google.com | test.py But I'm not calling ping like that. I guess it applies to regular stream, non-piping operations, too? ie, something like this is happening [ping output] passes through==> [test.py] ==> passes through [ssh] ==> passes through => [more ssh, bash, etc, up to my terminal] And when ssh disappears, then Linux automatically sends ping SIGPIPE, because it's output can no longer be "passed through" to anywhere. Pretty interesting, but I'm a noob with this stuff. If I want to learn more, would this WP article (and linked pages) be a good place to learn more? http://en.wikipedia.org/wiki/Signal_%28computing%29 Thanks, David. From bc at freeuk.com Fri Oct 1 09:46:39 2010 From: bc at freeuk.com (BartC) Date: Fri, 1 Oct 2010 14:46:39 +0100 Subject: discussion In-Reply-To: <31a08825-bb72-4e9f-8710-a39fe2bc9216@u31g2000pru.googlegroups.com> References: <31a08825-bb72-4e9f-8710-a39fe2bc9216@u31g2000pru.googlegroups.com> Message-ID: "Geo_subodh" wrote in message news:31a08825-bb72-4e9f-8710-a39fe2bc9216 at u31g2000pru.googlegroups.com... > please send me the simple python code that uses input number greater > than3 digits(>3 digits) and checks whether the number is palindrome > or not. The following works without using strings (although leading zeros are ignored, so that 01210 returns False): def fpalindrome(n): if n<0: return False if n<10: return True digits=1 a=n while a>=10: digits=digits+1 a=a//10 lastdigit=n%10 firstdigit=n//(10**(digits-1)) if firstdigit!=lastdigit: return False if digits==2: return True middledigits=n//10-firstdigit*(10**(digits-2)) return fpalindrome(middledigits) print fpalindrome(12345678987654321) -- Bartc From bc at freeuk.com Fri Oct 1 09:56:22 2010 From: bc at freeuk.com (BartC) Date: Fri, 1 Oct 2010 14:56:22 +0100 Subject: "Strong typing vs. strong testing" In-Reply-To: <87zkuyjawh.fsf@kuiper.lan.informatimago.com> References: <87tyl63cag.fsf@mail.geddis.org><13ac95a0-c9f5-4f45-a94b-27d917ee4220@w15g2000pro.googlegroups.com><87sk0qkzhz.fsf@kuiper.lan.informatimago.com> <87zkuyjawh.fsf@kuiper.lan.informatimago.com> Message-ID: "Pascal J. Bourguignon" wrote in message news:87zkuyjawh.fsf at kuiper.lan.informatimago.com... > "BartC" writes: > >> "Pascal J. Bourguignon" wrote in message >>> When Intel will realize that 99% of its users are running VM >> >> Which one? > > Any implementation of a controlled environment is a virtual machine. > Sometimes it is explicitely defined, such as in clisp, parot or jvm, but > more often it is implicit, such as in sbcl, or worse, developed in an > ad-hoc way in applications (eg. written in C++). But if you had to implement a VM directly in hardware, which one (of the several varieties) would you choose? And having chosen one, how would that impact the performance of a language with an incompatible VM? Perhaps processors executing native code as it is now, aren't such a bad idea. -- Bartc From rui.maciel at gmail.com Fri Oct 1 10:17:36 2010 From: rui.maciel at gmail.com (Rui Maciel) Date: Fri, 01 Oct 2010 15:17:36 +0100 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> <87tyl63cag.fsf@mail.geddis.org> <13ac95a0-c9f5-4f45-a94b-27d917ee4220@w15g2000pro.googlegroups.com> <87sk0qkzhz.fsf@kuiper.lan.informatimago.com> Message-ID: <4ca5ed80$0$23408$a729d347@news.telepac.pt> Pascal J. Bourguignon wrote: > Nothing extraordinary here. Common Lisp is more efficient than C. > http://www.lrde.epita.fr/~didier/research/verna.06.ecoop.pdf > http://portal.acm.org/citation.cfm?id=1144168 I don't know if you are intentionally trying to be deceitful or if you honestly didn't spent much time thinking about this issue. To be brief I will only point out the following topics: a) no language is inherently more or less efficient than any other language. The efficiency aspect is only related to how those languages are implemented (i.e., the investments made in optimizing the compilers/interpreters) b) Just because someone invested enough effort to optimize a specific implementation of language X to run, under a specific scenario, a benchmark faster than some other implementation of language Y it doesn't mean that language X's implementation outperforms or even matches every implementation of language Y under every conceivable scenario. Regarding the links that you've provided, again I don't know if you intended to be dishonest or if you simply didn't read them. The first link, entitled "Beating C in Scienti?c Computing Applications On the Behavior and Performance of LISP, Part 1", basically compares a highly optimized implementation of lisp (quite literally the "current state of the art in COMMON -LISP compiler technology") with a standard, run of the mill C implementation by performing a very specific benchmark. If that wasn't enough, the C implementation they adopted to represent C was none other than GCC 4.0.3. As we all know, the 4.0 branch of GCC was still experimental an ran notoriously worse than the 3.4 branch[1]. But even though you've ignored this, the article's authors haven't. They've stated the following on their article: We must admit however that this point of view is not totally unjusti?ed. Recent studies (Neuss, 2003; Quam, 2005) on various numerical computation algorithms ?nd that LISP code compiled with C MU - CL can run at 60% of the speed of equivalent C code. So, where exactly do you base your claims? > Actually, it's hard to find a language that has no compiler generating > faster code than C... Once again, I don't know if you are intentionally trying to be deceitful. If an undergraduate student happens to write a C compiler for a compiler class which employs no optimization whatsoevere then that will not mean that every single C compiler is incapable of generating efficient code. Rui Maciel [1] http://coyotegulch.com/reviews/gcc4/index.html From solipsis at pitrou.net Fri Oct 1 10:35:52 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 1 Oct 2010 16:35:52 +0200 Subject: Python becoming orphaned over ssh References: <4ca36e44$0$1584$742ec2ed@news.sonic.net> <91cdb1f0-5db1-4566-9899-386a7f06104d@y31g2000vbt.googlegroups.com> Message-ID: <20101001163552.326d532e@pitrou.net> On Thu, 30 Sep 2010 07:01:09 -0700 (PDT) Jean-Paul Calderone wrote: > > But signal dispositions are inherited by child processes. So you run > ping from your short Python program, and it inherits SIGPIPE being > ignored. And it's written in C, not Python, so when it writes to the > pipe, there's no exception. So ping never gets any indication that it > should exit. But doesn't write() fail with EPIPE in that situation? That would mean `ping` ignores any error return from write(). Regards Antoine. From solipsis at pitrou.net Fri Oct 1 10:37:53 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 1 Oct 2010 16:37:53 +0200 Subject: Determine sockets in use by python References: <4CA37FDA.3080605@digipen.edu> Message-ID: <20101001163753.44cfc82f@pitrou.net> On Thu, 30 Sep 2010 12:32:45 -0700 Jim Mellander wrote: > Thanks, I realized that even if I found out relevant info on the > socket, I would probably need to use ctypes to provide a low level > interface to select, as the socket wouldn't be a python socket object, > unless there is some way to promote a c socket to a python socket > object. > > Appreciate the info, folks. You can also try to monkeypatch the socket module (before importing the 3rd-party library) and replace the socket.socket() constructor with a custom one which tracks all created sockets in a structure of your choice. Not very pretty of course. From bruno.desthuilliers at gmail.com Fri Oct 1 10:40:52 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Fri, 1 Oct 2010 07:40:52 -0700 (PDT) Subject: namespace hacking question References: <302c25ba-2df6-4ecd-b11e-d12afd65df5b@a19g2000yql.googlegroups.com> Message-ID: <7dd83457-253b-420a-bf62-f004576be954@c10g2000yqh.googlegroups.com> On 1 oct, 14:12, Fuzzyman wrote: > On Sep 30, 6:07?pm, kj wrote: > > > > > This is a recurrent situation: I want to initialize a whole bunch > > of local variables in a uniform way, but after initialization, I > > need to do different things with the various variables. > > > What I end up doing is using a dict: > > > d = dict() > > for v in ('spam', 'ham', 'eggs'): > > ? ? d[v] = init(v) > > > foo(d['spam']) > > bar(d['ham']) > > baz(d['eggs']) > > > This is fine, but I'd like to get rid of the tedium of typing all > > those extra d['...']s. > > > I.e., what I would *like* to do is something closer to this: > > > d = locals() > > for v in ('spam', 'ham', 'eggs'): > > ? ? d[v] = init(v) > > > foo(spam) > > bar(ham) > > baz(eggs) > > > ...but this results in errors like "NameError: global name 'spam' is > > not defined". > > > But the problem is deeper than the fact that the error above would > > suggest, because even this fails: > > > spam = ham = eggs = None > > d = locals() > > for v in ('spam', 'ham', 'eggs'): > > ? ? d[v] = init(v) > > > foo(spam) # calls foo(None) > > bar(ham) ?# calls bar(None) > > baz(eggs) # calls baz(None) > > > In other words, setting the value of locals()['x'] does not set > > the value of the local variable x. > > > I also tried a hack using eval: > > > for v in ('spam', 'ham', 'eggs'): > > ? ? eval "%s = init('%s')" % (v, v) > > > but the "=" sign in the eval string resulted in a "SyntaxError: > > invalid syntax". > > > Is there any way to use a loop to set a whole bunch of local > > variables (and later refer to these variables by their individual > > names)? > > One way: > > import sys > module = sys.modules[__name__] > > for entry in ('spam', 'eggs', 'ham'): > ? ? setattr(module, entry, 'some value') > Only works on globals - which you can already set using globals() IIRC. From usenet-nospam at seebs.net Fri Oct 1 10:44:53 2010 From: usenet-nospam at seebs.net (Seebs) Date: 01 Oct 2010 14:44:53 GMT Subject: "Strong typing vs. strong testing" References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: On 2010-10-01, RG wrote: > Again, you can't have it both ways. Either a warning is a "compiler > error" according to the claim at issue (see below) or it is not. If it > is, then this is a false positive. No, it isn't. It's a correctly identified type mismatch. You keep moving the goal posts from the actual standard of a false positive (the compiler warns that something is of the wrong type when it's not of the wrong type) to a made-up standard (the compiler warns that something is of the wrong type when it is indeed of the wrong type, but could be safely converted to the right type). It doesn't matter whether, in a given case, you *could* safely perform the conversion. If you don't perform the conversion, and the compiler points this out, that's not a false positive. >> Those goal posts are sorta red shifted at this point. > At this point I would like to quote a wise man who once said: >> May I suggest that, if you don't want to use words and terminology >> precisely, perhaps computer programming is not for you? > Red shifted? Moving away fast enough that their color has visibly changed. > The truth of this claim hinges on the definitions of "work", "never blow > up", "invalid", "call incorrectly" and "compile error." Define these > however you like, the result will be that the claim is either false or > vacuous. Not really. If you use the most obvious and natural meanings *for a statically typed language*, it is obvious that it is true. And indeed, significantly so. In the real world, programs written in scripting languages with runtime typing are fairly likely to throw occasional exceptions because something is of the wrong type. In a statically typed language, the of-the-wrong-type is something which can, by definition, be caught at compile time. The fundamental thing you seem to be getting stuck on is that you're assuming that if a conversion could be made, that it should be and it should be automatic and silent. That, however, is at odds with discussion of a statically typed language. There's a reason we have the option of converting things from one type to another. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Fri Oct 1 10:46:04 2010 From: usenet-nospam at seebs.net (Seebs) Date: 01 Oct 2010 14:46:04 GMT Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> <87tyl63cag.fsf@mail.geddis.org> Message-ID: On 2010-10-01, TheFlyingDutchman wrote: >> > ? ? ? ? in C I can have a function maximum(int a, int b) that will always >> > ? ? ? ? work. Never blow up, and never give an invalid answer. If someone >> > ? ? ? ? tries to call it incorrectly it is a compile error. >> I would agree that the third sentence is arguably wrong, simply >> because there's no such thing (outside #error) of a mandate to stop >> compiling. ?However, my understanding was that the dispute was over >> the second sentence, and that's certainly correct. > Why do you consider the term "compile error" a "mandate to stop > compiling"? Because that's what people normally mean -- compilation failed. > What do you say to refer to the situation when you have a > statement in your program that the compiler finds is an error? And is > it really material whether the compiler flagged an error and stopped, > or flagged an error and looked for additional errors??? It might be, because someone might argue that if the compiler will generate code for a bad construct, it hasn't really produced a "compiler error", just a warning. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Fri Oct 1 10:47:24 2010 From: usenet-nospam at seebs.net (Seebs) Date: 01 Oct 2010 14:47:24 GMT Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> <87tyl63cag.fsf@mail.geddis.org> <87wrq2l0k9.fsf@kuiper.lan.informatimago.com> Message-ID: On 2010-10-01, Pascal J. Bourguignon wrote: > Seebs writes: >> The obvious simple maximum() in C will not raise an exception nor return >> something which isn't an int in any program which is not on its face >> invalid in the call. This is by definite contrast with several of the >> interpreted languages, > This has nothing to do with the fact that these languages have > implementations using the interpreter pattern instead of a compiler. True, but it's a good enough statistical correlation to serve in many cases. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Fri Oct 1 10:49:36 2010 From: usenet-nospam at seebs.net (Seebs) Date: 01 Oct 2010 14:49:36 GMT Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> <8gk6o2Fc8aU2@mid.individual.net> <87lj6ikz7s.fsf@kuiper.lan.informatimago.com> Message-ID: On 2010-10-01, Pascal J. Bourguignon wrote: > static dynamic > > compiler detects wrong type fail at compile fails at run-time > (with exception > explaining this is > the wrong type) Unless, of course, the "wrong type" happens to be compatible enough to pass. In which case, it's unclear whether it is the "wrong type" or not. > compiler passes wrong type wrong result fails at run-time > (the programmer (with exception > spends hours explaining this is > finding the the wrong type) > problem) I have no clue what exact scenario you're talking about here. I've never seen a bug that could plausibly be described as "compiler passes wrong type" which wasn't picked up quickly by running with more warnings enabled. And on the other end of things, it is not always obvious or straightforward to figure out *why* the dynamic language has ended up with something of the wrong type, or what's wrong with that type. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From exarkun at twistedmatrix.com Fri Oct 1 11:21:04 2010 From: exarkun at twistedmatrix.com (Jean-Paul Calderone) Date: Fri, 1 Oct 2010 08:21:04 -0700 (PDT) Subject: Python becoming orphaned over ssh References: <4ca36e44$0$1584$742ec2ed@news.sonic.net> <91cdb1f0-5db1-4566-9899-386a7f06104d@y31g2000vbt.googlegroups.com> Message-ID: On Oct 1, 10:35?am, Antoine Pitrou wrote: > On Thu, 30 Sep 2010 07:01:09 -0700 (PDT) > > Jean-Paul Calderone wrote: > > > But signal dispositions are inherited by child processes. ?So you run > > ping from your short Python program, and it inherits SIGPIPE being > > ignored. ?And it's written in C, not Python, so when it writes to the > > pipe, there's no exception. ?So ping never gets any indication that it > > should exit. > > But doesn't write() fail with EPIPE in that situation? > That would mean `ping` ignores any error return from write(). > Quite so. A quick look at ping.c from iputils confirms this - there are many write() and fprintf() calls with no error handling. Jean-Paul From usenet-nospam at seebs.net Fri Oct 1 11:30:25 2010 From: usenet-nospam at seebs.net (Seebs) Date: 01 Oct 2010 15:30:25 GMT Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> <8gk6o2Fc8aU2@mid.individual.net> <4ca5a8c6$0$11112$c3e8da3@news.astraweb.com> Message-ID: On 2010-10-01, Steven D'Aprano wrote: > Now can we (by which I mean *you*) stop cross-posting C talk to multiple > newsgroups that don't have anything to do with C? Fair enough. The original thread does seem to have been crossposted in an innovative way. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rustompmody at gmail.com Fri Oct 1 11:38:10 2010 From: rustompmody at gmail.com (rustom) Date: Fri, 1 Oct 2010 08:38:10 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> <87tyl63cag.fsf@mail.geddis.org> <13ac95a0-c9f5-4f45-a94b-27d917ee4220@w15g2000pro.googlegroups.com> <87sk0qkzhz.fsf@kuiper.lan.informatimago.com> <4ca5ed80$0$23408$a729d347@news.telepac.pt> Message-ID: <4f77e84f-1eaa-469a-9456-8dbc14a1e8ab@t5g2000prd.googlegroups.com> On Oct 1, 7:17?pm, Rui Maciel wrote: > a) no language is inherently more or less efficient than any other language. ?The efficiency > aspect is only related to how those languages are implemented (i.e., the investments made in > optimizing the compilers/interpreters) I used to believe the same. But if you see Richard Bird's paper: More haste less speed http://www.comlab.ox.ac.uk/people/richard.bird/online/BirdJonesDeMoor1997More.pdf maybe you would rethink this position? From pjb at informatimago.com Fri Oct 1 12:07:30 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Fri, 01 Oct 2010 18:07:30 +0200 Subject: "Strong typing vs. strong testing" References: <87tyl63cag.fsf@mail.geddis.org> <13ac95a0-c9f5-4f45-a94b-27d917ee4220@w15g2000pro.googlegroups.com> <87sk0qkzhz.fsf@kuiper.lan.informatimago.com> <87zkuyjawh.fsf@kuiper.lan.informatimago.com> Message-ID: <87k4m1kibh.fsf@kuiper.lan.informatimago.com> "BartC" writes: > "Pascal J. Bourguignon" wrote in message > news:87zkuyjawh.fsf at kuiper.lan.informatimago.com... >> "BartC" writes: >> >>> "Pascal J. Bourguignon" wrote in message > >>>> When Intel will realize that 99% of its users are running VM >>> >>> Which one? >> >> Any implementation of a controlled environment is a virtual machine. >> Sometimes it is explicitely defined, such as in clisp, parot or jvm, but >> more often it is implicit, such as in sbcl, or worse, developed in an >> ad-hoc way in applications (eg. written in C++). > > But if you had to implement a VM directly in hardware, which one (of > the several varieties) would you choose? > > And having chosen one, how would that impact the performance of a > language with an incompatible VM? Indeed. C running on LispMachine, wasn't so fast. All this bit twiddling and pointer computing... But if that could be construed as a reason why to use dynamic languages (they run faster!) than C, it'd be all for the best! Otherwise we need to further go down the road of VM (cf. the hardware virtualization stream), down to the microcode. Again, it's because of the cheapness of microprocessors founders that we forgot for a long time the notion of microcode, which was found more often on big irons. Nowadays the biggest microprocessors are back on the track of microcode; this should be open, and virtual machines should be more routinely implemented in microcode. > Perhaps processors executing native code as it is now, aren't such a > bad idea. Perhaps if they had a more controlled execution model it would be a better idea. Remember that processors are like they are because C (and unix) is like it is! -- __Pascal Bourguignon__ http://www.informatimago.com/ From pjb at informatimago.com Fri Oct 1 12:18:59 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Fri, 01 Oct 2010 18:18:59 +0200 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> <8gk6o2Fc8aU2@mid.individual.net> <87lj6ikz7s.fsf@kuiper.lan.informatimago.com> Message-ID: <878w2hkhsc.fsf@kuiper.lan.informatimago.com> Seebs writes: > On 2010-10-01, Pascal J. Bourguignon wrote: >> static dynamic >> >> compiler detects wrong type fail at compile fails at run-time >> (with exception >> explaining this is >> the wrong type) > > Unless, of course, the "wrong type" happens to be compatible enough to > pass. In which case, it's unclear whether it is the "wrong type" or not. > >> compiler passes wrong type wrong result fails at run-time >> (the programmer (with exception >> spends hours explaining this is >> finding the the wrong type) >> problem) > > I have no clue what exact scenario you're talking about here. I've never > seen a bug that could plausibly be described as "compiler passes wrong > type" which wasn't picked up quickly by running with more warnings enabled. This is the scenario discussed in this thread, a long is passed to maximum without a compiler warning. > And on the other end of things, it is not always obvious or straightforward > to figure out *why* the dynamic language has ended up with something of the > wrong type, or what's wrong with that type. It is on the contrary rather obvious or easily discoverable, looking at the backtrace, and inspecting the data structures referenced from it. -- __Pascal Bourguignon__ http://www.informatimago.com/ From brian.curtin at gmail.com Fri Oct 1 12:26:09 2010 From: brian.curtin at gmail.com (Brian Curtin) Date: Fri, 1 Oct 2010 11:26:09 -0500 Subject: discussion In-Reply-To: <31a08825-bb72-4e9f-8710-a39fe2bc9216@u31g2000pru.googlegroups.com> References: <31a08825-bb72-4e9f-8710-a39fe2bc9216@u31g2000pru.googlegroups.com> Message-ID: On Thu, Sep 30, 2010 at 21:12, Geo_subodh wrote: > please send me the simple python code that uses input number greater > than3 digits(>3 digits) and checks whether the number is palindrome > or not. $ cat homework.py raise NotImplementedError -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Fri Oct 1 12:43:21 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 01 Oct 2010 17:43:21 +0100 Subject: __file__ is sometimes absolute, sometimes relative References: Message-ID: <87hbh5vp7a.fsf@gmail.com> S?bastien Barth?lemy writes: > Hello, Hi! > I use a data file that lies on disk in the same directory that the > module which makes use of it. > > The data file is checked in the repository and gets installed by > the distutils ``package_data`` directive, so it is in place both > during development and after and install. > > In my program, I need to find the absolute path to this data file. > > I could think of 3 ways to do this: > 1. using the __path__ property in the module > 2. using __file__ property in the module > 3. using __file__ and os.getcwd() in the module I have used the following, but I don't know either if it is a good way: os.path.dirname(os.path.realpath(__file__)) -- Arnaud From emile at fenx.com Fri Oct 1 12:44:34 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 01 Oct 2010 09:44:34 -0700 Subject: sequence multiplied by -1 In-Reply-To: <20101001125652.GC2144@rcpc42.vub.ac.be> References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> <7x4odcc426.fsf@ruckus.brouhaha.com> <20100930121043.GD2272@rcpc42.vub.ac.be> <20101001125652.GC2144@rcpc42.vub.ac.be> Message-ID: On 10/1/2010 5:56 AM Antoon Pardon said... > Someone provides you with a library of functions that act on sequences. > They rely on the fact that '+' concatenates. > > Someone else provides you with a library of functions that act on > numbers. They rely on the fact that '+' provides addition. > But you can do that now -- you just can't have a class that provides _both_ behaviors. >>> class Addem: ... def __init__(self,val): ... self.val = val ... def __add__(self,other): ... return self.val + other ... >>> class Concatem: ... def __init__(self,val): ... self.val = val ... def __add__(self,other): ... return "%s%s" % (self.val,other) ... >>> >>> a = Addem(7) >>> a+4 11 >>> >>> b = Concatem(7) >>> b+4 '74' Emile From ukpeople01 at gmail.com Fri Oct 1 12:49:01 2010 From: ukpeople01 at gmail.com (maha) Date: Fri, 1 Oct 2010 09:49:01 -0700 (PDT) Subject: See Hot Sexy Star *Kunjal Desai Sex Videos Message-ID: <38016593-e06c-4aa8-8da6-950aa6aaca8c@l38g2000pro.googlegroups.com> See Hot Sexy Star *Kunjal Desai Sex Videos Athttp://austrianews.co.cc Due to high sex content, i have hidden the videos in an image. in that website on Right side below search box click on image and watch videos in all angles. From nagle at animats.com Fri Oct 1 12:52:36 2010 From: nagle at animats.com (John Nagle) Date: Fri, 01 Oct 2010 09:52:36 -0700 Subject: "Strong typing vs. strong testing" In-Reply-To: <4ca5ed80$0$23408$a729d347@news.telepac.pt> References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> <87tyl63cag.fsf@mail.geddis.org> <13ac95a0-c9f5-4f45-a94b-27d917ee4220@w15g2000pro.googlegroups.com> <87sk0qkzhz.fsf@kuiper.lan.informatimago.com> <4ca5ed80$0$23408$a729d347@news.telepac.pt> Message-ID: <4ca611f6$0$1608$742ec2ed@news.sonic.net> On 10/1/2010 7:17 AM, Rui Maciel wrote: > Pascal J. Bourguignon wrote: > >> Nothing extraordinary here. Common Lisp is more efficient than C. >> http://www.lrde.epita.fr/~didier/research/verna.06.ecoop.pdf >> http://portal.acm.org/citation.cfm?id=1144168 > > I don't know if you are intentionally trying to be deceitful or if you honestly didn't spent much > time thinking about this issue. To be brief I will only point out the following topics: > > > a) no language is inherently more or less efficient than any other language. The efficiency > aspect is only related to how those languages are implemented (i.e., the investments made in > optimizing the compilers/interpreters) > b) Just because someone invested enough effort to optimize a specific implementation of language X > to run, under a specific scenario, a benchmark faster than some other implementation of language Y > it doesn't mean that language X's implementation outperforms or even matches every implementation > of language Y under every conceivable scenario. If the implementation has an omniscient compiler, yes. If not, some languages have serious speed penalties. Python has some inherent performance problems stemming from its "gratuitous hidden dynamism". That is, there are bits of dynamism which are very unlikely, but not visible at compile time, and thus very difficult to optimize out. For example, it's possible to add an attribute to an object from outside the object's class. It's thus very difficult to detect at compile time which classes could use static "slots", and which could not. Python allows replacing a function at run time, even while another thread is executing in it. (Even PHP disallows that.) This breaks a wide range of optimizations. And then, of course, there's the "global interpreter lock" problem. Dynamism is not the problem. It's hidden dynamism, which forces compiling for the worst case all the time, that's the problem. Most of these problems come from CPython, which is a naive interpreter. The feature set of Python is well matched to a naive interpreter. The organizational situation is a lot like the one with Pascal and Wirth. There'a a very straightforward way to write a recursive-descent Pascal compiler that compiles to a stack notation. Wirth wrote one of those, and insisted that the language should be very close to what a compiler of that form can do. This eventually killed Pascal. John Nagle From emile at fenx.com Fri Oct 1 12:55:25 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 01 Oct 2010 09:55:25 -0700 Subject: sequence multiplied by -1 In-Reply-To: References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> <7x4odcc426.fsf@ruckus.brouhaha.com> <20100930121043.GD2272@rcpc42.vub.ac.be> <20101001125652.GC2144@rcpc42.vub.ac.be> Message-ID: On 10/1/2010 9:44 AM Emile van Sebille said... > On 10/1/2010 5:56 AM Antoon Pardon said... > >> Someone provides you with a library of functions that act on sequences. >> They rely on the fact that '+' concatenates. >> >> Someone else provides you with a library of functions that act on >> numbers. They rely on the fact that '+' provides addition. >> > > But you can do that now -- you just can't have a class that provides > _both_ behaviors. Well, you can, but that's why you don't... >>> class Guess: ... def __init__(self,val): ... self.val = val ... def __add__(self,other): ... try: ... other / 1 ... return self.val + other ... except: ... return "%s%s" % (self.val,other) ... >>> c = Guess(7) >>> c+4 11 >>> c+"4" '74' Emile > > >>> class Addem: > ... def __init__(self,val): > ... self.val = val > ... def __add__(self,other): > ... return self.val + other > ... > >>> class Concatem: > ... def __init__(self,val): > ... self.val = val > ... def __add__(self,other): > ... return "%s%s" % (self.val,other) > ... > >>> > >>> a = Addem(7) > >>> a+4 > 11 > >>> > >>> b = Concatem(7) > >>> b+4 > '74' > > > Emile > From usenet-nospam at seebs.net Fri Oct 1 12:58:02 2010 From: usenet-nospam at seebs.net (Seebs) Date: 01 Oct 2010 16:58:02 GMT Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> <8gk6o2Fc8aU2@mid.individual.net> <87lj6ikz7s.fsf@kuiper.lan.informatimago.com> <878w2hkhsc.fsf@kuiper.lan.informatimago.com> Message-ID: On 2010-10-01, Pascal J. Bourguignon wrote: > Seebs writes: >> On 2010-10-01, Pascal J. Bourguignon wrote: >>> compiler passes wrong type wrong result fails at run-time >>> (the programmer (with exception >>> spends hours explaining this is >>> finding the the wrong type) >>> problem) > >> I have no clue what exact scenario you're talking about here. I've never >> seen a bug that could plausibly be described as "compiler passes wrong >> type" which wasn't picked up quickly by running with more warnings enabled. > This is the scenario discussed in this thread, a long is passed to > maximum without a compiler warning. The compiler didn't pass the wrong type, the user did. >> And on the other end of things, it is not always obvious or straightforward >> to figure out *why* the dynamic language has ended up with something of the >> wrong type, or what's wrong with that type. > It is on the contrary rather obvious or easily discoverable, looking at > the backtrace, and inspecting the data structures referenced from it. This is a fascinating assertion, but it is slightly marred by not actually being generally true. It's often the case that it's pretty obvious, but sometimes it's not so obvious -- it can take quite a bit of doing to figure out how or where some hunk of a data structure got set up wrong. It's very easy to find the call where a nil was passed to something expecting some kind of integer; it's sometimes not so easy to find the completely unrelated hunk of code which modified the data structure half an hour earlier. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From tjreedy at udel.edu Fri Oct 1 13:02:17 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 01 Oct 2010 13:02:17 -0400 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> <87tyl63cag.fsf@mail.geddis.org> Message-ID: On 10/1/2010 2:28 AM, TheFlyingDutchman wrote: > >>> in C I can have a function maximum(int a, int b) that will always >>> work. Never blow up, and never give an invalid answer. If someone >>> tries to call it incorrectly it is a compile error. >> >> I would agree that the third sentence is arguably wrong, simply >> because there's no such thing (outside #error) of a mandate to stop >> compiling. However, my understanding was that the dispute was over >> the second sentence, and that's certainly correct. >> > Why do you consider the term "compile error" a "mandate to stop > compiling"? What do you say to refer to the situation when you have a > statement in your program that the compiler finds is an error? And is > it really material whether the compiler flagged an error and stopped, > or flagged an error and looked for additional errors??? For the purpose of the argument, I do not think it matters whether the compiler looks for additional errors before it stops compiling. More to to point is whether or not it eventually produces an object file that can be linked into an executable file. 'Compile error' (as opposed to 'compile warning') should mean that it does not. -- Terry Jan Reedy From pavlovevidence at gmail.com Fri Oct 1 13:24:11 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 1 Oct 2010 10:24:11 -0700 (PDT) Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> <7x4odcc426.fsf@ruckus.brouhaha.com> Message-ID: <4cf6455f-c181-44ea-9424-ce52761eb886@j24g2000yqa.googlegroups.com> On Sep 26, 8:20?am, Grant Edwards wrote: > On 2010-09-26, Paul Rubin wrote: > > > Steven D'Aprano writes: > >> There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", > > Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"? > > Because > > 3 * "spam" == "spam" + "spam" + "spam" > > Just like > > 3 * 6 = 6 + 6 + 6 > > So now I suppose "+" for string concatenation is a bad thing. Yes. It's not the end of the world, but a separate concatenation operator would have been better. Then there's no temptation to special case a failure of sum(list_of_strings), because it's not a sum any more. As for repeat, I can't personally think of a time I ever repeated anything but a single item, and that only rarely. It's not useful enough to deserve its own syntax, and the language wouldn't have suffered one bit if it had been a method of sequences. Carl Banks Carl Banks From pjb at informatimago.com Fri Oct 1 13:36:18 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Fri, 01 Oct 2010 19:36:18 +0200 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> <8gk6o2Fc8aU2@mid.individual.net> <87lj6ikz7s.fsf@kuiper.lan.informatimago.com> <878w2hkhsc.fsf@kuiper.lan.informatimago.com> Message-ID: <87vd5lizn1.fsf@kuiper.lan.informatimago.com> Seebs writes: > On 2010-10-01, Pascal J. Bourguignon wrote: >> Seebs writes: >>> On 2010-10-01, Pascal J. Bourguignon wrote: >>>> compiler passes wrong type wrong result fails at run-time >>>> (the programmer (with exception >>>> spends hours explaining this is >>>> finding the the wrong type) >>>> problem) >> >>> I have no clue what exact scenario you're talking about here. I've never >>> seen a bug that could plausibly be described as "compiler passes wrong >>> type" which wasn't picked up quickly by running with more warnings enabled. > >> This is the scenario discussed in this thread, a long is passed to >> maximum without a compiler warning. > > The compiler didn't pass the wrong type, the user did. And the compiler passed it on without saying anything. >>> And on the other end of things, it is not always obvious or straightforward >>> to figure out *why* the dynamic language has ended up with something of the >>> wrong type, or what's wrong with that type. > >> It is on the contrary rather obvious or easily discoverable, looking at >> the backtrace, and inspecting the data structures referenced from it. > > This is a fascinating assertion, but it is slightly marred by not actually > being generally true. It's often the case that it's pretty obvious, but > sometimes it's not so obvious -- it can take quite a bit of doing to figure > out how or where some hunk of a data structure got set up wrong. It's very > easy to find the call where a nil was passed to something expecting some kind > of integer; it's sometimes not so easy to find the completely unrelated hunk > of code which modified the data structure half an hour earlier. When debugging C program, you are perfectly right. But I don't observe the same when debugging lisp programs. -- __Pascal Bourguignon__ http://www.informatimago.com/ From nagle at animats.com Fri Oct 1 14:23:25 2010 From: nagle at animats.com (John Nagle) Date: Fri, 01 Oct 2010 11:23:25 -0700 Subject: if the else short form In-Reply-To: <16a5c344-b6fb-4da1-b07b-b4168bdda2f7@x42g2000yqx.googlegroups.com> References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> <20100930132231.6f51b2a6@geekmail.INVALID> <16a5c344-b6fb-4da1-b07b-b4168bdda2f7@x42g2000yqx.googlegroups.com> Message-ID: <4ca6273f$0$1621$742ec2ed@news.sonic.net> On 10/1/2010 12:42 AM, bruno.desthuilliers at gmail.com wrote: > On 30 sep, 19:22, Andreas Waldenburger > wrote: >> On Thu, 30 Sep 2010 03:42:29 -0700 (PDT) >> >> "bruno.desthuilli... at gmail.com" wrote: >>> On 29 sep, 19:20, Seebs wrote: >>>> On 2010-09-29, Tracubik wrote: >>>>> button = gtk.Button(("False,", "True,")[fill==True]) >> >>>> Oh, what a nasty idiom. >> >>> Well, it's not very different from dict-based dispatch , which is the >>> core of OO polymorphic dispatch in quite a few dynamic OOPLs. >> >>> Anyway, it's a common Python idiom and one that's not specially hard >>> to grasp so I don't see any legibility problem here. >> >> But it does violate the "explicit is better than implicit" tenet, don't >> you think? > > Why so ? The doc clearly states that booleans are integers with True > == 1 and False == 0, so there's nothing implicit here. Python "bool" values are NOT integers. They can be coerced to integers for historical reasons. But "str(True)" is "True". The above could be better written as button = gtk.Button(str(fill)) John Nagle From ian-news at hotmail.com Fri Oct 1 14:30:31 2010 From: ian-news at hotmail.com (Ian Collins) Date: Sat, 02 Oct 2010 07:30:31 +1300 Subject: "Strong typing vs. strong testing" In-Reply-To: <878w2hkhsc.fsf@kuiper.lan.informatimago.com> References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> <8gk6o2Fc8aU2@mid.individual.net> <87lj6ikz7s.fsf@kuiper.lan.informatimago.com> <878w2hkhsc.fsf@kuiper.lan.informatimago.com> Message-ID: <8gmnm7Fc8aU6@mid.individual.net> On 10/ 2/10 05:18 AM, Pascal J. Bourguignon wrote: > Seebs writes: > >> On 2010-10-01, Pascal J. Bourguignon wrote: >>> static dynamic >>> >>> compiler detects wrong type fail at compile fails at run-time >>> (with exception >>> explaining this is >>> the wrong type) >> >> Unless, of course, the "wrong type" happens to be compatible enough to >> pass. In which case, it's unclear whether it is the "wrong type" or not. >> >>> compiler passes wrong type wrong result fails at run-time >>> (the programmer (with exception >>> spends hours explaining this is >>> finding the the wrong type) >>> problem) >> >> I have no clue what exact scenario you're talking about here. I've never >> seen a bug that could plausibly be described as "compiler passes wrong >> type" which wasn't picked up quickly by running with more warnings enabled. > > This is the scenario discussed in this thread, a long is passed to > maximum without a compiler warning. Which will cause the test for the bit of code doing the call to fail. So it fails at run-time with a failed test, just as it would in a dynamic language. -- Ian Collins From rNOSPAMon at flownet.com Fri Oct 1 14:33:45 2010 From: rNOSPAMon at flownet.com (RG) Date: Fri, 01 Oct 2010 11:33:45 -0700 Subject: "Strong typing vs. strong testing" References: <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: In article , Seebs wrote: > On 2010-10-01, RG wrote: > > Again, you can't have it both ways. Either a warning is a "compiler > > error" according to the claim at issue (see below) or it is not. If it > > is, then this is a false positive. > > No, it isn't. It's a correctly identified type mismatch. > > You keep moving the goal posts from the actual standard of a false positive > (the compiler warns that something is of the wrong type when it's not of > the wrong type) to a made-up standard (the compiler warns that something is > of the wrong type when it is indeed of the wrong type, but could be safely > converted to the right type). > > It doesn't matter whether, in a given case, you *could* safely perform > the conversion. If you don't perform the conversion, and the compiler points > this out, that's not a false positive. > > >> Those goal posts are sorta red shifted at this point. > > > At this point I would like to quote a wise man who once said: > > >> May I suggest that, if you don't want to use words and terminology > >> precisely, perhaps computer programming is not for you? > > > Red shifted? > > Moving away fast enough that their color has visibly changed. > > > The truth of this claim hinges on the definitions of "work", "never blow > > up", "invalid", "call incorrectly" and "compile error." Define these > > however you like, the result will be that the claim is either false or > > vacuous. > > Not really. If you use the most obvious and natural meanings *for a > statically typed language*, it is obvious that it is true. > > And indeed, significantly so. In the real world, programs written in > scripting languages with runtime typing are fairly likely to throw occasional > exceptions because something is of the wrong type. In a statically typed > language, the of-the-wrong-type is something which can, by definition, be > caught at compile time. > > The fundamental thing you seem to be getting stuck on is that you're assuming > that if a conversion could be made, that it should be and it should be > automatic and silent. That, however, is at odds with discussion of a > statically typed language. There's a reason we have the option of converting > things from one type to another. No, this is not what I'm getting stuck on. I understand the technical theory behind statically typed languages. What I'm getting "stuck" on is this: > In a statically typed language, the of-the-wrong-type is something which > can, by definition, be caught at compile time. Any time something is true "by definition" that is an indication that it's not a particularly useful fact. The whole concept of "type" is a red herring. It's like this: there are some properties of programs that can be determined statically, and others that can't. Some of the properties that can't be determined statically matter in practice. But all of the properties that can be determined statically can also be determined dynamically. The *only* advantage that static analysis has is that *sometimes* it can determine *some* properties of a program faster or with less effort than a dynamic approach would. What I take issue with is the implication made by advocates of static analysis that static analysis is somehow *inherently* superior to dynamic analysis, that static analysis can provide some sort of "guarantee" of reliability that actually has some sort of practical meaning in the real world. It doesn't. The net effect of static analysis in the real world is to make programmers complacent about properties of programs that can only be determined at run time, to make them think that compiling without errors means something, and that if a program compiles without errors then there is no need for run-time checking of any sort. *You* may not believe these things, but the vast majority of programmers who use statically typed languages do believe these things, even if only tacitly. The result is a world where software by and large is a horrific mess of stack overflows, null pointer exceptions, core dumps, and security holes. I'm not saying that static analysis is not useful. It is. What I'm saying is that static analysis is nowhere near as useful as its advocates like to imply that it is. And it's better to forego static analysis and *know* that you're flying without a net at run-time than to use it and think that you're safe when you're really not. rg From kst-u at mib.org Fri Oct 1 14:41:40 2010 From: kst-u at mib.org (Keith Thompson) Date: Fri, 01 Oct 2010 11:41:40 -0700 Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> <87tyl63cag.fsf@mail.geddis.org> Message-ID: Seebs writes: > On 2010-10-01, TheFlyingDutchman wrote: >>> > ? ? ? ? in C I can have a function maximum(int a, int b) that will always >>> > ? ? ? ? work. Never blow up, and never give an invalid answer. If someone >>> > ? ? ? ? tries to call it incorrectly it is a compile error. > >>> I would agree that the third sentence is arguably wrong, simply >>> because there's no such thing (outside #error) of a mandate to stop >>> compiling. ?However, my understanding was that the dispute was over >>> the second sentence, and that's certainly correct. > >> Why do you consider the term "compile error" a "mandate to stop >> compiling"? > > Because that's what people normally mean -- compilation failed. At least for C, I'd say it refers to a syntax error or constraint violation, i.e., something that requires a diagnostic. [...] -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From kst-u at mib.org Fri Oct 1 14:44:47 2010 From: kst-u at mib.org (Keith Thompson) Date: Fri, 01 Oct 2010 11:44:47 -0700 Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> <87tyl63cag.fsf@mail.geddis.org> Message-ID: TheFlyingDutchman writes: > On Sep 30, 10:37?pm, RG wrote: >> In article <87tyl63cag.... at mail.geddis.org>, >> ?Don Geddis wrote: >> > Keith Thompson wrote on Thu, 30 Sep 2010: >> > > RG writes: >> > >> You're missing a lot of context. ?I'm not trying to criticize C, just to >> > >> refute a false claim that was made about it. >> > > Can you cite the article that made this false claim, and exactly what >> > > the false claim was? >> >> >http://groups.google.com/group/comp.lang.lisp/msg/431925448da59481 >> >> > ? ? ? ? Message-ID: >> > ? ? ? ? <0497e39d-6bd1-429d-a86f-f4c89babe... at u31g2000pru.googlegroups.com> >> > ? ? ? ? From: TheFlyingDutchman >> > ? ? ? ? Newsgroups: comp.lang.lisp >> >> > ? ? ? ? [...] >> > ? ? ? ? in C I can have a function maximum(int a, int b) that will always >> > ? ? ? ? work. Never blow up, and never give an invalid answer. If someone >> > ? ? ? ? tries to call it incorrectly it is a compile error. >> > ? ? ? ? [...] That was slightly overstated. In fact, you can have such a function that will always work when called correctly, *unless* something else has caused the program's behavior to be undefined, in which case all bets are off. [...] > Thanks from me as well, Don. I was worried that people would start to > believe that the original statement was what you said it was: > > "I'm not even saying it's a flaw in the language. All I'm saying is > that > the original claim -- that any error in a C program will be caught by > the compiler -- is false, and more specifically, that it can be > demonstrated to be false without appeal to unknown run-time input." Yes, that would have been an absurd claim if anyone had actually made it. -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From ethan at stoneleaf.us Fri Oct 1 14:46:46 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 01 Oct 2010 11:46:46 -0700 Subject: if the else short form In-Reply-To: <4ca6273f$0$1621$742ec2ed@news.sonic.net> References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> <20100930132231.6f51b2a6@geekmail.INVALID> <16a5c344-b6fb-4da1-b07b-b4168bdda2f7@x42g2000yqx.googlegroups.com> <4ca6273f$0$1621$742ec2ed@news.sonic.net> Message-ID: <4CA62C96.2030307@stoneleaf.us> John Nagle wrote: > On 10/1/2010 12:42 AM, bruno.desthuilliers at gmail.com wrote: >> On 30 sep, 19:22, Andreas Waldenburger >> wrote: >>> >>> But it does violate the "explicit is better than implicit" tenet, don't >>> you think? >> >> Why so ? The doc clearly states that booleans are integers with True >> == 1 and False == 0, so there's nothing implicit here. > > Python "bool" values are NOT integers. They can be coerced to > integers for historical reasons. But "str(True)" is "True". Okay, so they are *subtypes* of integers, to be precise... but what, exactly, does the string representation of an object have to do with its type? ~Ethan~ From kst-u at mib.org Fri Oct 1 14:58:26 2010 From: kst-u at mib.org (Keith Thompson) Date: Fri, 01 Oct 2010 11:58:26 -0700 Subject: "Strong typing vs. strong testing" References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: RG writes: > In article , > Seebs wrote: > >> On 2010-09-30, RG wrote: >> > That gives (what I would consider to be) false positives, e.g.: >> >> > [ron at mighty:~]$ cat foo.c >> >> > void foo(long x) {} >> >> > int main() { foo(1); } >> > [ron at mighty:~]$ gcc -Wconversion foo.c >> > foo.c: In function ???main???: >> > foo.c:4: warning: passing argument 1 of ???foo??? with different width due >> > to prototype >> >> But it's *not* a false positive. The compiler is not claiming that the >> conversion couldn't be done -- it's just telling you that there is a >> change of type going on. > > Again, you can't have it both ways. Either a warning is a "compiler > error" according to the claim at issue (see below) or it is not. If it > is, then this is a false positive. If it is not, then my previous > example refutes the claim. [...] In this case, the conversion (from int to long) cannot fail (barring undefined behavior elsewhere in the program), because long is guaranteed to be able to hold any value within the range of int. It would be reasonable, at least as an option, to warn only about conversions that can fail, or only about conversions that can lose information, perhaps distinguishing between implicit conversions and explicit conversions (casts). Even the warning about foo(1) is not entirely unreasonable; some programmers might prefer to write foo(1L) rather than foo(1), to make it clear that the argument being passed is of type long rather than int. I don't know whether gcc provides this level of control over which conversions it warns about, but again, that's a gcc issue, not a C issue. -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From barthelemy at crans.org Fri Oct 1 15:00:02 2010 From: barthelemy at crans.org (=?ISO-8859-1?Q?S=E9bastien_Barth=E9lemy?=) Date: Fri, 1 Oct 2010 21:00:02 +0200 Subject: __file__ is sometimes absolute, sometimes relative In-Reply-To: <87hbh5vp7a.fsf@gmail.com> References: <87hbh5vp7a.fsf@gmail.com> Message-ID: Hi, Arnaud, Christian, thank you for your help. I'll use abspath, it's shorter. Any idea why it's sometimes absolute, sometimes not? From kst-u at mib.org Fri Oct 1 15:01:59 2010 From: kst-u at mib.org (Keith Thompson) Date: Fri, 01 Oct 2010 12:01:59 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> <8gk6o2Fc8aU2@mid.individual.net> <87lj6ikz7s.fsf@kuiper.lan.informatimago.com> <878w2hkhsc.fsf@kuiper.lan.informatimago.com> <87vd5lizn1.fsf@kuiper.lan.informatimago.com> Message-ID: pjb at informatimago.com (Pascal J. Bourguignon) writes: > Seebs writes: >> On 2010-10-01, Pascal J. Bourguignon wrote: >>> Seebs writes: >>>> On 2010-10-01, Pascal J. Bourguignon wrote: >>>>> compiler passes wrong type wrong result fails at run-time >>>>> (the programmer (with exception >>>>> spends hours explaining this is >>>>> finding the the wrong type) >>>>> problem) >>> >>>> I have no clue what exact scenario you're talking about here. I've never >>>> seen a bug that could plausibly be described as "compiler passes wrong >>>> type" which wasn't picked up quickly by running with more warnings enabled. >> >>> This is the scenario discussed in this thread, a long is passed to >>> maximum without a compiler warning. >> >> The compiler didn't pass the wrong type, the user did. > > And the compiler passed it on without saying anything. Because the user didn't use the option (-Wconversion) that would have caused the compiler to warn about it. [...] -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From pakalk at gmail.com Fri Oct 1 15:07:09 2010 From: pakalk at gmail.com (pakalk) Date: Fri, 1 Oct 2010 12:07:09 -0700 (PDT) Subject: IMAP support Message-ID: <13ee8219-5925-4978-ba89-83ee0f7b7820@30g2000yqm.googlegroups.com> Hello, Can anyone help me find GOOD IMAP library for python? Imaplib is.. ekhm... nevermind... Is there any good library? From ethan at stoneleaf.us Fri Oct 1 15:15:01 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 01 Oct 2010 12:15:01 -0700 Subject: difference between %s and %d Message-ID: <4CA63335.1010001@stoneleaf.us> If I'm printing the number 735, or any other positive or negative integer, is there any difference between %7s and %7d? ~Ethan~ From solipsis at pitrou.net Fri Oct 1 15:22:19 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 1 Oct 2010 21:22:19 +0200 Subject: __file__ is sometimes absolute, sometimes relative References: <87hbh5vp7a.fsf@gmail.com> Message-ID: <20101001212219.678fad9a@pitrou.net> On Fri, 1 Oct 2010 21:00:02 +0200 S?bastien Barth?lemy wrote: > Hi, > > Arnaud, Christian, thank you for your help. > > I'll use abspath, it's shorter. > > Any idea why it's sometimes absolute, sometimes not? AFAICT, that's because sys.path contains some absolute paths and some relative ones. Regards Antoine. From invalid at invalid.invalid Fri Oct 1 15:25:35 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 1 Oct 2010 19:25:35 +0000 (UTC) Subject: difference between %s and %d References: Message-ID: On 2010-10-01, Ethan Furman wrote: > If I'm printing the number 735, or any other positive or negative > integer, is there any difference between %7s and %7d? Let's ask Python: >>> [n for n in range(-99999999,99999999,123) if ("%7d" % n) != ("%7s" % n)] [] >>> [n for n in range(-99999,99999) if ("%7d" % n) != ("%7s" % n)] [] Apparently not. -- Grant Edwards grant.b.edwards Yow! What I want to find at out is -- do parrots know gmail.com much about Astro-Turf? From python at mrabarnett.plus.com Fri Oct 1 15:38:52 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 01 Oct 2010 20:38:52 +0100 Subject: difference between %s and %d In-Reply-To: <4CA63335.1010001@stoneleaf.us> References: <4CA63335.1010001@stoneleaf.us> Message-ID: <4CA638CC.9080000@mrabarnett.plus.com> On 01/10/2010 20:15, Ethan Furman wrote: > If I'm printing the number 735, or any other positive or negative > integer, is there any difference between %7s and %7d? > "%s" uses str(). In Python 2.7: >>> class MyInt(int): ... def __init__(self, value): ... int.__init__(self, value) ... def __str__(self): ... return "MyInt(%d)" % self ... >>> MyInt(735) 735 >>> "%7d" % MyInt(735) ' 735' >>> "%7s" % MyInt(735) 'MyInt(735)' From ethan at stoneleaf.us Fri Oct 1 15:51:27 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 01 Oct 2010 12:51:27 -0700 Subject: difference between %s and %d In-Reply-To: <4CA63335.1010001@stoneleaf.us> References: <4CA63335.1010001@stoneleaf.us> Message-ID: <4CA63BBF.2080504@stoneleaf.us> Ethan Furman wrote: > If I'm printing the number 735, or any other positive or negative > integer, is there any difference between %7s and %7d? Grant Edwards wrote: > Let's ask Python: > > --> [n for n in range(-99999999,99999999,123) if ("%7d" % n) > != ("%7s" % n)] > [] > > --> [n for n in range(-99999,99999) if ("%7d" % n) != ("%7s" % n)] > [] > > Apparently not. MRAB wrote: > "%s" uses str(). In Python 2.7: > > --> class MyInt(int): > ... def __init__(self, value): > ... int.__init__(self, value) > ... def __str__(self): > ... return "MyInt(%d)" % self > ... > --> MyInt(735) > 735 > --> "%7d" % MyInt(735) > ' 735' > --> "%7s" % MyInt(735) > 'MyInt(735)' Thanks! Both enlightening answers. ~Ethan~ From tekion at gmail.com Fri Oct 1 16:32:49 2010 From: tekion at gmail.com (tekion) Date: Fri, 1 Oct 2010 13:32:49 -0700 (PDT) Subject: ElementTree handling nested tag Message-ID: All, I have the following xml tag: httpRequest HTTP://cmd.wma.ibm.com:80/ GET 200 I am interested in: httpRequest HTTP://cmd.wma.ibm.com:80/ GET 200 as well as the upper layer tag. How do I get at the nest tag listed above? Thanks. From bc at freeuk.com Fri Oct 1 16:47:02 2010 From: bc at freeuk.com (BartC) Date: Fri, 1 Oct 2010 21:47:02 +0100 Subject: "Strong typing vs. strong testing" In-Reply-To: <87sk0qkzhz.fsf@kuiper.lan.informatimago.com> References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com><0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com><9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com><996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com><07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com><0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> <87tyl63cag.fsf@mail.geddis.org><13ac95a0-c9f5-4f45-a94b-27d917ee4220@w15g2000pro.googlegroups.com> <87sk0qkzhz.fsf@kuiper.lan.informatimago.com> Message-ID: "Pascal J. Bourguignon" wrote in message news:87sk0qkzhz.fsf at kuiper.lan.informatimago.com... > Nothing extraordinary here. Common Lisp is more efficient than C. > http://www.lrde.epita.fr/~didier/research/verna.06.ecoop.pdf > http://portal.acm.org/citation.cfm?id=1144168 > > Actually, it's hard to find a language that has no compiler generating > faster code than C... I had a quick look at Lisp to see if your claims had any basis. I tried this program: (defun fib (n) (if (< n 2) n (+ n (fib (- n 1)) (fib (- n 2)) ) )) But it gave the wrong results and it took ages to figure out why. Even after downloading a working version for comparison, it's was difficult to spot the extraneous 'n' (I think I was concentrating on getting the round brackets all in the right places). I thought you were saying that Lisp (and dynamic typing in general) was better for pointing out errors? The above error in C would have been picked up more easily I think (due to less parentheses clutter, and more obvious separators between terms). As for speed, executing fib(38) took about 60 seconds on my machine (gnu clisp with no switches set). (Compared with 3.5 seconds, for my own interpreted, dynamic language, and 0.6 seconds for C.) -- bartc From arnodel at gmail.com Fri Oct 1 17:01:50 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 01 Oct 2010 22:01:50 +0100 Subject: difference between %s and %d References: Message-ID: <87sk0pr5j5.fsf@gmail.com> Ethan Furman writes: > If I'm printing the number 735, or any other positive or negative > integer, is there any difference between %7s and %7d? > > ~Ethan~ To link with another thread: >>> "%s" % True 'True' >>> "%d" % True '1' -- Arnaud From pjb at informatimago.com Fri Oct 1 17:02:55 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Fri, 01 Oct 2010 23:02:55 +0200 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> <87tyl63cag.fsf@mail.geddis.org> <13ac95a0-c9f5-4f45-a94b-27d917ee4220@w15g2000pro.googlegroups.com> <87sk0qkzhz.fsf@kuiper.lan.informatimago.com> Message-ID: <877hi1iq2o.fsf@kuiper.lan.informatimago.com> "BartC" writes: > "Pascal J. Bourguignon" wrote in message > news:87sk0qkzhz.fsf at kuiper.lan.informatimago.com... > >> Nothing extraordinary here. Common Lisp is more efficient than C. >> http://www.lrde.epita.fr/~didier/research/verna.06.ecoop.pdf >> http://portal.acm.org/citation.cfm?id=1144168 >> >> Actually, it's hard to find a language that has no compiler generating >> faster code than C... > > I had a quick look at Lisp to see if your claims had any basis. I > tried this program: > > (defun fib (n) > (if (< n 2) > n > (+ n (fib (- n 1)) (fib (- n 2)) ) > )) > > But it gave the wrong results and it took ages to figure out why. Even > after downloading a working version for comparison, it's was difficult > to spot the extraneous 'n' (I think I was concentrating on getting the > round brackets all in the right places). > > I thought you were saying that Lisp (and dynamic typing in general) > was better for pointing out errors? The above error in C would have > been picked up more easily I think (due to less parentheses clutter, > and more obvious separators between terms). There are more parentheses in C (you must take into account {} and [] too, and <> in C++), and the additionnal separators in C are clutter. > As for speed, executing fib(38) took about 60 seconds on my machine > (gnu clisp with no switches set). Yes, you choosed the ONLY CL implementation having an interpreter by default, and which when compiling, compiles to a virtual machine. This happens also to be my favorite CL implementation, which tells you how much I care about those silly time benchmarks. If you want to try a CL implementation generating faster code, try SBCL. > (Compared with 3.5 seconds, for my > own interpreted, dynamic language, and 0.6 seconds for C.) -- __Pascal Bourguignon__ http://www.informatimago.com/ From flebber.crue at gmail.com Fri Oct 1 18:14:13 2010 From: flebber.crue at gmail.com (flebber) Date: Fri, 1 Oct 2010 15:14:13 -0700 (PDT) Subject: Crummy BS Script Message-ID: I have a simple question regarding the Beuatiful soup crummy script. The last line is f.write('%s, %s, %s, %s, %s \n' % (i, t[0], t[1], t[2], t[3])), But where is this saving the imported file and under what name? #!/usr/bin/env python # ogm-sampples.py # Author: Matt Mayes # March 11, 2008 """ -- This requires the Beautiful Soup mod: http://www.crummy.com/software/BeautifulSoup/ -- Steps: 1. Identify all