Re: Writing to a file

2011-03-25 Thread Gregory Ewing
John Gordon wrote: The write() way is much better. (However, I'm not sure it will do what you were expecting with the tilde in the file path.) It won't, but the os.path.expanduser() function can be used to fix that. -- Greg -- http://mail.python.org/mailman/listinfo/python-list

Re: Writing to a file

2011-03-25 Thread Gregory Ewing
jyoun...@kc.rr.com wrote: import os os.system('echo "Testing a... b... c..." > "~/Desktop/test2.txt"') This is like going out the back door, getting a ladder out of the shed and climbing through your bedroom window to get into bed at night, instead of just using the stairs. Use open/write/clo

Re: Fun python 3.2 one-liner

2011-03-30 Thread Gregory Ewing
Martin De Kauwe wrote: what is the character limit on a one liner :P. For PEP 8 compliance, 80 characters. :-) -- Greg -- http://mail.python.org/mailman/listinfo/python-list

Re: Python CPU

2011-04-02 Thread Gregory Ewing
Brad wrote: I've heard of Java CPUs. Has anyone implemented a Python CPU in VHDL or Verilog? Not that I know of. I've had thoughts about designing one, just for the exercise. It's doubtful whether such a thing would ever be of practical use. Without as much money as Intel has to throw at CPU

Re: Python CPU

2011-04-04 Thread Gregory Ewing
Paul Rubin wrote: You can order 144-core Forth chips right now, http://greenarrays.com/home/products/index.html They are asynchronous cores running at around 700 mhz, so you get an astounding amount of raw compute power per watt and per dollar. But for me at least, it's not that easy to fi

Re: Python CPU

2011-04-04 Thread Gregory Ewing
John Nagle wrote: A tagged machine might make Python faster. You could have unboxed ints and floats, yet still allow values of other types, with the hardware tagging helping with dispatch. But it probably wouldn't help all that much. It didn't in the LISP machines. What might help more

Re: Python CPU

2011-04-04 Thread Gregory Ewing
Terry Reedy wrote: So a small extension to array with .map, .filter, .reduce, and a wrapper class would be more useful than I thought. Also useful would be some functions for doing elementwise operations between arrays. Sometimes you'd like to just do a bit of vector arithmetic, and pulling in

Re: Python CPU

2011-04-04 Thread Gregory Ewing
geremy condra wrote: I'd be interested in seeing the performance impact of this, although I wonder if it'd be feasible. A project I have in the back of my mind goes something like this: 1) Design an instruction set for a Python machine and a microcode architecture to support it 2) Write a si

Re: Python CPU

2011-04-04 Thread Gregory Ewing
Paul Rubin wrote: Vector processors are back, they just call them GPGPU's now. Also present to some extent in the CPU, with MMX, Altivec, etc. -- Greg -- http://mail.python.org/mailman/listinfo/python-list

Re: Fun python 3.2 one-liner

2011-04-04 Thread Gregory Ewing
Chris Angelico wrote: (Remind me how it is that Python code is more readable than line noise or Perl code?) Crazy thought: I wonder if Perl programmers have "multi line Perl" competitions where they laugh their heads off at how readable the code is, and how nobody in their right mind would eve

Re: Feature suggestion -- return if true

2011-04-16 Thread Gregory Ewing
Chris Angelico wrote: def fac(n): # attempt to get from a cache return? cache[n] # not in cache, calculate the value ret=1 if n<=1 else fac(n-1)*n # and cache and return it cache[n]=ret; return ret My idiom for fetching from a cache looks like this: def get_from_cach

Re: Equivalent code to the bool() built-in function

2011-04-17 Thread Gregory Ewing
candide wrote: bool(x) is nothing more than a shortcut for the following expression : True if x else False. It's a much shorter and easier-to-read shortcut. Also keep in mind that if-else expressions are quite a recent addition to the language. Before that, we had 'not not x' as another equi

Re: Equivalent code to the bool() built-in function

2011-04-17 Thread Gregory Ewing
Chris Angelico wrote: Well, of course you can always implement bool as an int; Which Python used to do once upon a time -- and still does in a way, because bool is a subclass of int. The bool type was added mainly to provide a type that prints out as 'True' or 'False' rather than 1 or 0. This

