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

2017-09-06 Thread Steve D'Aprano
ing it). The point of making the assertion is to pass on information that would otherwise by ambiguous: "There is that same (identity) cat again (not merely one that looks like it)." -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

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

2017-09-06 Thread Steve D'Aprano
list with multiple links to the same video on Youtube, one which claims to prove that the world is not a moving sphere. List admins, can you please remove nopsidy's spam posts, and unsubscribe him if possible? -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and

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

2017-09-06 Thread Steve D'Aprano
...] > Yes it is. Pascal VAR parameters are exactly like Python a assignment. Proof by assertion? "It is true, because I say it is true!" -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

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

2017-09-06 Thread Steve D'Aprano
use the key to the puzzle is > that everything matches a line from the following look-up table: > > 5 => 5 > 7 => 12 > 9 => 21 > 19 => banana Well played sir! -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: tictactoe script - commented - may have pedagogical value

2017-09-06 Thread Steve D'Aprano
same way that people stopped taking me seriously when I > implemented Fizz Buzz in CSS. > > Though they were rather amused... CSS is Turing complete. If they stopped taking you seriously, that speaks volumes about *them* rather than either you or CSS. I am intrigued by the (alleged?) HTML ver

Re: tictactoe script - commented - may have pedagogical value

2017-09-07 Thread Steve D'Aprano
ther than being any > sort of "hey look, HTML is a programming language" thing. Which is what I thought it was. I thought I had learned something new, but it turned out I was right again :-( -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Design: method in class or general function?

2017-09-07 Thread Steve D'Aprano
at takes an instance, > a dict, a key, and an optional value? I'm afraid your example is too generic for me to give an opinion. Do you literally mean a method called "method"? What does it do? -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure

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

2017-09-07 Thread Steve D'Aprano
, and I think I can count the number of times I've used __new__ on the fingers of one hand. Maybe two hands. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

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

2017-09-07 Thread Steve D'Aprano
ng if you declare an array parameter without "var", and copy the whole array. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

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

2017-09-07 Thread Steve D'Aprano
On Fri, 8 Sep 2017 02:24 am, Chris Angelico wrote: > On Fri, Sep 8, 2017 at 1:30 AM, Steve D'Aprano > wrote: >> On Fri, 8 Sep 2017 12:28 am, Chris Angelico wrote: >> >>> languages without mutable objects don't >>> really care whether they're p

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

2017-09-07 Thread Steve D'Aprano
umber base you are using. 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. [1] https://en.wikipedia.org/wiki/Almost_all -- Steve “Cheer up,”

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

2017-09-07 Thread Steve D'Aprano
r don't apply to Python objects, or they apply equally to all objects in the universe and there's nothing we can do about it. Either way, the problem of defining the Python `is` operator without referring to memory is solved. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

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

2017-09-08 Thread Steve D'Aprano
On Fri, 8 Sep 2017 05:48 pm, Gregory Ewing wrote: > 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-defi

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

2017-09-08 Thread Steve D'Aprano
On Fri, 8 Sep 2017 05:54 pm, Gregory Ewing wrote: > 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) >

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

2017-09-08 Thread Steve D'Aprano
On Fri, 8 Sep 2017 08:20 pm, Ben Bacarisse wrote: > Steve D'Aprano writes: > >> On Fri, 8 Sep 2017 12:28 am, Chris Angelico wrote: >> >>> languages without mutable objects don't >>> really care whether they're pass-by-X or pass-by-Y. >>

Re: Using Python 2

2017-09-08 Thread Steve D'Aprano
port. (By the way, RHEL 6 goes out of Production Phase 3 in 2020.) -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Delay a computation in another thread

2017-09-08 Thread Steve D'Aprano
On Sun, 3 Sep 2017 03:03 am, MRAB wrote: > On 2017-09-02 11:59, Steve D'Aprano wrote: >> On Sat, 2 Sep 2017 08:53 pm, Steve D'Aprano wrote: >> >>> I want to delay a computation and then print it, in the REPL (interactive >>> interpreter). I have

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

