Re: newbie question
On Fri, 1 Apr 2011 21:52:24 +0200, Karl <8213543ggxnvjx...@kabelmail.de> wrote: >Hello, > >one beginner question: > >aList = [0, 1, 2, 3, 4] >bList = [2*i for i in aList] >sum = 0 >for j in bList: > sum = sum + bList[j] >print j > >0 >2 >4 >IndexError: 'list index out of range' >Why is j in the second run 2 and not 1 in the for-loop?? I think j is a >control variable with 0, 1, 2, 3, ... No--to see what 'j' is, comment out your "sum = sum + bList[j]" statement and run again. The name 'j' refers in order to the 0th, 1st, etc., value in bList, and it's therefore just 'j' (i.e., the value that j now refers to) you want to add to the sum. To get "the usual" (in many oter PLs) indexing instead you would use: for j in range(len(bList)): sum = sum + bList[j] And if you again comment out the "sum =..." and add: print j, bList[j] you'll see the difference. wwwayne > >Thanks! > >Karl -- http://mail.python.org/mailman/listinfo/python-list
Re: Deep vs. shallow copy?
On 12 Mar 2014 15:29:59 GMT, Alex van der Spek wrote: >On Wed, 12 Mar 2014 10:00:09 -0500, Zachary Ware wrote: > >> On Wed, Mar 12, 2014 at 9:25 AM, Alex van der Spek >> wrote: === 8< === >Having been taught programming in Algol60 Python still defeats me at times! >Particularly since Algol60 wasn't very long lived and what came >thereafter (FORTRAN) much worse. Actually, Algol 60 lived on (and lives on, though not so much used now outside of Scandinavia) in an improved and OOP-extended form in Simula 67 (now just Simula). Most implementations excpt that for DEC-System10 were, however, overpriced and poorly marketed, so we had to wait for C++ (improved and OOP-extended C) for OOP to catch on. === 8< === -- https://mail.python.org/mailman/listinfo/python-list
Re: 2**2**2**2**2 wrong? Bug?
On Mon, 09 Jul 2007 23:51:25 -0700, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: >On Jul 9, 11:42?pm, Paul McGuire <[EMAIL PROTECTED]> wrote: >> On Jul 9, 11:21 pm, "Jim Langston" <[EMAIL PROTECTED]> wrote:> In Python 2.5 >> on intel, the statement >> > 2**2**2**2**2 >> > evaluates to>>> 2**2**2**2**2 >> >> > 200352993040684646497907235156025575044782547556975141926501697371089405955 >> > 63114 >> > 530895061308809333481010382343429072631818229493821188126688695063647615470 >> > 29165 >> > 041871916351587966347219442930927982084309104855990570159318959639524863372 >> > 36720 >> >> >> >> Exponentiation is right associative, so this is the same as: >> >> 2**(2**(2**(2**2))) >> 2**2**2**4 >> 2**2**16 >> 2**65536 >> >> 2=10**0.3010, so 2**65536 is approx 10**19726 >> >> There are 19730 digits in your answer, > import gmpy n = 2**2**2**2**2 gmpy.numdigits(n) >19729 > >Did you count the 'L'? numdigits(n)? What? 'L' is a digit in Python? I'm going back to Fortran! wwwayne >>so this seems to be at least in >> the ball park. >> >> -- Paul > -- http://mail.python.org/mailman/listinfo/python-list
Re: Understanding python functions - Instant Python tutorial
On Fri, 13 Jul 2007 18:49:06 +0200, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: >Wildemar Wildenburger wrote: >> x = [1, 2, 3] >> y = [1, 2, 3] >> id(x), id(y) >> x == y >> x is y >> >Ooops! > >Make that: > >x = [1, 2, 3] >y = [1, 2, 3] >id(x); id(y) >x == y >x is y > >(had to be a semicolon there) Not "had to be" since a discerning reader will note that the two values in the list: >>> id(x), id(y) (19105872, 19091664) are different, and can guess that id() means "address of". But "nicer to be" perhaps since it makes it even more clea rto discerning readers, and more likely clear to others. ;-) >>> id(x); id(y) 19105872 19091664 wwwayne -- http://mail.python.org/mailman/listinfo/python-list
Re: 2**2**2**2**2 wrong? Bug?
On Wed, 11 Jul 2007 21:37:00 -0400, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > >"Evan Klitzke" <[EMAIL PROTECTED]> wrote in message >news:[EMAIL PROTECTED] >| On 7/11/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote: >| > Just for curiosity: This helps to find the answer to the problem "Which >is >| > the largest number that can be written with only 3 digits?" >| > Some people stop at 999, others try 99**9 and 9**99, and the winner is >| > 9**9**9, or: >| > >| > | 9 >| > | 9 >| > | 9 >| > >| > Sorry, couldn't resist. >| >| But you can append ! (i.e. factorial) indefinitely without adding any >| digits to make the number arbitrarily large ;-) > >But as Gabriel showed, 9**9**9 in standard math pen-and-paper or >chalk-and-blackboard notation, not the squished computer linear imitation >thereof, uses three nines and nothing else ;-) Since no base was specified: (hex) F**F**F > (dec) 9**9**9 and we could use BASE-64 numbers (immediately coming to mind if we ever drove a CDC CYBER machine), where: (base-64) del**del**del > (hex) F**F**F > (dec) 9**9**9 Then someone who had read the Busy Beaver reference would introduce base-BB2, or (where we assume the digits base-BB2 are 0, 1, ..., BB2(???)): BB2(1) ** BB2(1) ** BB2(1) and so on, ad infinitum--as the bard said (http://www-groups.dcs.st-and.ac.uk/~history/Quotations/De_Morgan.html): Great fleas have little fleas upon their backs to bite 'em, And little fleas have lesser fleas, and so ad infinitum. And the great fleas themselves, in turn, have greater fleas to go on; While these again have greater still, and greater still, and so on. wwwayne === "Come along son, and put your whip away. That horse is dead!" --- Wise Old Man >tjr > > -- http://mail.python.org/mailman/listinfo/python-list
Re: 2**2**2**2**2 wrong? Bug?
On Fri, 13 Jul 2007 11:30:16 -0700, Paul McGuire <[EMAIL PROTECTED]> wrote: >On Jul 13, 1:20 pm, Wayne Brehaut <[EMAIL PROTECTED]> wrote: >> On Mon, 09 Jul 2007 23:51:25 -0700, "[EMAIL PROTECTED]" >> >> >> >> >> >> <[EMAIL PROTECTED]> wrote: >> >On Jul 9, 11:42?pm, Paul McGuire <[EMAIL PROTECTED]> wrote: >> >> On Jul 9, 11:21 pm, "Jim Langston" <[EMAIL PROTECTED]> wrote:> In Python >> >> 2.5 on intel, the statement >> >> > 2**2**2**2**2 >> >> > evaluates to>>> 2**2**2**2**2 >> >> >> > 200352993040684646497907235156025575044782547556975141926501697371089405955 >> >> > 63114 >> >> > 530895061308809333481010382343429072631818229493821188126688695063647615470 >> >> > 29165 >> >> > 041871916351587966347219442930927982084309104855990570159318959639524863372 >> >> > 36720 >> >> >> >> >> >> Exponentiation is right associative, so this is the same as: >> >> >> 2**(2**(2**(2**2))) >> >> 2**2**2**4 >> >> 2**2**16 >> >> 2**65536 >> >> >> 2=10**0.3010, so 2**65536 is approx 10**19726 >> >> >> There are 19730 digits in your answer, >> >> >>>> import gmpy >> >>>> n = 2**2**2**2**2 >> >>>> gmpy.numdigits(n) >> >19729 >> >> >Did you count the 'L'? >> >> numdigits(n)? >> >> What? 'L' is a digit in Python? I'm going back to Fortran! >> >> wwwayne >> >> >> >> >>so this seems to be at least in >> >> the ball park. >> >> >> -- Paul- Hide quoted text - >> >> - Show quoted text -- Hide quoted text - >> >> - Show quoted text - > >'L' counts for 50, but only when you use Roman font. WTL?! Not Times New Roman I hope? Now I'll have to extend my remarks below to include: L**L**L D**D**D M**M**M etc. (since I don't recall what comes next) though these (L, D, M, ...) would seem to be numbers rather than digits: the Romans used a base-1 system [for purposes of this argument, at least] so I is the only Roman digit* and the others are just shorthand for: I = 1 V = I X = I*10 L = I*50 D = I*500 M = I*1000 etc. --- For those who don't know which Roman digit I represents: | _\|/__ wwwayne > >-- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a low-level programmer learn OOP?
On Sat, 14 Jul 2007 06:01:56 +0200, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: >Chris Carlen a écrit : >> Hi: >> >> From what I've read of OOP, I don't get it. I have also found some >> articles profoundly critical of OOP. I tend to relate to these articles. >> === 8< === >> >> Hence, being a hardware designer rather than a computer scientist, I am >> conditioned to think like a machine. I think this is the main reason >> why OOP has always repelled me. > >OTOH, OO is about machines - at least as conceveid by Alan Key, who >invented the term and most of the concept. According to him, each object >is a (simulation of) a small machine. Oh you young'uns, not versed in The Ancient Lore, but filled with self-serving propaganda from Xerox PARC, Alan Kay, and Smalltalk adherents everywhere! As a few more enlightened have noted in more than one thread here, the Mother of All OOP was Simula (then known as SIMULA 67). All Alan Kay did was define "OOPL", but then didn't notice (apparently--though this may have been a "convenient oversight") that Simula satisfied all the criteria so was actually the first OOPL--and at least 10 years earlier than Smalltalk! So Kay actually invented NONE of the concepts that make a PL an OOPL. He only stated the concepts concisely and named the result OOP, and invented yet another implementation of the concepts-- based on a LISP-like functional syntax instead of an Algol-60 procedural syntax, and using message-passing for communication amongst objects (and assumed a GUI-based IDE) (and introduced some new terminology, especially use of the term "method" to distinguish class and instance procedures and functions, which Simula hadn't done) . As Randy Gest notes on http://www.smalltalk.org/alankay.html, "The major ideas in Smalltalk are generally credited to Alan Kay with many roots in Simula, LISP and SketchPad." Too many seem to assume that some of these other "features" of Smalltalk are part of the definition of an OOP, and so are misled into believing the claim that it was the first OOPL. Or they claim that certain deficiencies in Simula's object model--as compared to Smalltalk's--somehow disqualifies it as a "true OOPL", even though it satisfies all the criteria as stated by Kay in his definition. See http://en.wikipedia.org/wiki/Simula and related pages, and "The History of Programming Languages I (HOPL I)", for more details. Under a claim of Academic Impunity (or was that "Immunity"), here's another historical tid-bit. In a previous empolyment we once had a faculty applicant from CalTech who knew we were using Simula as our introductory and core language in our CS program, so he visited Xerox PARC before coming for his inteview. His estimate of Alan Kay and Smalltalk at that time (early 80s) was that "They wanted to implement Simula but didn't understand it--so they invented Smalltalk and now don't understand _it_!" wwwayne === 8< === -- http://mail.python.org/mailman/listinfo/python-list
Re: A Python newbie ask a simple question
On Fri, 13 Jul 2007 14:51:52 -0400, "Jeff McNeil" <[EMAIL PROTECTED]> wrote: >The raw_input built-in returns a string. The '[0]' subscript returns >the first character in the user supplied response as strings support >indexing. > >[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin >Type "help", "copyright", "credits" or "license" for more information. mystr = "asdf" mystr[0] >'a' > raw_input("Another one, please: ")[0] >Another one, please: ASDF >'A' > >-Jeff And, as I'm sure Jeff intended to add, you should always try to answer such questions for yourself by just trying a few examples. An advantage of Python is that it's very quick and easy to test one idea at a time without having to create a complete program skeleton before getting started as you would have to in some other languages (such as Java). It also wouldn't hurt to start with one of the many introductory tutorials, some referenced in similar threads above in this group under topics like: Off Topic: What is the good book to learn Python ? Want to learn Python Start to see what others recommend you start with. Or just take a common suggestion and go to: http://www.python.org/doc/ and check out some of the beginners' resources listed and linked to there, such as the "offical" tutorial: http://docs.python.org/tut/tut.html or the widely used wiki site: http://wiki.python.org/moin/BeginnersGuide or the list of Introductory Books: http://wiki.python.org/moin/IntroductoryBooks It may be that none of these answer the specific question you have, but if you start with some of these you'll possibly get a more efficient and enjoyable start than trying to find details of one particular example--and you'll then also have a number of resources at hand with which to try to find your own answers. In case you still have questions, you can always ask in this friendly group; though perhaps more appropriate for "getting started" questions might be the Python Tutorial list at: http://mail.python.org/mailman/listinfo/tutor I use ActivePython a lot, (from ActiveState at http://aspn.activestate.com/ASPN/Python/Downloads/), and use Help, Python Manuals, Python Documentation instead of having to store, open, and maintain the most commonly used dfocumentation separately. Note that the Tutorial is listed here, so it's conveniently located and easy to copy code and paste into the interactive window to test! Or you can use the usual Help Index facility to find the description of "raw_input": === raw_input( [prompt]) If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised. Example: === Knowing this, and having checked out some of the tutorials so you know that [0] is the first element of any "indexable object" (sequence); or using the Help Index again with "sequence" (since you will probably have noted from your tutorial exercises that strings are one type of sequence) you find that one of the operations on strings is: s[i] i'th item of s, origin 0 so the answer to your question: What does the statement "choice = raw_input(prompt)[0]" mean? is now obvious. And the more tutorials you work through, and the more examples you try, the more such statements will be "obvious" or easy to figure out! Happy pythoning! wwwayne >On 7/13/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> what does the statement "choice = raw_input(prompt)[0]" mean? I don't >> know why there is a '[0]' in the statement. >> >> Thank you very much >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> -- http://mail.python.org/mailman/listinfo/python-list
Re: Understanding python functions - Instant Python tutorial
On Sat, 14 Jul 2007 03:18:43 +0200, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: >Wayne Brehaut wrote: >>> (had to be a semicolon there) >>> >> >> Not "had to be" since a discerning reader will note that the two >> values in the list: >> >> >>> id(x), id(y) >> (19105872, 19091664) > >Wll, as long as we are nitpicking: That's a tuple, not a list. Yeah, just wanted to see if you'd catch it! w >;) >/W -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a low-level programmer learn OOP?
On Fri, 13 Jul 2007 20:37:04 -0400, Steve Holden <[EMAIL PROTECTED]> wrote: >Aahz wrote: >> In article <[EMAIL PROTECTED]>, >> Chris Carlen <[EMAIL PROTECTED]> wrote: >>>From what I've read of OOP, I don't get it. >> >> For that matter, even using OOP a bit with C++ and Perl, I didn't get it >> until I learned Python. >> >>> The problem for me is that I've programmed extensively in C and .asm on >>> PC DOS way back in 1988. >> >> Newbie. ;-) >> >> (I started with BASIC in 1976.) >> >Newbie ;-) > >(I started with Algol 60 in 1967). Newbie ;-) (I started with Royal McBee LGP 30 machine language (hex input) in 1958, and their ACT IV assembler later! Then FORTRAN IV in 1965. By 1967 I too was using (Burroughs) Algol-60, and 10 years later upgraded to (DEC-10) Simula-67.) Going---going--- >>> Form 2: Use Python and PySerial and TkInter or wxWidgets. >>> >>> Pro: Cross-platform goal will likely be achieved fully. Have a >>> programmer nearby with extensive experience who can help. >>> Con: Must learn new language and library. Must possibly learn a >>> completely new way of thinking (OOP) not just a new language syntax. >>> This might be difficult. >> >> My experience is that learning GUI programming is difficult. Moreover, >> GUI programming in C involves a lot of boilerplate that can be automated >> more easily with Python. So I think this will be a better solution. >> >I used to write in C for the SunView platform (back in the days when the >GUI was integrated into the kernel as the only way to get acceptable >speed on the display). From what I remember, "Hello World" took about 40 >lines. > >The immense (relatively speaking: this was 1985) size of the libraries >required was one of the primary justifications for implementing shared >libraries. > >> Note very very carefully that Python does not require an OOP style of >> programming, but it will almost certainly be the case that you just >> naturally start using OOP techniques as you learn Python. > >That's very true. I still use a lot of (perhaps too much) procedural >coding, but driving the object-oriented libraries is a great way for a >noob to get started in OOP. > >regards > Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a low-level programmer learn OOP?
On Sat, 14 Jul 2007 19:18:05 +0530, "Rustom Mody" <[EMAIL PROTECTED]> wrote: >On 7/14/07, Alex Martelli <[EMAIL PROTECTED]> wrote: >> >> OOP can be abused (particularly with deep or intricate inheritance >> structures). But the base concept is simple and clear: you can bundle >> state and behavior into a stateful "black box" (of which you may make as >> many instances, with independent state but equal behavior, as you need). >> > >Many years ago (86??) Wegner wrote a paper in OOPSLA called Dimensions >of Object Orientation in which he called the 'base concept' of 'bundle >of state and behavior' as 'object based' programming and >'object-oriented' as object-based + inheritance. Not quite--according to him: object-based + classes => class-based class-based + class inheritance => object-oriented I.e., "object-oriented = objects + classes + inheritance". This was not the, by then, standard definition: to be OO would require all four of: 1. modularity (class-based? object-based?) 2. inheritance (sub-classing) 3. encapsulation (information hiding) 4. polymorphism ((sub-) class-specific response to a message, or processing of a method) Unfortunately, most of the "definitions" (usually just hand-waving, loosey-goosey descriptions) found on the web include none--or only one or two--of these fundamental requirements by name, and are so loose that almost any proramming paradigm or style would be OO. >What Alex is saying is (in effect) that object-based is simple and >clear (and useful) whereas the object-orientation is subject to abuse. But OO is also simple and clear (if clearly defined and explained and illustrated and implemented), and ANY programming style is subject to abuse. During the hey-day of Pascal as an introductory programming language (as often misused as more than that) I found many often spent much of their time defining the data types their program would use. >This anyway is my experience: C++ programmers are distinctly poorer >programmers than C programmers -- for some strange reason closeness to >the machine has a salutary effect whereas the encouragment of >uselessly over-engineered programs makes worse programmers. But this is a tautology: "over-engineered" programs are, by definition or terminology, not a good thing--independent of what PL or style they're finally implemented in (assuming that by "engineering" you mean "design" or similar). Many of my Pascal students over-engineered their solutions to simple problems too? >GUI is one of those cases wherein inheritance actually helps people >produce better code but this is something of an exception. This seems to imply that the list of applications you have in mind or have worked on includes fewer domains that might profit from full OO instead of just OB. My guess is that there are many application domains in which analysts and programmers often think in an "OO way", but implement in just an OB way because of the PL they or their employer requires or prefers: in some--perhaps many--of these cases they have to do "manually" what OO would have automated. There is a problem, though, of (especially university and college) education and training in OOP "talking about" how glorious OO is, and requiring students to use OO techniques whether they're most appropriate or not (the "classes early" pedagogical mindset). And this problem is compounded by teaching introductory programming using a language like Java that requires one to use an OO style for even trivial programs. And by using one of the many very similar introductory texbooks that talk a lot about OO before actually getting started on programming, so students don't realize how trivial a program is required to solve a trivial problem, and hence look for complexity everywhere--whether it exists or not--and spend a lot of time supposedly reducing the complexity of an already simple problem and its method of solution. But as I noted above, a similar problem occurred with the crop of students who first learned Pascal: they often spent much of their time defining the data types their program would use, just as OO (especially "classes early") graduates tend to waste time "over-subclassing" and developing libraries of little-used classes. The answer is always balance, and having an extensive enough toolkit that one is not forced or encouraged to apply a programming model that isn't appropriate and doesn't help in any way (including maintainability). And starting with a language that doesn't brainwash one into believing that the style it enforces or implies is always the best--and texbooks that teach proper choice of programming style instead of rigid adherence to one. wwwayne -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a low-level programmer learn OOP?
On Sat, 14 Jul 2007 11:49:48 -0600, darren kirby <[EMAIL PROTECTED]> wrote: >quoth the Wayne Brehaut: > >> (I started with Royal McBee LGP 30 machine language (hex input) in >> 1958, and their ACT IV assembler later! Then FORTRAN IV in 1965. By >> 1967 I too was using (Burroughs) Algol-60, and 10 years later upgraded >> to (DEC-10) Simula-67.) >> >> Going---going--- > >Mel? Is that you? > >http://www.pbm.com/~lindahl/mel.html > Ha-ha! Thanks for that! Although I'm not Mel, the first program I saw running on the LGP-30 was his Blackjack program! In 1958 I took a Numerical Methods course at the University of Saskatchewan, and we got to program Newton's forward difference method for the LGP-30. Our "computer centre tour" was to the attic of the Physics building, where their LGP-30 was networked to a similar one at the Univeristy of Toronto (the first educational computer network in Canada!), and the operator played a few hands of Blackjack with the operator there to illustrate how useful computers could be. A few years later, as a telecommunications officer in the RCAF, I helped design (but never got to teach :-( ) a course in LGP-30 architecture and programming using both ML and ACT IV AL, complete with paper tape input and Charactron Tube (http://en.wikipedia.org/wiki/Charactron) output--handy, since this display was also used in the SAGE system. We weren't encouraged to use card games as examples, so used navigational and tracking problems involving fairly simple trigonometry. wwwayne >-d -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a low-level programmer learn OOP?
On Sun, 15 Jul 2007 07:47:20 -, [EMAIL PROTECTED] wrote: >On Jul 13, 3:20 pm, Wayne Brehaut <[EMAIL PROTECTED]> wrote: >> On Sat, 14 Jul 2007 06:01:56 +0200, Bruno Desthuilliers >> >> <[EMAIL PROTECTED]> wrote: >> >Chris Carlen a écrit : >> >> Hi: >> >> >> From what I've read of OOP, I don't get it. I have also found some >> >> articles profoundly critical of OOP. I tend to relate to these articles. >> >> === 8< === === 8< === >> Under a claim of Academic Impunity (or was that "Immunity"), here's >> another historical tid-bit. In a previous empolyment we once had a >> faculty applicant from CalTech who knew we were using Simula as our >> introductory and core language in our CS program, so he visited Xerox >> PARC before coming for his inteview. His estimate ofAlan Kayand >> Smalltalk at that time (early 80s) was that "They wanted to implement >> Simula but didn't understand it--so they invented Smalltalk and now >> don't understand _it_!" >> >> wwwayne >> >> === 8< === > >A couple of notes on this post. > >Alan Kay has always publicly credited Simula as the direct inspiration >for Smalltalk, and if you know the man and his work, this implication >of taking credit for the first OOP language is not true, it is a >credit assigned to him by others, and one which he usually rights when >confronted with it. I know this, and was perhaps a little too flippant in my all-inclusive statement "self-serving propaganda from Xerox PARC,Alan Kay, and Smalltalk adherents everywhere!", for which I apologize. But it was made with humorous intent, as I had hoped the opening "Oh you young'uns, not versed in The Ancient Lore, but filled with self-serving propaganda..." would imply. A more accurate and unhumorous statement of my opinion is that it is Smalltalk adherents who know virtually nothing of the history of OOP--and even some who do--who did and still do make such claims, both personally and in the published literature of OOP. And my statement about a prospective faculty member's opinion was just that: a historical anecdote, and the expression of an early 80s opinion by a professional CS professor and researcher in formal semantics (which may have been part of his distrust of the Smalltalk team's "understanding" of Smalltalk) . The opinion he expressed was his and not my own, and I was just recording (what I thought might be) an amusing anecdote in a context in which I thought it appropriate: discussion of what OOP is, and after Bruno made the claim: "OO is about machines - at least as conceveid by Alan Key, who invented the term and most of the concept." I don't think my recording it here should be construed as my opinion of either Smalltalk or its creators (at that time or now). As often happens in many arenas, the creator of an idea can lose control to the flock, and many publications can get accepted if referrees themselves don't know the facts or take care to check them before recommending publication--which probably explains why so many publications (especially in conference proceedings) on OOP in the 80s and 90s completely omitted any mention of Simula: so much so that I once intended writing a paper on "Ignorance of Simula Considered Harmful." On the other hand, anytyhing you may have inferred about my distaste for those who doesn't bother to learn anything of the history of a subject, then make false or misleading claims, and don't bother to correct themselves when questioned, is true. >You may be confused with the fact that "object oriented >programming"was a term which I believe was first used by Alan and his >group at PARC, so perhaps the coining of the term is what is being >referenced by others. No, I have been at more than one CS (or related area) conference where a Smalltalk aficionado has stated unequivocally that Kay invented OOP and that Smalltalk was the first OOPL. The last I recall for sure was WebNet 2000, where a (quite young) presenter on Squeak made that statement, and was not at all certain what Simula was when I asked whether it might actually have been the first more than 10 years before Smalltalk 80. So his claim, and that of many others, explicitly or implicitly, is that not only the term, but most (or all) of the concept, and (often) the first implementation of OOP was by Kay and his Xerox PARC team in Smalltalk 80. >Perhaps I'm mistaken, but the tone of your post conveys an animosity >that did not exist between the original Smalltalk and Simula >inventors; Nygard and Kay were good friends, and admired each others' >work very much. Yes, you are very much mistaken (as I note above), and appear not to have understood the intended humorous tone of my posting. wwwayne > >Bonnie MacBird > -- http://mail.python.org/mailman/listinfo/python-list
Re: 2**2**2**2**2 wrong? Bug?
On Fri, 13 Jul 2007 14:27:13 -0700, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: >On Jul 13, 1:20 pm, Wayne Brehaut <[EMAIL PROTECTED]> wrote: >> On Mon, 09 Jul 2007 23:51:25 -0700, "[EMAIL PROTECTED]" >> >> >> >> >> >> <[EMAIL PROTECTED]> wrote: >> >On Jul 9, 11:42?pm, Paul McGuire <[EMAIL PROTECTED]> wrote: >> >> On Jul 9, 11:21 pm, "Jim Langston" <[EMAIL PROTECTED]> wrote:> In Python >> >> 2.5 on intel, the statement >> >> > 2**2**2**2**2 >> >> > evaluates to>>> 2**2**2**2**2 === 8< === >> >Did you count the 'L'? >> >> numdigits(n)? === 8< === >> What? 'L' is a digit in Python? > >No, but it's a character. Don't you know the difference >between str() and repr()? Don't you know the difference between humorous (even if slightly silly at times) banter and serious discussion? Did you bother to read the context before responding? Do you know what you're attributing to whom, and whether they're actually the ones who said it--and, if so, do you understand what they meant by it? === 8< === >> I'm going back to Fortran! > >Sounds like you never left. Now that's a low blow--but I'll consider the source and overlook it. w >> >> wwwayne >> >> >>so this seems to be at least in >> >> the ball park. >> >> >> -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: 2**2**2**2**2 wrong? Bug?
On Fri, 13 Jul 2007 14:32:03 -0700, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: >On Jul 13, 2:52 pm, Wayne Brehaut <[EMAIL PROTECTED]> wrote: >> On Fri, 13 Jul 2007 11:30:16 -0700, Paul McGuire <[EMAIL PROTECTED]> >> wrote: >> >> >> >> >> >> >On Jul 13, 1:20 pm, Wayne Brehaut <[EMAIL PROTECTED]> wrote: >> >> On Mon, 09 Jul 2007 23:51:25 -0700, "[EMAIL PROTECTED]" >> >> >> <[EMAIL PROTECTED]> wrote: >> >> >On Jul 9, 11:42?pm, Paul McGuire <[EMAIL PROTECTED]> wrote: >> >> >> On Jul 9, 11:21 pm, "Jim Langston" <[EMAIL PROTECTED]> wrote:> In >> >> >> Python 2.5 on intel, the statement >> >> >> > 2**2**2**2**2 >> >> >> > evaluates to>>> 2**2**2**2**2 === 8< === >> >> >Did you count the 'L'? >> >> >> numdigits(n)? >> >> >> What? 'L' is a digit in Python? I'm going back to Fortran! >> >> >> wwwayne === 8< === >> >'L' counts for 50, but only when you use Roman font. >> >> WTL?! Not Times New Roman I hope? >> >> Now I'll have to extend my remarks below to include: >> >> L**L**L >> D**D**D >> M**M**M >> etc. (since I don't recall what comes next) >> >> though these (L, D, M, ...) would seem to be numbers rather than >> digits: the Romans used a base-1 system > >No, "base" refers to a Positional Number system for which >radix 1 is undefined. > >You can call Roman Numerals a Tally System of Radix 1. I can call it what I want--within reason--so long as those I'm mainly addressing understand what I mean and the context in which I'm saying it. As I note in my other response to your response below, my remark was intended to be humorous, and everyone else who responded took it that way. There's no need to get all formal in such a context, and there's no harm in defining a tally system to be 1-based or to be a base-1 system. If I had intended this to be a formal discussion instead of just having a little fun (and sorry for doing that) I would have instead said: "Define a base-1 number system as...". Since you clearly don;t want to accept my terminology and assume there's just one right one, please see http://www.psinvention.com/zoetic/basenumb.htm for an independent opinion of the reasonableness of using this term: "Base Valued Numbers Any use of numbers implies the use of a base value for the numbers. The simplest base value to use in a numbering scheme is '1'." Because we're most familiar with the use of the term "base" in the context of positional notation in no way implies that's the only possible context in which it can be used--or has been used--with perfectly clear meaning. So the Roman system was based on the number 1 and was, therefore, 1-based or base-1. Even in the context of positional systems it's perfectly clear what a base-1 system would be and the fact that it's generally excluded isn;t because it's not cleaar what it weould be, but only that most assume it isn't of any uise, so exclude it. As we all know: 1^0 = 1 1^1 = 1 1^n = 1 for any positive natural number [and negative natural numbers don't exist, but extension to negative integers is left as an exercise for the reader] In the base 1 positional number system, what is the value of: 1 11 111 1...1 (with n 1s)? And would the value be any different if I wrote them: 1 11 111 1...1 (with n 1s)? In pictures: Pos? ? Value 1 Digit1 Pos? ? ? Value 1 1 Digit1 1 Pos? ? ? ? Value 1 1 1 Digit1 1 1 Pos? ? ... ? Value 1 ... 1 (n positions) Digit1 ... 1 (n 1s) >Tally sytems ARE defined for radix 1, but operate >completely different from positional systems. Clearly, the algorithm to find the value of a base-1 number is to multiply the value of each position (1) by the digit in that position (1) and add the results--just as you would do for any other positional system. One common assumption for excluding base-1 is that this can't be a proper positional number system because there's no zero digit, so how can we represent the 0 value of a position? The obvious answer is that there is no way of knowing what power of 1 each position represents anyway, since the value of each and every position is 1, so we just leave out positions whose value is zero; equivalently, we just admit that the base-1 tally system is equivalent to the base-1 positional system so far as counting is concerned, since we don't count things that aren't there. I claim
Re: 2**2**2**2**2 wrong? Bug?
On Sun, 15 Jul 2007 17:37:13 -0400, Steve Holden <[EMAIL PROTECTED]> wrote: >Wayne Brehaut wrote: >> On Fri, 13 Jul 2007 14:32:03 -0700, "[EMAIL PROTECTED]" >[...] >> But I digress (but only because provoked!)... >> >>>> [for purposes of this argument, at least] >> >> This statement is the informal equivalent to saying "Define a base-1 >> number system as...", as I noted above. If you'd noted this, and >> understood it, or were willing to accept it whether or not you >> understood it, you'd have saved us both some bother--but me more than >> you I guess, so maybe you were just trolling? >> >wwway to beat a response to a pulp. Sometimes it's easier and better for >your blood pressure just to let someone else have the last word, however >ill-informed or hostile. Best answer: Not hit Reply or Send. [Too late!] Short answer: Yes, I agree--and thank you for this sage advice! My answer: Guilty with an explanation. I tend to use a "stream of consciousness approach" when I have time, so my responses tend to grow until I run out of time or energy, or I'm called to dinner (so not without bounds). Also, I tend to follow the general Evolutionarily Stable Strategy generally called "Retaliator". In the simple game of Hawk vs. Dove a Hawk always attacks and defends to the death, whereas a Dove always runs. A mixed strategy would be to sometimes attack-and-defend and sometimes run, and a special case is to always run except when you're attacked--then defend to the death; i.e., behave like a Dove to a Dove and like a Hawk to a Hawk. In Game Theory, if not in practice, Retaliator is dominant over both pure Hawk and pure Dove, partly because some who present like Hawks are actually Bullies--who behave like Hawks until an opponent defends, then behave like Doves. Of course this should be a cooperative group to help one another learn more about Python and solve problems--perhaps with an occasional sidebar of humour for relaxation-- rather than attacking and defending; but when someone attacks my attempt at humour, or makes a demonstrably incorrect statement attacking my peaceable, well-reasoned one, I get really POd and my Hawk-like tendencies emerge. And my blood pressure is fine, though I am monitoring it... Moreover, I find it's sometimes harder on my blood pressure to lie awake at night thinking of all the things I would have liked to say and didn't. But thank you for this sage advice! w >regards > Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a low-level programmer learn OOP?
On Mon, 16 Jul 2007 10:10:05 +0200, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: >Wayne Brehaut a écrit : >(snip) > > after Bruno made the >> claim: "OO is about machines - at least as conceveid by Alan Key, who >> invented the term and most of the concept." > >Please reread more carefully the above. I do give credit to Smalltalk's >author for the *term* "OOP", and *most* (not *all*) of the concepts (I >strongly disagree with your opinion that message-passing is not a core >concept of OO). One problem is that it's often not clear what lists of properties are his definition of OOP vs. what are the intended properties of Smalltalk--his intended impelmentation of OOP. Many of the lists begin with the basic requirements that "everything is an object" and "objects communicate by message passing", but the most common "generally agreed upon" definition abstracts just four requirements from these (changing) lists--attempting to separate implementation details from what is essential to the underlying framework. As I note below, these were: 1. modularity (class-based? object-based?) 2. inheritance (sub-classing) 3. encapsulation (information hiding) 4. polymorphism ((sub-) class-specific response to a message, or processing of a method) Other details in Kay's lists are considered implementation details, and important advances or alternatives to pevious methods, but not required for a language to _be_ OO. It is reputed, though, that in 2003 Kay said (http://c2.com/cgi/wiki?AlanKaysDefinitionOfObjectOriented) "OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme LateBinding of all things." So I understand your accepting one of Kay's lists as being a definition of OOP instead of "just" a description of Smalltalk, or of accepting this fairly recent "definition" as being the true one (as opposed to the previous lists of usually 6 properties). "It's hard to hit a moving target!" >FWIW, I first mentionned Simula too (about the state-machine and >simulation aspect), then sniped this mention because I thought it was >getting a bit too much OT - we're not on comp.object here. Understood--sort of--but there is sufficient accurate information about Simula available on the web now that it's no longer necessary to use quotes from Kay about OOP and Smalltalk just because they're more accessible, as used to be the case. What would be so OT about referring to Simulain one sentence instead of or in addition to Smalltalk? But I digress--my only real objection to your post was your opinion and claim that Kay "invented the term and most of the concept": I've never seen anyone claim that anyone else invented the term, but for the claim that he invented "most of the concept" we need only refer to Nygaard's claim in "How Object-Oriented Programming Started" at http://heim.ifi.uio.no/~kristen/FORSKNINGSDOK_MAPPE/F_OO_start.html that "Simula 67 introduced most of the key concepts of object-oriented programming: both objects and classes, subclasses (usually referred to as inheritance) and virtual procedures, combined with safe referencing and mechanisms for bringing into a program collections of program structures described under a common class heading (prefixed blocks)." Combine this with the fact--as stated above by Bonnie MacBird (Alan Kay's significant other)--that "Alan Kay has always publicly credited Simula as the direct inspiration for Smalltalk, and... this implication of taking credit for the first OOP language is not true, it is a credit assigned to him by others, and one which he usually rights when confronted with it." If he acknowledges this perhaps others should too? As has been noted before, it's often the fact that a cause becomes a religion: true believers tend to take it over from the originator, and this religiosity tends to blind them from the facts. Opinions and rumours become facts, stories are invented, definitions are changed or twisted, and another religion is born! Even those who don't belong to the religion cpme to believe the oft-repreated stories, and then help spread and perpetuate them. (Continuing in my original humorous vein I was tempted to use terms like "religious zealots", "false gospel", "propaganda", etc., but thought better of it in case I was again misunderstood.) Again, I disagree only with this one claim. You make significant contributions to the group and to ellucidating Python and OOP to the great unwashed: in contrast, all I've done so far is complain about those who don't accept the correct (i.e., my) definition or use of terms. wwwayne -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a low-level programmer learn OOP?
On Mon, 16 Jul 2007 09:55:35 +0200, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: >Wayne Brehaut a écrit : >> On Sat, 14 Jul 2007 06:01:56 +0200, Bruno Desthuilliers >> <[EMAIL PROTECTED]> wrote: >> >>> Chris Carlen a écrit : >>>> Hi: >>>> >>>> From what I've read of OOP, I don't get it. I have also found some >>>> articles profoundly critical of OOP. I tend to relate to these articles. >>>> >> >> === 8< === >> >>>> Hence, being a hardware designer rather than a computer scientist, I am >>>> conditioned to think like a machine. I think this is the main reason >>>> why OOP has always repelled me. >>> OTOH, OO is about machines - at least as conceveid by Alan Key, who >>> invented the term and most of the concept. According to him, each object >>> is a (simulation of) a small machine. >> >> Oh you young'uns, not versed in The Ancient Lore, but filled with >> self-serving propaganda from Xerox PARC, Alan Kay, and Smalltalk >> adherents everywhere! > >Not feeling concerned. > >(snip pro-simula/anti-Xerox propaganda). Or, more accurately, pro: 1. Nygaard & Dahl as the inventors of most of the concept of OOP 2. Simula as the first OOP 3. Kay as the originator of the term OOP 4. Kay, Xerox PARC, and Smalltalk as making significant useful advances in implementation of OOP and "popularizing" it and anti: 1. attributing credit for any accomplishment to someone who doesn't himself claim it and even denies it wwwayne o/o -- http://mail.python.org/mailman/listinfo/python-list
Re: 2**2**2**2**2 wrong? Bug?
On Mon, 16 Jul 2007 08:51:31 +0200, "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: > "Wayne Brehaut" <[EMAIL PROTECTED]> wrote: > >> On Sun, 15 Jul 2007 17:37:13 -0400, Steve Holden <[EMAIL PROTECTED]> >> wrote: >> >> >Wayne Brehaut wrote: >> >> On Fri, 13 Jul 2007 14:32:03 -0700, "[EMAIL PROTECTED]" > >8< - > >> Also, I tend to follow the general Evolutionarily Stable Strategy >> generally called "Retaliator". In the simple game of Hawk vs. Dove a >> Hawk always attacks and defends to the death, whereas a Dove always >> runs. A mixed strategy would be to sometimes attack-and-defend and >> sometimes run, and a special case is to always run except when you're >> attacked--then defend to the death; i.e., behave like a Dove to a Dove >> and like a Hawk to a Hawk. >> >> In Game Theory, if not in practice, Retaliator is dominant over both >> pure Hawk and pure Dove, partly because some who present like Hawks >> are actually Bullies--who behave like Hawks until an opponent defends, >> then behave like Doves. > >*grin* - you realise of course, that this stated strategy leaves you wide >open to trolls of the "Lets see what we can provoke him into responding" >kind - from people whose sense of humour is either subtle, or evil... > >- Hendrik Subtle is good and generally easy enough to spot ("Never kid a kidder!"). As for evil, no problem--I'm also a bit of an Equivocator (perhaps even Prevaricator), and probably won't bother to respond to anyone who seems to be a waste of time or is beyond redemption. I seldom use a kill filter though since I'm too curious about what they're going to say next, but can just read and suffer silently when I choose to! And thanks for the sage advice! wwwayne -- http://mail.python.org/mailman/listinfo/python-list
Re: How to optimise this code?
On Tue, 21 Aug 2007 21:56:18 +0200, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: >Christof Winter <[EMAIL PROTECTED]> writes: > >> To get rid of the if statements, replace __init__ function with: >> >> def __init__(self, tc): >> functionToCall = eval("self.testCase%s" % tc) > >Or functionToCall = getattr(self, "testCase" + tc) > >eval can introduce unwanted side effects. Hence the slogan "Do No Eval!" wwwayne -- http://mail.python.org/mailman/listinfo/python-list
Re: readline() - problem
On Tue, 02 Oct 2007 12:13:21 -, [EMAIL PROTECTED] wrote: >On 2 Pa , 13:39, Ben Finney <[EMAIL PROTECTED]> >wrote: >> [EMAIL PROTECTED] writes: >> > import string >> >> Why import 'string' if you're not using it? >> >> > f=open('/test/test.asc','r') >> > o=open('/test/out.asc','w') >> > for line in f: >> > s= f.readline() >> >> Your line object is already bound to the 'line' name in each >> iteration. You need to use that, not attempt to read yet another line >> each time. >> > >Of course, it helped. Many thanks for all. But be sure you note Wesley's point in teh following post: If you want the 15th character your subscript must be 14, since there's a 0th element? wwwayne > >piotr -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Magazine: Issue 1 Free!
On Thu, 04 Oct 2007 04:12:04 +0200, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: >J. Clifford Dyer a écrit : >> On Fri, Oct 05, 2007 at 04:11:07PM -, Grant Edwards wrote >> regarding Re: Python Magazine: Issue 1 Free!: >> >>> On 2007-10-05, Steve Holden <[EMAIL PROTECTED]> wrote: >>> >> I've just been told by the editors at Python Magazine that >> the first issue is out. > > The first issue is issue number 10? > > That's a bit silly. It's the October edition. They obviously decided to make sure the month numbering was consistent across the volumes. >>> >>> I presumed that was the reasoning. It just seems counter-intuitive >>> (and sort of un-Pythonic) to start numbering a sequence of objects >>> at 10. ;) >>> >> >> >> Well, it's also unpythonic to start numbering a sequence at 1, but >> it's clearly the right thing to do in this case. > >As far as I'm concerned, if I had to number a magazine about >programming, I'd obviously start with 0. And since the "first" issue is free that would be best here too. >Then it would be n°1, n°10, >n°11, n°100 etc !-) But probably with enough leading zeros to last the expected lifetime (8 bits should about do it?) so they'd sort properly: 0001 etc. wwwayne -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Magazine: Issue 1 Free!
On Thu, 04 Oct 2007 04:52:13 +0200, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: >Wayne Brehaut a écrit : >> On Thu, 04 Oct 2007 04:12:04 +0200, Bruno Desthuilliers >> <[EMAIL PROTECTED]> wrote: >> >> >>>J. Clifford Dyer a écrit : >(snip) >>>>Well, it's also unpythonic to start numbering a sequence at 1, but >>>>it's clearly the right thing to do in this case. >>> >>>As far as I'm concerned, if I had to number a magazine about >>>programming, I'd obviously start with 0. >> >> And since the "first" issue is free that would be best here too. >> >>>Then it would be n°1, n°10, >>>n°11, n°100 etc !-) >> >> But probably with enough leading zeros to last the expected lifetime >> (8 bits should about do it?) so they'd sort properly: >> >> >> 0001 >> etc. > >Mmm... sort of reminds me of y2k. Funny, I was thinking IPv4. www -- http://mail.python.org/mailman/listinfo/python-list
Re: linear programming in Python
Hi Jorge, On Wed, 17 Oct 2007 08:44:28 -0700, [EMAIL PROTECTED] wrote: >Hi all, > >I'm new to this group so I don't know if this question has been posted >before, but does anyone knows about linear/integer programming >routines in Python that are available on the web, more specifically of >the branch and bound method. Try using your favourite search engine with a search string like "linear programming Python branch bound". Using Alta Vista (http://www.altavista.com/web/adv) I got: AltaVista found 16,500 results and Google gave: Results 1 - 10 of about 7,990 Some on the first page of each look like good possibilities, and I'm sure there are others in the group that have first-hand experience and can offer comparisons and advice. You might also try searching the archives of this group--I searched just what my server has still available and got no hits on "linear programming", but didn't try just "LP" or similar. Good luck! Wayne >Thanks, > >Jorge Velasquez >PhD Student, Department of Ecology and Evolution at Stony Brook -- http://mail.python.org/mailman/listinfo/python-list
Re: LaTeX tutorial updated [OT]
On Wed, 07 Nov 2007 09:00:12 -0800, John DeRosa <[EMAIL PROTECTED]> wrote: >On Wed, 07 Nov 2007 16:23:56 +0900, Byung-Hee HWANG <[EMAIL PROTECTED]> >wrote: > >>On Wed, 2007-11-07 at 00:10 +, [EMAIL PROTECTED] wrote: >>> On Nov 6, 12:30 pm, Nicola Talbot <[EMAIL PROTECTED]> wrote: >>> > Hi, >>> > >>> > I've updated my "Using LaTeX to write a PhD thesis" tutorial. Both PDF > >My understanding is that the correct nomenclature is, "Master's >thesis," and, "PhD dissertation." This may be more common usage in some regions, but "thesis" is more general and quite correct in either case, as the following indicate. === Thinkmap Visual Thesaurus (http://www.visualthesaurus.com/): exposition a systematic interpretation or explanation (usually written) of a given topic; an account that sets forth the meaning or intent of a writing or discourse treatise a formal exposition thesis dissertation a treatise advancing a new point of view resulting from research; usually a requirement for an advanced academic degree === Oxford Refernce Online--requires subscription (http://0-www.oxfordreference.com.aupac.lib.athabascau.ca/views/GLOBAL.html): The Concise Oxford Dictionary of Literary Terms: thesis an argument or proposition, which may be opposed by an antithesis ; or a scholarly essay defending some proposition, usually a dissertation submitted for an academic degree. --- Pocket Fowler's Modern English Usage thesis meaning a dissertation, has the plural form theses , pronounced thee -seez . --- The Concise Oxford Dictionary of English Etymology: thesis proposition, theme XVI ; (theme of) a dissertation XVII . === Merriam-Webster Online (http://www.m-w.com/): thesis 4: a dissertation embodying results of original research and especially substantiating a specific view; especially : one written by a candidate for an academic degree dissertation an extended usually written treatment of a subject; specifically : one submitted for a doctorate === HTH? wwwayne -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions on Using Python to Teach Data Structures and Algorithms
On Thu, 28 Sep 2006 17:23:25 +0200, "Ramon Diaz-Uriarte" <[EMAIL PROTECTED]> wrote: >Going back to the original question, a related question: does anybody >know why there are so few books on data structures and algorithms that >use Python? > >I remember that, at least ~ 12 years ago there were many (and very >good) books that used Pascal for this topic. So when I did my own >search for one in Python (just for my own consumption and >enlightnment) and could only find the same one as the original poster >of this thread [1], I was very surprised. No publishers have felt the >need to fill this gap? No, and you'll know why if you check for the number of university and college computer science students learning Python in their introductory programming course (not the number of institutions that teach a little bit in a physics course), and the number of textbooks available to support that (and not free online or print tutorials). There's just not a big enough market for (traditional) publishers to be interested in publishing them or (traditional) authors in writing them. Preiss (http://www.brpreiss.com/page1.html) translated his original C++ text (1999) into a number of other languages: Java (2000), C# (2001), Python (2003), and Ruby (2004). So he could easily afford to Translate the early money-makers into less used languages because the initial writing overhead was no longer an issue--and much of the tyranslation was "automated". And he uses his free online versions to help market the publishe'rs small (relative to C++ and Java) print runs, so they can afford to service this very small market. DSA--formerly (i.e., in the "Good Old Days") just Data Structures-- is or was, in the "usual" CS curriculum (a la ACM+IEEE) at least, a second-level course based on CS1; hence, "most efficiently" taught using the students' introductory language (if it's at all suitable, and texts are available) so only some finer points of the language needed covering and one can concentrate on implementation of the data structures themselves. So very little CS1 in Python translates into very little--and probably even less--CS2, etc., in Python. wwwayne >Best, > >R. > >[1] http://thread.gmane.org/gmane.comp.python.general/486698/focus=486698 > "Data Structures and Algorithms with Object Oriented Design Patterns" >(http://www.brpreiss.com/books/opus7/html/book.html) and was surprised. -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions on Using Python to Teach Data Structures and Algorithms
On Thu, 28 Sep 2006 17:32:06 +0200, Fredrik Lundh <[EMAIL PROTECTED]> wrote: >Ramon Diaz-Uriarte wrote: > >> Going back to the original question, a related question: does anybody >> know why there are so few books on data structures and algorithms that >> use Python? > >Probably because Python has "better than textbook" implementations of >core structures, and "better than textbook" implementations of many core >algorithms, so lots of things can be done more efficiently by combining >existing structures and algorithms than by using "textbook" algorithms. But this answers a diiferent question: university and (academic) college data structure courses don't care how efficient a particular language's built-in data structures are, since the intent is for the students to learn how to implement data structures in general, and probably in a particular language--the "core" languasge used in their core programs--and then be able to apply that knowledge and skill to implementing at least "reasonably efficient" ones when they need to in languages that don't have any to speak of built in. And, since many students will go direct to business or industry, and may even be apprenticing there in "co-op work terms" during their education, most could care less how efficient Python's built-in data structures are. Also, it's a very rare DSA text that intends its DS code to be used directly--especially in "serious" applications. Preiss's texts, noted by the OP, are one exception, and many could be used "out of the box" in industrial strength applications. So far as "combining existing structures" is concerned, it's highly unlikely that any such combination of linear structures could be more efficient in both--if either--storage and running time than one specifically designed and implemented for non-linear structures, such as (many) trees and algorithms on them. For general graphs efficient list processing may be sufficient for an adjacncy structure for the graph itself, of course, but how does that translate to storing a subtree found using a DFS, for example, and efficiently processing it in some way? For learning DSA it's more important to have a clear, well-written and well-documented implementation in a language of interest (again, especially, the core language in one's programs) than just "using" or even inspecting and trying to learn subtle details of some particular implementation of a related DS or A in some "other" language. How many of those who devleoped and improved the very efficient data structures in Python learned and honed their skills in Python (vs. C or Pascal, for example)? wwwayne > -- http://mail.python.org/mailman/listinfo/python-list
Re: eof
Hi braver, On Wed, 21 Nov 2007 15:17:14 -0800 (PST), braver <[EMAIL PROTECTED]> wrote: >I'd like to check, for a filehandle f, that EOF has been reached on >it. What's the way to do it? I don't want to try/except on EOF, I >want to check, after I read a line, that now we're in the EOF state. It would be nicer to check the reference manual than ask here. If you have PythonWin 2.5.1 (r251:54863, May 1 2007, 17:47:05) [MSC v.1310 32 bit (Intel)] on win32.for example, using Help, Index, eof gives: eof Token used to determine end of file. This will be set to the empty string (''), in non-POSIX mode, and to None in POSIX mode. New in version 2.3. If you don't use Active State Python--and even of you do--it helps to have these three "official" references handy: === http://docs.python.org/ref/ref.html Python Reference Manual Guido van Rossum Python Software Foundation Email: [EMAIL PROTECTED] Fred L. Drake, Jr., editor Release 2.5 19th September, 2006 === http://docs.python.org/lib/lib.html Python Library Reference Guido van Rossum Python Software Foundation Email: [EMAIL PROTECTED] Fred L. Drake, Jr., editor Release 2.5 19th September, 2006 === http://docs.python.org/tut/tut.html Python Tutorial Guido van Rossum Python Software Foundation Email: [EMAIL PROTECTED] Fred L. Drake, Jr., editor Release 2.5 19th September, 2006 === The tutorial gives simpler explanations and examples, including: 7. Input and Output 7.2.1 Methods of File Objects >>> f.read() 'This is the entire file.\n' >>> f.read() '' === If the end of the file has been reached, f.read() will return an empty string (""). By browsing the index or TOC, or searching, or guessing, you should conclude that you want 3.9 File Objects There, and checking for "EOF" you'll note that both read( [size]) and readline( [size]) include: "An empty string is returned only when EOF is encountered immediately." HTH? >In Ruby it's f.eof: It also is not nice to talk Ruby here--nor Perl. Refer to C/C++ if necessary. wwwayne > >In Ruby: >>> f = File.open("jopa") >=> # >>> f.read() >=> "jopa\n" >>> f.eof >=> true > >Is there a Python analog? > >Cheers, >Alexy -- http://mail.python.org/mailman/listinfo/python-list
Re: eof
On Wed, 21 Nov 2007 17:06:15 -0800 (PST), braver <[EMAIL PROTECTED]> wrote: >On Nov 22, 3:41 am, Wayne Brehaut <[EMAIL PROTECTED]> wrote: >> If you have PythonWin 2.5.1 (r251:54863, May 1 2007, 17:47:05) [MSC v.1310 >> 32 bit (Intel)] on win32.for example, using Help, Index, eof gives: >> 8< === > > HTH? >Nope! I don't want to buffer input myself, and don't want to store >look-ahead and push it back. f.read()/readline() is not a non- >destructive check, and thus won't do. Your original statement was: "I'd like to check, for a filehandle f, that EOF has been reached on it." You now appear to be "upping the ante" as though you're more interested in attacking what you perceive as an omission in Python than in doing what you originally stated. >Well folks compare scripting languages all the time, and surely Ruby >is closer to Python than C++. If I didn't abhor smileys and text substitutes you might have caught on that this was partly "just kidding", but not completely: since Python is implemented in C/C++ it makes perfect sense to see what's readily available there that might account for how one would do it in Python if he really thought it necessary. (As others have noted, it's not necessary.) So what Python is "closer to" is not the point--and there's no standard way of measuring that that I know of? >Since Ruby can do f.eof, which is >easily found in its references, and Python can't, or its EOF can't >easily be found -- the one *equivalent* to a semantically clear >Ruby's, or Pascal's IIRC, f.eof -- something's missing here... >Why do I have to count sizes of lines read and compare it to some >filesize Why would you think that it's you doing the counting? If you insist, write your own trivial eof() and call it so you won't have to fret about how it's discovering whether you're at EOF. >or do other weird tricks just to see, in a way not changing >my input stream, whether it's at the, well, EOF? As others have already pointed out, "because it's seldom necessary in Python". If you really think you need to do it the way you're implying in Python, you're probably mistaken. You should do it the pythonic way instead of complaining about not finding the exact equivalent to how you would do it in some other language. "Python is not Ruby." wwwayne >Cheers, >Alexy -- http://mail.python.org/mailman/listinfo/python-list
Re: JESUS in the QURAN
On Mon, 10 Dec 2007 11:20:49 -0800 (PST), aassime abdellatif <[EMAIL PROTECTED]> wrote: > 'And they devised, and God >devised, and God devised, and God is the best of divisors. Obvious, since God is One, and so He divides 1, and 0, and -1, and all integers both positive and negative (Peace Be Upon Them). wwwayne -- http://mail.python.org/mailman/listinfo/python-list
Re: J in the Q
On Mon, 10 Dec 2007 21:41:56 +0100, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: >Wayne Brehaut a écrit : >(snip spam) >> Obvious, since God is One, and so He divides 1, and 0, and -1, and all >> integers both positive and negative (Peace Be Upon Them). >> >> wwwayne > > >wwwayne, > >My isp did a good job at filtering out that spam. In fact, if it wasn't >for your answer, I wouldn't even know someone about it. Does that ring a >bell, or do I have to say it out loud ? PLEASE DONT ANSWER TO SPAMS ! > >Nah. I suppose you realize that now any troll lurking nearby knows how to bypass your ISP's spam filter and p you off? Rule number 2: NEVER REPLY TO A REPLY TO A SPAMMER! Please killfilter me so you won't be bothered by my posts. If you didn't provide so much useful information I'd killfilter you too so I wouldn't be bothered by your cranky retorts to all my posts. Did you somehow miss the complete reposting of this guy's previous message by Deltantor on 05 Dec 2007? Or is just me that youfeel the need to chastise? o/o wwwayne -- http://mail.python.org/mailman/listinfo/python-list
Re: Update of Gnuplot.py
On Wed, 9 Jan 2008 03:43:38 -0800 (PST), Tom La Bone <[EMAIL PROTECTED]> wrote: > >Can someone suggest where to get a version of Gnuplot.py (for Windows) that >has been updated to use numpy? Or, is there another interface available to >use GnuPlot from Python? > >Thanks. > >Tom Gnuplot 1.7 uses numpy: http://gnuplot-py.sourceforge.net ''' Before you can use Gnuplot.py, you will need working versions of the gnuplot program, Python (version 1.5 or later), and the Numeric Python extension ''' wwwayne -- http://mail.python.org/mailman/listinfo/python-list
Re: Program to compute and print 1000th prime number
On Sat, 7 Nov 2009 19:34:47 +0100, Andre Engels wrote: >On Sat, Nov 7, 2009 at 6:40 PM, Mensanator wrote: > >>> Tongue in cheek solution: >>> >>> import urllib2 >>> >>> url = 'http://primes.utm.edu/lists/small/1.txt' >>> primes = [] >>> for line in urllib2.urlopen(url).read().splitlines(): >>> values = line.split() >>> if len(values) == 10: >>> primes.extend(values) >>> print primes[1000-1] >> >> Nice, but you can do better. >> > import gmpy > n = 1 > for i in xrange(1000): >> n = gmpy.next_prime(n) > print n >> 7919 > >With the help of the solutions given so far, I can do even better than that: > >n = 7919 >print n >>> 7919 7919 ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Tutorials on Jinja
On Wed, 24 Jun 2009 11:46:55 -0700 (PDT), Saurabh wrote: >Hi All, > >I am trying to move my application on a MVC architecture and plan to >use Jinja for the same. Can anyone provide me with few quick links >that might help me to get started with Jinja? Perhaps the most useful link is: http://www.google.com/ from which you can easily find many more with a very basic search, including: http://jinja.pocoo.org/ Hope that helps? wwwayne > >Thanks, >Saby -- http://mail.python.org/mailman/listinfo/python-list
Re: missing 'xor' Boolean operator
On Wed, 15 Jul 2009 13:37:22 +0200, Christian Heimes wrote: >pdpi wrote: >> On Jul 15, 12:08 am, Christian Heimes wrote: >>> Chris Rebert wrote: Using the xor bitwise operator is also an option: bool(x) ^ bool(y) >>> I prefer something like: >>> >>> bool(a) + bool(b) == 1 >>> >>> It works even for multiple tests (super xor): >>> >>> if bool(a) + bool(b) + bool(c) + bool(d) != 1: >>> raise ValueError("Exactly one of a, b, c and d must be true") >>> >>> Christian >> >> "if bool(a) + bool(b) + bool(c) + bool(d) != 1:" is not equivalent to >> xor. 1 xor 1 xor 1 = 1 xor (1 xor 1) = 1 xor 0 = 1 (or = (1 xor 1) xor >> 1 = 0 xor 1 = 1 if you assicate to the left) > >I'm well aware of the fact that I've described something differently. >'xor' can be explained as 'check if exactly one element of two elements >is true'. My algorithms describes a super xor, aka 'check if exactly one >element of n elements is true'. But that's not a "super xor" (commonly known as XOR). Rather than describing xor as: check if exactly one element of two elements is true describe it as: check if an odd number of two elements is true then you'll get the correct definition of "super xor": check if an odd number of n elements is true I.e., XOR determines parity, and: XOR = 0 if v has an even number of 1s and 1 if v has an odd number of 1s wayne >Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: missing 'xor' Boolean operator
On Tue, 14 Jul 2009 11:47:41 -0700 (PDT), Mark Dickinson wrote: >On Jul 14, 7:25 pm, "Dr. Phillip M. Feldman" >wrote: >> Current Boolean operators are 'and', 'or', and 'not'. It would be nice to >> have an 'xor' operator as well. > >Hmm. I don't think 'nice' is sufficient. You'd need to make the case >that it's sufficiently useful to justify adding a new keyword 'xor' to >the language; I suspect that would be an uphill struggle. :) > >I'll just note that: > >(1) It's easy to emulate xor: 'x xor y' <-> bool(x) != bool(y) > >(2) 'and' and 'or' are special in that they have useful short- >circuiting behaviour; xor doesn't have this property (that is, you >always need to evaluate *both* operands to determine the result). > >I'd also guess that 'xor' would be much less used than 'and' or 'or', >but maybe that's just a reflection of the sort of code that I tend to >write. You're right about that!. It's used everywhere in: - coding and encryption theory (and practice) (e.g., http://www.mathcs.emory.edu/~whalen/Hash/Hash_Articles/IEEE/XOR-based%20hash%20functions.pdf) - emulation and simulation of hardware (since all but the most trivial logic circuits are likely to include XOR-gates) - hence, for design of new architectures or simulators or virtual machines and simplification of existing ones--(e.g., http://www.date-conference.com/archive/conference/proceedings/PAPERS/1999/DATE99/PDFFILES/05A_6.PDF) and http://bochs.sourceforge.net/Virtualization_Without_Hardware_Final.pdf which includes: "The answer relies on the observation that subtracting an integer value from 0x gives the same result as XOR-ing that same value to 0x." And, perhaps the most useful use of all, for Bouton's solution of the game of Nim--both for the proof that his strategy "solves" the game and for an easy implementation of a Nim-playing program--and the only operator needed is XOR (e.g., http://www.wordiq.com/definition/Nim). wayne -- http://mail.python.org/mailman/listinfo/python-list
Re: missing 'xor' Boolean operator
On Wed, 15 Jul 2009 11:51:44 -0700 (PDT), Mark Dickinson wrote: >On Jul 15, 7:29 pm, Wayne Brehaut wrote: >> On Tue, 14 Jul 2009 11:47:41 -0700 (PDT), Mark Dickinson >> wrote: >> >I'd also guess that 'xor' would be much less used than 'and' or 'or', >> >but maybe that's just a reflection of the sort of code that I tend to >> >write. >> >> You're right about that!. It's used everywhere in: >> [snip examples and references] > >Those examples are (almost) all about the *bitwise* xor operator, >which exists in Python ('^') and, as you point out, has no shortage of >good uses. The discussion was about a *logical* xor, to parallel the >existing 'and' and 'or' operators. I thought you were saying your program domains didn't include a lot of requirements for xor in general, rather than just no uses for Boolean xor--and I'm used to thinking of xor on binary vectors as "Boolean" anyway so would still have been confused. The most common non-binary-bit-wise xor is the general "symmetric difference" of sets, most likely to be useful in list or dictionary processing or database-like contexts. Please see my suggested use-case for Steven below. wayne -- http://mail.python.org/mailman/listinfo/python-list
Re: missing 'xor' Boolean operator
On Tue, 14 Jul 2009 11:47:41 -0700 (PDT), Mark Dickinson wrote: >On Jul 14, 7:25 pm, "Dr. Phillip M. Feldman" >wrote: >> Current Boolean operators are 'and', 'or', and 'not'. It would be nice to >> have an 'xor' operator as well. > >Hmm. I don't think 'nice' is sufficient. You'd need to make the case >that it's sufficiently useful to justify adding a new keyword 'xor' to >the language; I suspect that would be an uphill struggle. :) === 8< === And for the objects for which it *is* sufficiently useful (sets) the xor operator ^ is available: >>> cheese = set(['cheddar', 'limburger', 'stilton']) >>> stinky = set(['skunk', 'limburger', 'stilton', 'polecat', 'doggy-doo', >>> 'civet']) >>> nasty = set(['doggy-doo', 'polecat', 'limburger', 'Perl']) >>> cheese & stinky # stinky cheese set(['limburger', 'stilton']) >>> cheese ^ stinky # either cheese or stinky but not both set(['doggy-doo', 'civet', 'polecat', 'skunk', 'cheddar']) >>> cheese ^ stinky ^ nasty # in an odd number of these sets (1 or 3) set(['civet', 'cheddar', 'Perl', 'limburger', 'skunk']) wayne -- http://mail.python.org/mailman/listinfo/python-list
Re: missing 'xor' Boolean operator
On 15 Jul 2009 09:11:44 GMT, Steven D'Aprano wrote: >On Tue, 14 Jul 2009 11:25:08 -0700, Dr. Phillip M. Feldman wrote: > >> Current Boolean operators are 'and', 'or', and 'not'. It would be nice >> to have an 'xor' operator as well. > >I've often wished there was too, for the sake of completeness and >aesthetics, I'd love to be able to write: > >a xor b > >instead of defining a function xor(a, b). > >Unfortunately, outside of boolean algebra and simulating electrical >circuits, I can't think of any use-cases for an xor operator. Do you have >any? Since xor in set theory is the symmetric difference, perhaps we'd like to know all items in exactly one of two word lists or dictionaries, or anything else we could easily set-ize: >>> cheese = set(['cheddar', 'limburger', 'stilton']) >>> stinky = set(['skunk', 'limburger', 'stilton', 'polecat', 'doggy-doo', >>> 'civet']) >>> nasty = set(['doggy-doo', 'polecat', 'limburger', 'Perl']) >>> cheese & stinky # stinky cheese set(['limburger', 'stilton']) >>> cheese ^ stinky # either cheese or stinky but not both set(['doggy-doo', 'civet', 'polecat', 'skunk', 'cheddar']) >>> cheese ^ stinky ^ nasty # in an odd number of these sets (1 or 3) set(['civet', 'cheddar', 'Perl', 'limburger', 'skunk']) Who hasn't needed that occasionally? wayne -- http://mail.python.org/mailman/listinfo/python-list
Re: analysis of algoritms
On Thu, 09 Sep 2010 18:26:52 -0400, Dave Angel wrote: > On 2:59 PM, Baba wrote: >> Hi >> >> In below code "the outer loop test in step 4 will execute ( n + 1 ) >> times (note that an extra step is required to terminate the for loop, >> hence n + 1 and not n executions), which will consume T4( n + 1 ) >> time." (from http://en.wikipedia.org/wiki/Analysis_of_algorithms) >> >> 1get a positive integer from input >> 2if n> 10 >> 3print "This might take a while..." >> 4for i = 1 to n >> 5for j = 1 to i >> 6print i * j >> 7print "Done!" >> >> Why does step 4 execute n+1 times? what is the exta step mentioned >> above >> >> tnx >> Baba >> >Why are you posting a question about BASIC syntax in a Python forum? >Python has no such statement, and its close approximations work much >differently. > >If you really want an abstract answer, then you should be decomposing >those BASIC statements into smaller atoms. The for statement is >composed of at least three "atoms", one of which is probably executed >n+1 times. > >A BASIC for statement for i=1 to n >decomposes into approximately: > >4a, i = 1 >4bcompare i to n >4cskip if greater > 5, 6 do some stuff >4d increment i REM And the vuitally important: 4e GOTO 4b But, as Robert noted, this is undoubtedly "pseudocode" rather than BASIC. Pity it's not Python-oriented pseudocode... >Note that the increment happens after steps 5 and 6, but it's part of line 4 > >Also note that the exact details depend thoroughly on the brand and >version of BASIC, there being at least 60 versions out there. For >example, I can think of at least three cases for what i will equal on >line 7. > >Incidentally, in some versions of BASIC, 4b and 4c might come after 4d, >and only be executed n times. > >DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Nautilus Python
On Mon, 27 Sep 2010 20:57:09 -0700 (PDT), Peter wrote: >On Sep 28, 12:31 pm, Steven D'Aprano t...@cybersource.com.au> wrote: >> On Mon, 27 Sep 2010 15:28:34 -0700, Eduardo Ribeiro wrote: >> > But it doesn't work. >> >> What do you mean "doesn't work"? >> >> - It crashes the operating system; >> - You get a core dump; >> - You get an exception; >> - It hangs forever, never doing anything; >> - It does something unexpected; >> - Something else? >> >> -- >> Steven > >It seems to be a fairly absolute statement - so I would assume all of >the above! :-) I assume "None of the above." Each of the above requires doing some work, so if "doesn't work" implies "does no work", then the closest it could come to that is: - It terminates almost immediately* without producing any output. *Required, or it might have been doing some work and just forgot to output the results. wwwayne -- http://mail.python.org/mailman/listinfo/python-list
Re: Introducing Kids to Programming: 2 or 3?
On Mon, 27 Sep 2010 12:45:44 -0400, Andreas Waldenburger wrote: >On Mon, 27 Sep 2010 17:48:06 +0200 Marco Gallotta > wrote: > >> Since these are kids, we feel the nice changes in 3 such as removing >> integer division will help in teaching. It will also remove confusion >> when they go to download Python and grab the latest version. Since >> they're just starting, chances are almost none will be hit by the >> limited library support for at least a year or two. > >That's your answer right there. > > >> They will, however, be hit by the confusion of seeing Python 2 code >> all over the web. > >Good point. Here is may suggestion: Make the kids aware of the 2/3 >issue as early as possible, but don't go into detail. === 8< === > Later on (once they know more programming constructs to >appreciate the differences), include another lecture, specifically on >the difference between Python 2 and Python 3. > >Disclaimer: I'm not an educator. Maybe this is horrible advice. Someone >with a better understanding of kids' and learner's minds please debunk >any nonsense I may have spouted here. The only obvious bit was assuming one should "lecture" to kids. Everything else sounds good. wwwayne >/W -- http://mail.python.org/mailman/listinfo/python-list