Re: Feature suggestion -- return if true

2011-04-17 Thread Gregory Ewing
Steven D'Aprano wrote: I'm sure you realise that that snippet needlessly recalculates any cached result that happens to be false, but others reading might not. I only use it as written when I'm dealing with types that don't have false values. If I did need to cache such a type, I would use a d

Re: Equivalent code to the bool() built-in function

2011-04-18 Thread Gregory Ewing
John Nagle wrote: Pascal got this right. (A nice feature of Pascal was that "packed array of boolean" was a bit array). C, which originally lacked a "bool" type, got it wrong. So did Python. If Python had had a boolean type from the beginning, it probably wouldn't have been a subclass of in

Re: Equivalent code to the bool() built-in function

2011-04-18 Thread Gregory Ewing
Chris Angelico wrote: Remind me some day to finish work on my "ultimate programming language", which starts out with a clean slate and lets the programmer define his own operators and everything. Didn't someone already do that and call it "lisp"? :-) -- Greg -- http://mail.python.org/mailman/

Re: Feature suggestion -- return if true

2011-04-18 Thread Gregory Ewing
Chris Angelico wrote: Question: How many factorial functions are implemented because a program needs to know what n! is, and how many are implemented to demonstrate recursion (or to demonstrate the difference between iteration and recursion)? :) A related question is how often factorial functi

Re: Equivalent code to the bool() built-in function

2011-04-19 Thread Gregory Ewing
Jean-Paul Calderone wrote: Also boolean xor is the same as !=. Only if you have booleans. Even without short circuiting, a boolean xor operator could provide the service of automatically booling things for you (is that a word?). Jean-Paul -- http://mail.python.org/mailman/listinfo/python-li

Re: Vectors

2011-04-21 Thread Gregory Ewing
Algis Kabaila wrote: the Vector3 class is available without any prefix euclid: import euclid v = Vector3(111.., 222.2, 333.3) Doesn't work that way for me: Python 2.7 (r27:82500, Oct 15 2010, 21:14:33) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "lic

Re: learnpython.org - an online interactive Python tutorial

2011-04-25 Thread Gregory Ewing
harrismh777 wrote: maybe the way to be really consistent (especially with the Zen of Python, explicit is better than implicit) that int --> float --> complex (imaginary) should not occur either ! Applying parts of the Zen selectively can be dangerous. Practicality also beats purity. I've used

Re: Reliably call code after object no longer exists or is "unreachable"?

2011-04-28 Thread Gregory Ewing
Jack Bates wrote: Python's __del__ or destructor method works (above) - but only in the absence of reference cycles (below). An object, with a __del__ method, in a reference cycle, causes all objects in the cycle to be "uncollectable". Store a weak reference to the object somewhere with a call

ANN: Sixth Pyggy Awards

2011-04-30 Thread Gregory Ewing
Registrations are now open for the Sixth Pyggy Awards. Judging will be from 17-31 July 2011. http://pyggy.pyweek.org/ This time, entry is open to any Python-based game, not just PyWeek games, and not just games developed during PyWeek or Pyggy. So if you've had a Python game project on the ba

Re: What other languages use the same data model as Python?

2011-05-01 Thread Gregory Ewing
Steven D'Aprano wrote: Python uses a data model of "name binding" and "call by object" (also known as "call by sharing"). It can be summed up in a less jargony way by saying that all data is stored in heap-allocated objects, and variables refer to objects rather than containing them directly.

Re: What other languages use the same data model as Python?

2011-05-01 Thread Gregory Ewing
Terry Reedy wrote: While Guido does not, that I know of, credit CLU as Python's direct inspiration, I think it (and Barbara Liskov) as the originator of Python's data model. I believe she thought of the call-by-object semantics as something of an innovation. I don't think she can claim credi

Re: Py_INCREF() incomprehension

2011-05-01 Thread Gregory Ewing
Hegedüs Ervin wrote: I've put it a Py_INCREF() after every PyModule_AddObject(), eg.: PyModule_AddObject(o, "error", cibcrypt_error_nokey); Py_INCREF(cibcrypt_error_nokey); That looks correct, because PyModule_AddObject is documented as stealing a reference to the object. By the way,