2017-09-08 Thread Steve D'Aprano
On Fri, 8 Sep 2017 01:01 pm, Rustom Mody wrote: > On Friday, September 8, 2017 at 7:39:38 AM UTC+5:30, Steve D'Aprano wrote: >> Rustom, I've already given you the definitive answer to your question about >> how to define `is` without talking about memory. You haven

Re: class inheritance when not defined

2017-09-08 Thread Steve D'Aprano
eigner: "Who is the father of this class?" Native: *PLONK* I'll leave you to guess where I think your response fits in this scale :-) -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Using Python 2

2017-09-08 Thread Steve D'Aprano
you won't even get *paid* support.) I know of a couple of companies still running Python 1.5 apps. They work, they're not connected to the Internet, they don't care about bug fixes or security upgrades, so they have no reason to upgrade. But they're sure not writing *new* app

Re: Using Python 2

2017-09-08 Thread Steve D'Aprano
; and make a dispassionate choice according to which one has the best cost/benefit ratio. And that choice won't always be #2. [1] Depends on the code base, and the developers. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

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

2017-09-08 Thread Steve D'Aprano
#x27;s the thing about infinity. No matter how huge the number is, it is still falls infinitely short of infinite. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Using Python 2

2017-09-08 Thread Steve D'Aprano
rtage of expensive Python rockstars who make unreasonable demands like "decent working conditions" and "life-work balance"; - perhaps it is worth the increased cost of re-writing your app to get better performance or reliability (or at least somebody thinks so...) -- Steve “Che

Re: Using Python 2

2017-09-08 Thread Steve D'Aprano
move from Python 2 to 3 then continue > to help answer questions when they are Python 2 based. As we do. Even if some of us can't help evangelising for Python 3 when they do so :-) -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Best way to insert sorted in a list

2017-09-08 Thread Steve D'Aprano
thod. If you think it is fast, that's because you have only tested it on small lists. Try a list with (say) a million items. Probably the best way is to use the bisect module to insert into a sorted list. Or append to the end, then sort in place. Python's sort is *very* efficient with al

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

2017-09-08 Thread Steve D'Aprano
On Sat, 9 Sep 2017 10:34 am, Gregory Ewing wrote: > 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 >

Re: Hat difference between "" and '' in string definition

2017-09-09 Thread Steve D'Aprano
#x27;bbb'", 'us-ascii' ), \ > |... byteorder='big', signed=False ) > |-21491679493 > > . And they say Germans have no sense of humour :-) -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Using Python 2

2017-09-09 Thread Steve D'Aprano
years ago, if I remember correctly. How did that prediction work out for you? -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Using Python 2

2017-09-09 Thread Steve D'Aprano
hon 4 will not be a major compatibility break, it will be more like the Python 1 to 2 transition. But you already know that, because we've had this discussion before. Multiple times. You can stop spreading this FUD now. -- Steve “Cheer up,” they said, “things could be worse.” So I cheer

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

2017-09-10 Thread Steve D'Aprano
On Mon, 11 Sep 2017 12:46 am, Rick Johnson wrote: > if we consider the damage that small changes > (like the print statement versus print function and > raw_input versus input) have caused The word for negative damage is "improvement". -- Steve “Cheer up,” they said, “th

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

2017-09-10 Thread Steve D'Aprano
7;m afraid few programmers will > be willing/able to get over the hump, and there are a number of tricky > aspects to be extra careful about. The huge popularity of asynchronous routines in the Javascript and Node.JS community is evidence that it won't be "few programmers" but

Re: [Tutor] beginning to code

2017-09-10 Thread Steve D'Aprano
u meant to reply to the Tutor list. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

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

2017-09-12 Thread Steve D'Aprano
ues being on the bleeding edge, and Red Hat customers as a rule value stability and long term support over the latest shiny new features. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

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

2017-09-12 Thread Steve D'Aprano
it isn't all about you. Just because you started this thread -- oh wait, you didn't *wink* -- doesn't mean you control its direction. If people want to discuss the pros and cons of upgrading, without specifically badgering you, you should remember that *it isn't about you* and don

Re: Python dress

2017-09-12 Thread Steve D'Aprano
ion when Prince Charles, Duke of Edinburgh, appears in public wearing a kilt. [1] Gosh, that's a shocker. Bet you didn't see that coming. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: [Tutor] beginning to code

2017-09-12 Thread Steve D'Aprano
nt(x))(y), values) map(lambda z: (lambda y: (lambda x: int(x))(y))(z), values) -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: [Tutor] beginning to code

2017-09-13 Thread Steve D'Aprano
; and if the caller chooses to shoot themselves in the foot by passing a bad argument, they'll get what's coming to them. (Defensive programming is not only the receiving function's responsibility. The caller should program defensively to ensure they don't pass the wrong arguments t

Re: How do I check all variables returned buy the functions exists

2017-09-15 Thread Steve D'Aprano
if any(v is None for v in values): print "at least one value was None" -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Which database system?

2017-09-15 Thread Steve D'Aprano
On Sat, 16 Sep 2017 04:24 am, Chris Angelico wrote: > but switching your dict/list system to be > disk-backed is a lot harder. import shelve :-) Now you have two problems :-) -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got

Old Man Yells At Cloud

2017-09-15 Thread Steve D'Aprano
different when they program with Python." /rant off And no, for once it wasn't Ranting Rick. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: String to Dictionary conversion in python

2017-09-16 Thread Steve D'Aprano
) > File "/usr/lib/python2.7/ast.py", line 63, in _convert > in zip(node.keys, node.values)) > File "/usr/lib/python2.7/ast.py", line 62, in > return dict((_convert(k), _convert(v)) for k, v > File "/usr/lib/python2.7/ast.py", line 79, in _convert > raise ValueError('malformed string') > ValueError: malformed string Here's the bug tracker: make a feature request for literal_eval to be more concise in its traceback and provide a more useful and detailed error message. https://bugs.python.org/ -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Old Man Yells At Cloud

2017-09-16 Thread Steve D'Aprano
d from my client) asking for help with some sorting > program... I'm pretty sure the partitioning logic would croak on Python3 > due to floating point results in the slice indices: > > pA = part[:n/2] > pB = part[n/2:] If you want integer division, you have to use integer div

Re: Old Man Yells At Cloud

2017-09-16 Thread Steve D'Aprano
On Sun, 17 Sep 2017 04:00 am, Stefan Ram wrote: > Steve D'Aprano writes: >>"Hi, I've been programming in Python for what seems like days now, and here's >>all the things that you guys are doing wrong. > > I never ever have written a line of Python

Re: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?"

2017-09-16 Thread Steve D'Aprano
hy browsing the web today on full ADSL or faster speeds is *slower* than using a dial up modem in the 1990s? This is why. www.antipope.org/charlie/blog-static/2008/05/why_your_internet_experience_i.html Nine years later, and the problem is worse, not better. -- Steve “Cheer up,” they said, “t

Re: Old Man Yells At Cloud

2017-09-17 Thread Steve D'Aprano
On Sun, 17 Sep 2017 02:07 pm, Paul Rubin wrote: > Steve D'Aprano writes: >>> concept integer / integer => integer_result >> That would be C, and C derived languages, perhaps? > > Certainly not. Fortran, machine languages, etc. all do that too. &

Re: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?"

2017-09-17 Thread Steve D'Aprano
ng, and was added for Numerical Python. It wasn't until recently (Python 3.4 perhaps?) that it finally became legal to write '...' instead of 'Ellipsis' outside of slice notation. Here's Peter Otten talking about it way back in 2004: http://grokbase.com/t/python/pyt

Python built-ins versus Javascript [was Re: Old Man Yells At Cloud]

2017-09-17 Thread Steve D'Aprano
ript's are better? -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Old Man Yells At Cloud

2017-09-17 Thread Steve D'Aprano
hen you would do: mystring.decode('utf-8') and it will return a Unicode string of "code points" (think: more or less characters). -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Old Man Yells At Cloud