Re: Coolest Python recipe of all time

2011-05-02 Thread Gregory Ewing
Terry Reedy wrote: The trick is that replacing x with j and evaluating therefore causes (in Python) all the coefficients of x (now j) to be added together separately from all the constant terms to reduce the linear equation to a*x+b (= 0 implied). Hmmm... so if we used quaternions, could we s

Re: importing class objects from a pickled file

2011-05-04 Thread Gregory Ewing
Catherine Moroney wrote: I am having some problems reading the object back out, as I get complaints about "unable to import module X". The only way I have found around it is to run the read-file code out of the same directory that contains the X.py file Even when I put statements into the c

Re: Fibonacci series recursion error

2011-05-04 Thread Gregory Ewing
Chris Angelico wrote: There's definitely something attractive about that letter. Lots of programming languages' names start with P. Including one I invented some years ago, that (in the spirit of C and its derivatives) was called simply "P". (I was playing around with Sun's NeWS window server

Re: Hooking into Python's memory management

2011-05-04 Thread Gregory Ewing
Daniel Neilson wrote: 1) Maintain a list of object id()'s for objects that have been created. Ideally, this list would also contain the file & line number where the object was created. 2) Provide a "deallocate" function that will remove a given object's id() from the list from (1). 3) P

Re: What other languages use the same data model as Python?

2011-05-04 Thread Gregory Ewing
Hans Georg Schaathun wrote: Is transmission by name the same as call by object? No, it's not. With call-by-name, the caller passes a small function (known as a "thunk") that calculates the address of the parameter. Every time the callee needs to refer to the parameter, it evaluates this functio

Re: What other languages use the same data model as Python?

2011-05-05 Thread Gregory Ewing
Hans Georg Schaathun wrote: With the references being purely abstract entities and not data objects, It's not clear to me that references are any more abstract than objects, or to put it another way, that objects are any less abstract than references. After all, in normal Python usage you neve

Re: What other languages use the same data model as Python?