2017-09-17 Thread Steve D'Aprano
On Sun, 17 Sep 2017 08:43 pm, Chris Angelico wrote: > On Sun, Sep 17, 2017 at 5:54 PM, Steve D'Aprano > wrote: >> To even *know* that there are branches of maths where int/int isn't defined, >> you need to have learned aspects of mathematics that aren't even

Re: Old Man Yells At Cloud

2017-09-17 Thread Steve D'Aprano
of printing etc. Sure you can. But where the ability to mock print shines is when you're dealing with an already existing function that you cannot change and that already uses print. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Old Man Yells At Cloud

2017-09-17 Thread Steve D'Aprano
is: def ex_GST(inc_GST): if isinstance(inc_GST, int): return divmod(10*inc_GST, 11)[0] # throw away any remainder else: return 10*inc_GST/11 # include the remainder which is not what anyone wanted. And because this was a silent error, giving garbage results instead o

Re: Old Man Yells At Cloud

2017-09-17 Thread Steve D'Aprano
On Mon, 18 Sep 2017 04:09 am, Tim Chase wrote: > On 2017-09-18 00:42, Steve D'Aprano wrote: >> On Sun, 17 Sep 2017 11:51 pm, Tim Golden wrote: >> Presumably you've never wanted to print to something other than >> std.out. The syntax in Python 2 is horrid: >>

Re: Old Man Yells At Cloud

2017-09-17 Thread Steve D'Aprano
On Mon, 18 Sep 2017 09:15 am, Rick Johnson wrote: > On Sunday, September 17, 2017 at 9:42:34 AM UTC-5, Steve D'Aprano wrote: >> On Sun, 17 Sep 2017 11:51 pm, Tim Golden wrote: >> >> [Snip: Reasons why print function is better than print statement] >> >> I

Re: [Tutor] beginning to code

2017-09-17 Thread Steve D'Aprano
s a bool; comparing it to True adds redundancy and noise, not clarity. Your insistence on adding the entirely superfluous, unnecessary and distracting "== True" at the end of something which is already True or False demonstrates a lack of fluency in the language and difficulty in reasoning a

Re: Old Man Yells At Cloud

2017-09-17 Thread Steve D'Aprano
olve two fingers but its effectively a single movement. If you micro-analyse this, not all keystrokes are equivalent. They use different fingers, different hands, the movements are different. The fact that some characters need two simultaneous keypresses is not so important. -- Steve “Cheer

Re: [Tutor] beginning to code

2017-09-18 Thread Steve D'Aprano
code and make it publicly available. [1] Always supposing I could write a musical score. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: [Tutor] beginning to code

2017-09-18 Thread Steve D'Aprano
On Mon, 18 Sep 2017 10:42 pm, Rick Johnson wrote: > Steve D'Aprano wrote: > >> [snip: offensive statements] >> >> Your insistence on adding the entirely superfluous, unnecessary > > Please acquaint yourself with the definition of superfluous, > a

Re: [Tutor] beginning to code

2017-09-18 Thread Steve D'Aprano
.org/2/reference/datamodel.html#object.__nonzero__ https://docs.python.org/3/reference/expressions.html#boolean-operations https://docs.python.org/3/reference/compound_stmts.html#the-if-statement https://docs.python.org/3/reference/datamodel.html#object.__bool__ -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: [Tutor] beginning to code

2017-09-18 Thread Steve D'Aprano
False} → False I thought it was intentional, because there's nothing more obvious than that False is false. Unless you're a pedant and completist like me, why even bother mentioning that False is falsey? Especially since you left out so many more obvious values. -- Steve “Cheer up,

Re: Old Man Yells At Cloud

2017-09-18 Thread Steve D'Aprano
ously huge numbers of digits, leading to excessive memory use and even more performance degradation. Guido strongly dislikes the rational option because of his experience with ABC, where simple-looking calculations would often grind to a halt as they calculated fractions with millions or billions

Re: [Tutor] beginning to code

2017-09-19 Thread Steve D'Aprano
ave type(obj) and isinstance(x, Type), plus a slightly more specialised version issubclass. Convert to a string or human-readable representation. And test whether an object is truthy or falsey. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Old Man Yells At Cloud

2017-09-19 Thread Steve D'Aprano
oint is, we all make the occasional silly error. Doesn't mean we should cripple our functions and fill the language with special cases like the print statement to avoid such rare errors. If print had always been a function, and someone suggested making it a statement, who would be willing to a

Re: Old Man Yells At Cloud

2017-09-19 Thread Steve D'Aprano
On Wed, 20 Sep 2017 03:44 am, Stefan Ram wrote: > Steve D'Aprano did *not* write > [it was edited/abbreviated by me - S. R.]: > |disadvantages: > |0 - it makes print a special thing > |1 - beginners have to unlearn > |2 - `print(x, y)` is *not* the same as `print x, y`

Re: Old Man Yells At Cloud

2017-09-19 Thread Steve D'Aprano
On Wed, 20 Sep 2017 04:31 am, bartc wrote: > On 19/09/2017 17:30, Steve D'Aprano wrote: [snip list of problems with print] > Can't you get around all those with things like sys.stdout.write? If you had kept reading, you would have seen that I wrote: Of course an experien

Re: Even Older Man Yells at Whippersnappers

2017-09-19 Thread Steve D'Aprano
ronounced the brackets: "open paren open paren three squared close paren plus the square root of four hundred close paren by two" they could have been calculating *anything* by the time you get to the end. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: [Tutor] beginning to code

2017-09-19 Thread Steve D'Aprano
On Wed, 20 Sep 2017 03:22 am, Chris Angelico wrote: > On Wed, Sep 20, 2017 at 2:20 AM, Steve D'Aprano > wrote: >> I can only think of four operations which are plausibly universal: >> >> Identity: compare two operands for identity. In this case, the type o

Re: Even Older Man Yells At Whippersnappers

2017-09-20 Thread Steve D'Aprano
n logic gates. After refining the silicon to make the > transistors first, of course. Silicon? You had it easy. In my day all we had was hydrogen and helium, we had to make our own silicon using fusion. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enou

Re: Even Older Man Yells At Whippersnappers

2017-09-20 Thread Steve D'Aprano
On Wed, 20 Sep 2017 09:50 pm, Steve D'Aprano wrote: > On Wed, 20 Sep 2017 07:12 pm, Gregory Ewing wrote: > >> Grant Edwards wrote: >>> Alternatively, you should design an instruction set and implement it >>> using microcode and AM2900 bit-slice processors. &

Re: How do I check all variables returned buy the functions exists

2017-09-20 Thread Steve D'Aprano
On Wed, 20 Sep 2017 06:04 pm, Bill wrote: > Robin Becker wrote: >> On 16/09/2017 01:58, Steve D'Aprano wrote: >> >>> >>> If you want to test for None specifically: >>> >>> if any(v is None for v in values): >>> print &

Re: Old Man Yells At Cloud

2017-09-20 Thread Steve D'Aprano
On Wed, 20 Sep 2017 02:55 pm, Pavol Lisy wrote: > On 9/19/17, Steve D'Aprano wrote: > > [...] > >> The point is, we all make the occasional silly error. Doesn't mean we should >> cripple our functions and fill the language with special cases like the >&g

Re: How do I check all variables returned buy the functions exists

2017-09-20 Thread Steve D'Aprano
On Wed, 20 Sep 2017 10:07 pm, Steve D'Aprano wrote: > I'm not sure whether to be surprised or not. > > The first one only checks for identity, which should be really fast, while the > `is` operator tests for equality too, Oops, that's supposed to be `in`, not `is`.

Re: Old Man Yells At Cloud

2017-09-20 Thread Steve D'Aprano
On Thu, 21 Sep 2017 01:06 am, Dennis Lee Bieber wrote: > On Wed, 20 Sep 2017 10:08:18 +1000, Steve D'Aprano > declaimed the following: > >>For what its worth: from Python 3.5 (I think) onwards the error you get is >>customized: >> >>py>