2011-05-05 Thread Gregory Ewing
harrismh777 wrote: 'C' is still the best high-level language on that processor. Some would argue that C is actually better than assembler these days, because modern architectures are so freaking complicated that it takes a computer to figure out the best instruction sequence. :-( -- Greg -- h

Re: What other languages use the same data model as Python?

2011-05-05 Thread Gregory Ewing
harrismh777 wrote: That is the $10,000,000 dollar problem... how to extricate ourselves from the von Neumann processor. *Everthing* comes down to that... its hilarious to hear folks talk about lambda the ultimate (especially those guys on Lambda the Ultimate) when there is no such thing until

Re: What other languages use the same data model as Python?

2011-05-05 Thread Gregory Ewing
John Nagle wrote: A reasonable compromise would be that "is" is treated as "==" on immutable objects. That wouldn't work for tuples, which can contain references to other objects that are not immutable. -- Greg -- http://mail.python.org/mailman/listinfo/python-list

Re: What other languages use the same data model as Python?

2011-05-05 Thread Gregory Ewing
harrismh777 wrote: 'C' does provide for pointers which are used by all 'C' programmers to firmly provide pass-by-reference in their coding Yes, but when they do that, they're building an abstraction of their own on top of the facilities provided by the C language. C itself has no notion of pass

Re: seems like a bug in isinstance()

2011-05-07 Thread Gregory Ewing
Chris Rebert wrote: This is because you did `from Point import ...` in file2.py, whereas in file1.py you did `from openopt.kernel.Point import ...`. These 2 different ways of referring to the same module are sufficient to "trick"/"outsmart" (C)Python and cause it to import the same module twice

Re: Dictionary Views -- good examples? [was Re: Python 3 dict question]

2011-05-07 Thread Gregory Ewing
Ethan Furman wrote: Ian Kelly wrote: next(iter(myDict.items())) Which is becoming less elegant. If you're doing this sort of thing a lot you can make a little helper function: def first(x): return next(iter(x)) then you get to say first(myDict.items()) -- Greg -- http://mail.pyt

Re: What other languages use the same data model as Python?

2011-05-07 Thread Gregory Ewing
Hans Georg Schaathun wrote: You cannot reference nor manipulate a reference in python, and that IMHO makes them more abstract. You can manipulate them just fine by moving them from one place to another: a = b You can use them to get at stuff they refer to: a = b.c a[:] = b[:] You

Re: What other languages use the same data model as Python?

2011-05-07 Thread Gregory Ewing
John Nagle wrote: Such tuples are still identical, even if they contain identical references to immutable objects. The point is you'd have to do the comparison only one level deep, so it wouldn't be exactly the same as == on tuples. -- Greg -- http://mail.python.org/mailman/listinfo/pytho

Re: What other languages use the same data model as Python?

2011-05-07 Thread Gregory Ewing
On Thu, 05 May 2011 07:43:59 +1000, Ben Finney wrote: ‘x’ is a name. Names are bound to values. Talk of “variable” only confuses the issue because of the baggage carried with that term. But to use 'name' as a complete replacement for 'variable', you have to stretch it to include things like a[

Re: What other languages use the same data model as Python?

2011-05-07 Thread Gregory Ewing
Andreas Tawn wrote: If True and False: waveFunction.collapse(cat) Call-by-entanglement would be interesting. Anything that the callee does to the parameter would affect the caller, but you would only be able to tell by examining a trace of the output afterwards. -- Greg -- http://mail.pyt

Re: What other languages use the same data model as Python?

2011-05-07 Thread Gregory Ewing
Grant Edwards wrote: if you feel it just right and you have just the right synchro-mesh setup, you can slide from 3rd into 4th without every touching the clutch peddle... and if that isn't automatic, I don't know what is No, that's _not_ automatic if you have to do it yourself. It's au

Re: What other languages use the same data model as Python?

2011-05-07 Thread Gregory Ewing
Chris Angelico wrote: I think "manipulate" here means things like pointer arithmetic, I don't believe that allowing arithmetic on pointers is a prerequisite to considering them first-class values. You can't do arithmetic on pointers in Pascal, for example, but nobody argues that Pascal pointer

Re: What other languages use the same data model as Python?

2011-05-07 Thread Gregory Ewing
Ben Finney wrote: No, I think not. The term “variable” usually comes with a strong expectation that every variable has exactly one name. I would say that many variables don't have names *at all*, unless you consider an expression such as a[i] to be a "name". And if you *do* consider that to be

Re: seems like a bug in isinstance()

2011-05-07 Thread Gregory Ewing
dmitrey wrote: Yes, you are right. But I have to do it due to another issue I haven't solved yet: Python3 imports don't see files from same directory http://groups.google.com/group/comp.lang.python/browse_thread/thread/9470dbdacc138709# That's because the syntax for relative imports has ch

Re: Django/AppEngine DevSoup

2011-05-07 Thread Gregory Ewing
John wrote: There's eclipse, pydev, django non-rel, mediagenerator, etc Would it be stupid of me to just use the simple, clean notepad++ & django with aims to port into appengine after I finish in a week? I don't want to deal with all of the other stuff. Will this come back to haunt me in 7

Re: What other languages use the same data model as Python?

2011-05-08 Thread Gregory Ewing
Steven D'Aprano wrote: Since you haven't explained what you think is happening, I can only guess. Let me save you from guessing. I'm thinking of a piece of paper with a little box on it and the name 'a' written beside it. There is an arrow from that box to a bigger box.

Re: What other languages use the same data model as Python?

2011-05-09 Thread Gregory Ewing
Steven D'Aprano wrote: It's just that the term "variable" is so useful and so familiar that it's easy to use it even for languages that don't have variables in the C/ Pascal/Fortran/etc sense. Who says it has to have the Pascal/Fortran/etc sense? Why should static languages have a monopoly on

Re: What other languages use the same data model as Python?

2011-05-09 Thread Gregory Ewing
Steven D'Aprano wrote: Or Chinese Gooseberries, better known by the name thought up by a marketing firm, "kiwi fruit". And I'm told that there is a language (one of the Nordic ones, IIRC) where "kiwi" means "stone". So in that country they wonder why they should be getting so excited about som

Re: What other languages use the same data model as Python?

2011-05-10 Thread Gregory Ewing
Steven D'Aprano wrote: All very good, but that's not what takes place at the level of Python code. It's all implementation. Actually, you're right. What I've presented is a paper-and-pencil implementation of the Python data model. Together with a set of rules for manipulating the diagram under

Re: What other languages use the same data model as Python?

2011-05-10 Thread Gregory Ewing
Chris Angelico wrote: There has to be a way to get from some mythical "home" location (which we know in Python as locals()+globals()+current expression - the "current namespace") to your object. That might involve several names, or none at all, but if there's no such path, the object is unrefere

Merge multiple source directories into one package with distutils?

2011-05-10 Thread Gregory Ewing
Is there a straightforward way to tell distutils to merge .py files from more than one source directory into a single package when installing? PyGUI consists of some generic modules and some platform specific ones, that conceptually all live at the same level within a single package. In the sourc

Re: Merge multiple source directories into one package with distutils?

2011-05-11 Thread Gregory Ewing
Miki Tebeka wrote: .py files from more than one source directory into a single package when installing? The Selenium Python bindings does something like that, have a look at http://selenium.googlecode.com/svn/trunk/setup.py Unless I'm missing something, nothing out of the ordinary is happenin

Re: checking if a list is empty

2011-05-11 Thread Gregory Ewing
Hans Georg Schaathun wrote: 0 is a number as real and existent as any other, one would think that the empty list is also as real and existent as any other list. 0 does have some special properties, though, such as being the additive identity and not having a multiplicative inverse. Adding fals

Re: checking if a list is empty

2011-05-11 Thread Gregory Ewing
Roy Smith wrote: Hans Georg Schaathun wrote: If both are numbers, they are converted to a common type. Otherwise, objects of different types always compare unequal That's just the default treatment for unrelated types that don't know anything about each other. I would guess that the list's =

Re: checking if a list is empty

2011-05-13 Thread Gregory Ewing
Ian Kelly wrote: If a math major comes to you wanting to learn some programming for theorem-proving, bearing in mind that they probably aren't interested in learning more than a single language, I would question whether theorem-proving is the *only* thing they will ever want to do with a progra

Re: checking if a list is empty

2011-05-13 Thread Gregory Ewing
harrismh777 wrote: ... and I'm also lumping two other languages into this 'category'... namely, Scheme, and Erlang. Scheme isn't really a functional language, though. You can use a subset of it in a functional way, but it doesn't have the sort of built-in support for pattern matching and cas

Re: checking if a list is empty

2011-05-13 Thread Gregory Ewing
rusi wrote: Dijkstra's problem (paraphrased) is that python, by choosing the FORTRAN alternative of having a non-first-class boolean type, hinders scientific/mathematical thinking/progress. Python doesn't have the flaw that Dijkstra was talking about. Fortran's flaw wasn't so much the lack of

Re: turn monitor off and on

2011-05-15 Thread Gregory Ewing
Terry Reedy wrote: My monitor then displays 'No signal detected' in a box and puts itself into a low-power state awaiting a signal. Even if the monitor does not do that, a black screen should use less power. I'm not so sure about that. If the monitor is an LCD and isn't doing anything to redu

Re: hash values and equality

2011-05-21 Thread Gregory Ewing
Ethan Furman wrote: Ulrich Eckhardt wrote: If two equal objects have different hashes, they will be stored in different places in the hash map. Looking for object1 will then not turn up with object2, even though they are equal. In this case this is the behavior I want. You can't rely on i

Re: Faster Recursive Fibonacci Numbers

2011-05-21 Thread Gregory Ewing
Chris Angelico wrote: It seems strange to smoothly slide from native integer to long integer and just keep on going, and yet to be unable to do the same if there's a fractional part on it. The trouble is that if you always compute exact results by default, the number of digits required can blow

Re: Abandoning Python

2011-05-22 Thread Gregory Ewing
Ed Keith wrote: Have you looked at Falcon (http://www.falconpl.org/)? This paragraph on the first page doesn't exactly fire me with enthuiasm: Falcon provides six integrated programming paradigms: procedural, object oriented, prototype oriented, functional, tabular and message oriented. And y

Re: Abandoning Python

2011-05-23 Thread Gregory Ewing
Steven D'Aprano wrote: On Mon, 23 May 2011 13:11:40 +1200, Gregory Ewing wrote: ...until you want to read someone *else's* code, that is. The same might be said about Python, which supports procedural, OO and functional styles out of the box. But it only uses *one* syntax and c

Re: Why did Quora choose Python for its development?

2011-05-26 Thread Gregory Ewing
John Bokma wrote: A Perl programmer will call this line noise: double_word_re = re.compile(r"\b(?P\w+)\s+(?P=word)(?!\w)", re.IGNORECASE) for match in double_word_re.finditer(text): print ("{0} is duplicated".format(match.group("word")) Actually, Python program

Re: The worth of comments

2011-05-28 Thread Gregory Ewing
Grant Edwards wrote: After hearing/reading somebody for years, I don't seem to have a detailed image of them in my head, but when I finally do see a picture of them, my initial reaction is almost always "no, that's not at all what I thought he/she looked like". It works the other way, too. I'v

Re: The worth of comments

2011-05-28 Thread Gregory Ewing
Irmen de Jong wrote: I don't see how that is opposed to what Grant was saying. It's that these 'contracts' tend to change and that people forget or are too lazy to update the comments to reflect those changes. However, I can't see that deleting the comment documenting the contract can be the

Re: float("nan") in set or as key

2011-05-28 Thread Gregory Ewing
MRAB wrote: float("nan") can occur multiple times in a set or as a key in a dict: >>> {float("nan"), float("nan")} {nan, nan} except that sometimes it can't: >>> nan = float("nan") >>> {nan, nan} {nan} NaNs are weird. They're not equal to themselves: Python 2.7 (r27:82500, Oct 15 2010,

Re: The worth of comments

2011-05-29 Thread Gregory Ewing
Ben Finney wrote: You omit the common third possibility: *both* the comment and the code are wrong. In that case, the correct response is to fix both of them. :-) -- Greg -- http://mail.python.org/mailman/listinfo/python-list

Re: Case-insensitive string equality

2017-09-03 Thread Gregory Ewing
Stefan Ram wrote: But of course, actually the rules of orthography require "Maße" or "Masse" and do not allow "MASSE" or "MASZE", just as in English, "English" has to be written "English" and not "english" or "ENGLISH". While "english" is wrong in English, there's no rule against usin

Re: A question on modification of a list via a function invocation

2017-09-04 Thread Gregory Ewing
Chris Angelico wrote: This is another proof that you can't divide everything into "pass by value" vs "pass by reference" True, but that doesn't mean you should deny that something is pass-by-value when it actually is. In C, a string is not an entity; it's simply an array of characters. Arrays

Re: A question on modification of a list via a function invocation

2017-09-04 Thread Gregory Ewing
Stefan Ram wrote: JavaScript and Python do not have references as values Yes, they do. The difference is that they don't have any way of *not* having references as values, so there's less need to use the word explicitly in that way -- most of the time it's just understood. Nevertheless, terms

Re: A question on modification of a list via a function invocation

2017-09-05 Thread Gregory Ewing
Steve D'Aprano wrote: The third entity is the reference linking the name to the object (the arrow). This isn't a runtime value in Python, nor is it a compile time entity that exists in source code. It is pure implementation, and as such, exists outside of the Python domain. The fact that there

Re: A question on modification of a list via a function invocation

2017-09-05 Thread Gregory Ewing
Steve D'Aprano wrote: On Tue, 5 Sep 2017 02:51 am, Stefan Ram wrote: > I am assuming that there are two argument passing mechanismss in the languages mentioned by me (C, C++, VBA, C#, Java, JavaScript, and Python): - pass by aliassing (reference) - pass "as if by assignment" That assumpti

Re: A question on modification of a list via a function invocation

2017-09-05 Thread Gregory Ewing
Dennis Lee Bieber wrote: Pascal, probably Modula-2, Visual BASIC are closer to the C++ reference semantics, in that the definition of a function declares how the argument(s) are passed. Well, sort of. In Pascal and Modula, and also VB I think, parameters are the only things that can be

Re: A question on modification of a list via a function invocation

2017-09-05 Thread Gregory Ewing
Steve D'Aprano wrote: [quoting Scott Stanchfield] Figure 7: (Java) Defining a Dog pointer Dog d; When you write that definition, you are defining a pointer to a Dog object, not a Dog object itself. [end quote] Here Scott mixes up what the compiler does (creates a pointer

Re: A question on modification of a list via a function invocation

2017-09-06 Thread Gregory Ewing
Rustom Mody wrote: 2. is — machine representation, too fine to be useful Disagree - "is" in Python has an abstract definition that doesn't depend on machine representation. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: A question on modification of a list via a function invocation

2017-09-06 Thread Gregory Ewing
Steve D'Aprano wrote: No, they aren't first-class. Maybe not fully, but you can do a lot more with them than you can in Pascal or Modula-2. - Containers of references are not allowed. You can't have arrays of references, but struct and class members can be references, so you can certainly b

Re: A question on modification of a list via a function invocation

2017-09-06 Thread Gregory Ewing
Chris Angelico wrote: You can't do this with Python, since pointer arithmetic fundamentally doesn't exist. Pointer arithmetic doesn't exist in Pascal either, yet Pascal most definitely has pointers as a distinct data type. Insisting that only pointer arithmetic counts as "manipulating" pointer

Re: A question on modification of a list via a function invocation

2017-09-06 Thread Gregory Ewing
Steven D'Aprano wrote: But many (perhaps even most) people have no problem dealing with location as a metaphor, where being in two places (metaphorically) is no problem at all: - I am in love, in trouble and in denial all at once. Sometimes the word "in" implies physical location, sometimes

Re: A question on modification of a list via a function invocation

2017-09-06 Thread Gregory Ewing
Steven D'Aprano wrote: Not in standard Pascal, but most actual Pascal compilers let you perform pointer arithmetic. Well, sort of. In the ones I've seen, it's more like being able to cast a pointer to an integer, do arithmetic on that and then cast it back. The results are about as implementati

Re: Please improve these comprehensions (was meaning of [ ])

2017-09-06 Thread Gregory Ewing
Seems to me you're making life difficult for yourself (and very inefficient) by insisting on doing the whole computation with sets. If you want a set as a result, it's easy enough to construct one from the list at the end. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: A question on modification of a list via a function invocation

2017-09-07 Thread Gregory Ewing
Rustom Mody wrote: I said: In that case please restate the definition of 'is' from the manual which invokes the notion of 'memory' without bringing in memory. I don't know whether it's in the manual, but at least for mutable objects, there is a way to define the notion of "same object" that do

Re: A question on modification of a list via a function invocation

2017-09-07 Thread Gregory Ewing
Steve D'Aprano wrote: I think that these two increment procedures will be (more or less?) equivalent: procedure increment(var n: integer); begin n := n + 1 end; procedure increment2(p: intpointer); begin p^ := p^ + 1 end; They are, with the proviso that, in standard Pascal, in

Re: A question on modification of a list via a function invocation

2017-09-08 Thread Gregory Ewing
Rustom Mody wrote: 2. is — machine representation, too fine to be useful No, it's *not* machine representation. As I pointed out before, it's part of the abstract semantics of Python. And it's not "too fine to be useful". On the contrary, being aware of which objects are the same and which are

Re: A question on modification of a list via a function invocation

2017-09-08 Thread Gregory Ewing
Steve D'Aprano wrote: A harder question is, what if you take a random number from the Integers? How many digits will it have in (say) base 10? I don't have a good answer to that. I think it may be ill-defined. I think the answer is that on average it has infinitely many digits -- despite every

Re: A question on modification of a list via a function invocation

2017-09-08 Thread Gregory Ewing
Steve D'Aprano wrote: py> class K: # defines an object ... def __init__(self, x): ... self.x = x ... def append(self, value): ... self.x.append(value) ... py> a = [] py> b = K(a) py> a is b # these are not the same object (they're different types) False py> b.appe

Re: A question on modification of a list via a function invocation

2017-09-08 Thread Gregory Ewing
Rustom Mody wrote: I'd like to know what these rules are I can't give you a complete list of them off the top of my head, but some examples of the kind of rules I have in mind are: * After the assigment a = b a and b refer to the same object. * After x = [e1, e2, e3, ...] x refers

Re: A question on modification of a list via a function invocation

2017-09-08 Thread Gregory Ewing
Rustom Mody wrote: Models are needed Math is one possible model Machines are another I'm not sure there's any real distinction between "math" and "machines". A Turing machine, for example, is an idealised mathematical model of computation. Maybe the distiction you're trying to get at is "stat

Re: A question on modification of a list via a function invocation

2017-09-08 Thread Gregory Ewing
Marko Rauhamaa wrote: I definitely trust that: a = b assert a is b even when b holds an immutable object. That's true, but there's rarely a good use case for that fact that isn't better addressed with an equality comparison rather than an 'is' test. As an example, back in the days of s

Re: tictactoe script - commented - may have pedagogical value

2017-09-08 Thread Gregory Ewing
Steven D'Aprano wrote: But anyway... it doesn't seem to me that the page is doing any computation using HTML. It's more like a book listing a table of primes. It's a "Choose Your Own Game Of Tic-Tac-Toe" book! -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: A question on modification of a list via a function invocation

2017-09-08 Thread Gregory Ewing
Steve D'Aprano wrote: I don't think that talking about the average integer is meaningful. We're not averaging the integers, we're averaging their numbers of digits, which are natural numbers. To do this rigorously you could write down an expression for the average length of integers up to som

Re: A question on modification of a list via a function invocation

2017-09-08 Thread Gregory Ewing
Steve D'Aprano wrote: The paradox of the axe is one illustration of the difficulty in defining "the same" in full generality. The axe situation doesn't arise in Python, because "same object" in Python is a concept that only applies to objects existing at the same time. There's no way to even a

Re: Why do we nned both - __init__() and __new__()

2017-09-08 Thread Gregory Ewing
dieter wrote: In the general case, constructing an object can be split into two subtasks: obtain a raw piece of storage able to manage the object's state; initialize the object's state. The first subtask is handled by "__new__", the second by "__init__". Except that's not quite correct, because

Re: The Incredible Growth of Python (stackoverflow.blog)

2017-09-09 Thread Gregory Ewing
Pavol Lisy wrote: Interesting reading: https://stackoverflow.blog/2017/09/06/incredible-growth-python/?cb=1 So, Python's rate of expansion is accelerating, like the universe. Does that mean there's some kind of dark energy fuelling its growth? -- Greg -- https://mail.python.org/mailman/listinf

Re: Using Python 2

2017-09-10 Thread Gregory Ewing
Rick Johnson wrote: Heck, when is the last time GvR participated in any discussion outside the hermetic bubble of Python-Dev or Python-Ideas? I'd hardly call python-ideas "hermetic". Anyone is free to post there and participate in discussions. Python-dev is open to anyone too, the only differe

Re: The Incredible Growth of Python (stackoverflow.blog)

2017-09-11 Thread Gregory Ewing
Chris Angelico wrote: Async functions in JS are an alternative to callback hell; most people consider async functions in Python to be an alternative to synchronous functions. What do you base that on? Seems to me async is an alternative to callback-based frameworks such as Twisted. Calling asy

Re: Python dress

2017-09-12 Thread Gregory Ewing
Larry Martell wrote: https://svahausa.com/collections/shop-by-interest-1/products/python-code-fit-flare-dress The only disadvantage might be the GIL interfering with parallel processing using multiple machines in a laundromat. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: "tkinter"

2017-09-13 Thread Gregory Ewing
Sean DiZazzo wrote: I usually just say "tinker", since it's easy... +1. All we need now are modules called talior, sodlier and psye. Should I write a PEP? -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Old Man Yells At Cloud

2017-09-16 Thread Gregory Ewing
Chris Angelico wrote: Or machine code on every CPU I've ever worked with. Dividing integers yields an integer. Every machine language I've used has different sets of instructions for int and float arithmetic, so there's no chance of confusion. -- Greg -- https://mail.python.org/mailman/listinf

Re: Old Man Yells At Cloud

2017-09-16 Thread Gregory Ewing
Paul Rubin wrote: Python 2 does something reasonable I don't agree. It might be reasonable in a statically-typed language, but in a dynamically-typed language where you're encouraged to use ints as stand-ins for integer-valued floats, it's an invitation for trouble. There are good reasons it wa

<    1   2   3   4   5   6   7   8   9   10   >