Re: Greater and less than operators [was Re: [Tutor] beginning to code]

2017-09-20 Thread Steve D'Aprano
intuit the arbitrary rules? Lists and tuples use the same lexicographic ordering as strings, except that lists accept arbitrary object not just characters. So long as each pair of objects in corresponding positions can be compared, the whole list can be compared too. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Old Man Yells At Cloud

2017-09-21 Thread Steve D'Aprano
el, for a decade or more, and put up with thousands of internet haters going on and on and on and on about "Python 3 is destroying Python", year after year after year. They were willing to do all this because they were looking at the long-term health of the Python language, not just the immedi

iPython ? magic

2017-09-21 Thread Steve D'Aprano
it to display anything except either "Python builtin" or "Interactive". -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Assertions

2017-09-21 Thread Steve D'Aprano
big difference between the two, but it turned out that there can be other byte-code differences. So no, I don't believe we can say they are *completely* equivalent, since they could compile to slightly different byte-code with slightly-different performance characteristics. But I think we can s

Re: Assertions

2017-09-21 Thread Steve D'Aprano
application. Your end-users should never see an AssertionError.) The bottom line is, if I saw if not (thing > 0): raise AssertionError(...) in a code review, I'd probably insist that either it be changed to use `assert`, or the exception be changed to ValueError, whichever better exp

Re: Assertions

2017-09-21 Thread Steve D'Aprano
On Fri, 22 Sep 2017 03:31 am, Chris Angelico wrote: > On Fri, Sep 22, 2017 at 3:23 AM, Steve D'Aprano > wrote: >> That is definitely version-dependent, because I've just tried it and got >> different byte-code in Python 2.7. >> >> py> import dis >

Re: Old Man Yells At Cloud

2017-09-21 Thread Steve D'Aprano
hould have invented their own language and used that instead. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: [Tutor] beginning to code

2017-09-21 Thread Steve D'Aprano
're right about the second point.) -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: [Tutor] beginning to code

2017-09-22 Thread Steve D'Aprano
written in Haskell. Skulpt is written in Javascript. Vyper was a really old implementation written in OCaml, apparently now lost and no longer visible on the internet. Some of these may been no longer supported, but the Big Four python implementations are CPython, Jython, IronPython and PyPy.

Re: [Tutor] beginning to code

2017-09-22 Thread Steve D'Aprano
> y="Z" > swap(x,y) > print (x,y) # "Z" and "10" > > If not, then it doesn't have reference passing as it is normally understood. No it cannot, and does not. You can emulate it by adding a layer of redirection, but that's i

Re: Assertions

2017-09-22 Thread Steve D'Aprano
or floats they're not the same. py> not (NAN > 0) True py> NAN <= 0 False -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: [Tutor] beginning to code

2017-09-22 Thread Steve D'Aprano
On Fri, 22 Sep 2017 05:01 pm, Bill wrote: > Steve D'Aprano wrote: >> On Fri, 22 Sep 2017 02:57 pm, Bill wrote: >> >>> I find Python to be more more >>> like Java, with regard to "passing objects by reference". >> Which is not a surprise, si

Re: [Tutor] beginning to code

2017-09-22 Thread Steve D'Aprano
way to emulate pass by reference which works in any scope: use a list. def swap(a, b): a[0], b[0] = b[0], a[0] a = [1] b = [2] swap(a, b) assert a[0] == 2 and b[0] == 1 It's not proper pass by reference, and so will still fail Bart's test, because you need to manually add an extr

Re: Assertions

2017-09-22 Thread Steve D'Aprano
On Fri, 22 Sep 2017 10:03 pm, alister wrote: > On Fri, 22 Sep 2017 21:15:54 +1000, Steve D'Aprano wrote: > >> On Fri, 22 Sep 2017 08:50 pm, alister wrote: >> >>>> The bottom line is, if I saw >>>> >>>> if not (thing > 0): raise

Re: [Tutor] beginning to code

2017-09-22 Thread Steve D'Aprano
7;x', 'y', scope_of_x, scope_of_y) or any other variant. That isn't call by reference semantics. The whole point of call by reference semantics is that the *compiler*, not the programmer, tracks the variables and their scopes. The programmer just says "swap x and y", an

Re: Python Boolean Logic

2017-09-22 Thread Steve D'Aprano
sk to eval strings that came from an untrusted user. eval("__import__('os').system('echo """rm-rf /"""')") Also, for what its worth, it's about ten times slower to run: eval('(20 - 10) > 15') than to simply run (20

Re: Python Boolean Logic

2017-09-23 Thread Steve D'Aprano
On Sat, 23 Sep 2017 03:01 pm, Bill wrote: > if (20 - 10) > 15 : > print("true") > else: > print("false"); print(20 - 10 > 15) will do the job. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sur

Re: Old Man Yells At Cloud

2017-09-23 Thread Steve D'Aprano
On Fri, 22 Sep 2017 04:05 pm, Paul Rubin wrote: > Steve D'Aprano writes: >> Having to spend a few hours being paid to migrate code using "print x" >> to "print(x)", or even a few months, is not a life-changing experience. > > Didn't someone

Re: [Tutor] beginning to code

2017-09-23 Thread Steve D'Aprano
On Sun, 24 Sep 2017 07:03 am, ROGER GRAYDON CHRISTMAN wrote: > I usually do not encourage people to optimize correctness out of their code. +1 quote of the week :-) -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- ht

Re: [Tutor] beginning to code

2017-09-23 Thread Steve D'Aprano
er in other ways. Assignment by reference would mean that name binding was an *alias* operation: module.y = 1 x = module.y # x is an alias for the name "module.y" x = 2 # binds 2 to module.y assert module.y == 2 -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Call by binding [was Re: [Tutor] beginning to code]

2017-09-24 Thread Steve D'Aprano
ke C, call by reference like Fortran, call by need like Haskell, or call by sharing like Python. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Reference cycles

2017-09-24 Thread Steve D'Aprano
Is there a way to log when the garbage collector finds and collects a reference cycle? I don't care about objects claimed by the reference counter, I only care about cycles. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. --

Re: Call by binding [was Re: [Tutor] beginning to code]

2017-09-24 Thread Steve D'Aprano
ards to find out its name (or names). But in Python, objects cannot do that: they have no way of telling what names they are known by, or even how many names there are. (There may be clever tricks you can play with the garbage collector or debugger, but that's not part of Python-the-language,

Re: _sitebuiltins?

2017-09-24 Thread Steve D'Aprano
t an implementation detail: site.py was refactored to keep long-lasting objects separate from those that are ephemeral. `builtins` is the official public name of the built-in namespace. In Python 2, it was unfortunately called __builtin__. Unfortunately there is also a __builtins__ name, which is a p

Re: [Tutor] beginning to code

2017-09-24 Thread Steve D'Aprano
l requires that the actual argument passed to the var parameter be an actual variable, not a constant or expression. Technically, it must be a "L-value", something which can appear on the left hand side of an assignment and therefore something that has an address. -- Steve “Cheer

Re: Call by binding [was Re: [Tutor] beginning to code]

2017-09-24 Thread Steve D'Aprano
nce variables, to we can say that assignment: a = b; is the same as function call func(b) regardless of whether C++ is using by-value or by-reference semantics. So I believe that either "call by binding" or "call by assignment" could both equally apply to any and all languages w

Re: [Tutor] beginning to code

2017-09-25 Thread Steve D'Aprano
signment. I don't know what you think "copy-over assignment" means, but none of DuckDuckGo, Google, Bing or Yahoo finds that term except in your post. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: _sitebuiltins?

2017-09-25 Thread Steve D'Aprano
average, in the builtins module, is the same function object as mean, in the statistics module, what should average.__module__ say? py> average.__module__ 'statistics' -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

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