Re: Help with some python homework...

2014-01-31 Thread Gregory Ewing
sjud9227 wrote: Doesn't assigning seconds/(60*60) mean that calculating 6*hours will give me 6 hours in seconds? No, it's giving you 6 seconds in hours. (That should give you a clue as to what you should have done instead. :-) Also, I don't know what you were trying to do with these two statem

Re: Help with some python homework...

2014-01-31 Thread Gregory Ewing
Chris Angelico wrote: OP is using 2.7.6, so short of a __future__ directive, that won't actually give 6 seconds in hours Oops, yes, you're right! (I always use future division these days, so I tend to forget about that.) and // is unnecessary. It's still a good habit to get into, though, si

Re: __init__ is the initialiser

2014-02-02 Thread Gregory Ewing
Roy Smith wrote: In article <[email protected]>, Steven D'Aprano wrote: A dubious analogy, since there are artists who would say that attacking the canvas with a knife and setting the remains on fire count as a form of artistic creation :-) That's __del__(

Re: __init__ is the initialiser

2014-02-02 Thread Gregory Ewing
Mark Lawrence wrote: Called when the instance is created. The arguments are those passed to the class constructor expression. If a base class has an __init__() method, the derived class’s __init__() method, if any, must explicitly call it to ensure proper initialization of the base class part o

Re: __init__ is the initialiser

2014-02-02 Thread Gregory Ewing
Steven D'Aprano wrote: (In hindsight, it was probably a mistake for Python to define two create- an-object methods, although I expect it was deemed necessary for historical reasons. I'm not sure that all of the reasons are historical. Languages that have a single creation/initialisation method

Re: __init__ is the initialiser

2014-02-03 Thread Gregory Ewing
Steven D'Aprano wrote: # --- Untested --- # Automatically call each __new__ constructor method, starting from # the most fundamental (object) and ending with the current class. stack = [] for c in cls.__mro__: if hasattr(c, '__new__'): stack.append(c.__new__) while stack: stack.po

Re: Question about `list.insert`

2014-02-06 Thread Gregory Ewing
Roy Smith wrote: O(-1). In Soviet Russia, operation performs you! It's rumoured that the PSU is developing a time machine module that can achieve O(-n), but -- https://mail.python.org/mailman/listinfo/python-list

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-10 Thread Gregory Ewing
Chris Angelico wrote: mylist = reorder_generator(mylist) You can iterate over it, but can't index it. But hey, it complies with the space/time requirements! Rather than a generator, you could use a view object that rearranges the indices when you access an element. That would comply with the s

Re: Sort one sequence by O(n) in time and O(1) in space

2014-02-11 Thread Gregory Ewing
Steven D'Aprano wrote: Secondly, O(N*log N) applies to *comparison sorts*. Non-comparison sorts such as radix-, counting- and bucket-sort have average case complexity of O(N). They require additional space, though. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?)

2015-11-26 Thread Gregory Ewing
Marko Rauhamaa wrote: What I'm saying is that Python does not prevent mutable keys but tries to do that with lists and tuples. I think Python should stop trying. Do you volunteer to answer all the posts from beginners complaining that "the dict type is broken" because they used a list as a key

Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?)

2015-11-26 Thread Gregory Ewing
BartC wrote: I simply stated that Python's approach was novel. Steven D'Aprano then responded by belittling my view, and effectively trashing every language I've ever used. He pointed out that many other dynamic languages construct functions on the fly the same way that Python does, going all

Re: Is vars() the most useless Python built-in ever?

2015-12-01 Thread Gregory Ewing
Rick Johnson wrote: the lie about: "THERE SHOULD BE ONE (AND PREFERABLY ONLY ONE) WAY TO DO IT!". You're misquoting the Zen. It says there should be one *obvious* way to do it. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: OT: citizens and countries - was Re: v3.5.1 - msi download

2015-12-23 Thread Gregory Ewing
Michael Torrie wrote: A country in which citizens only expect things from the country and never think about their ability to change and benefit the country is a week country indeed. Yep, definitely won't last more than 7 days. :-) -- Greg -- https://mail.python.org/mailman/listinfo/pyth

Re: Need help on a project To :"Create a class called BankAccount with the following parameters "

2015-12-25 Thread Gregory Ewing
Grant Edwards wrote: And don't get me started on those people who use those "integrated circuits" instead of transistors, relays, and tubes... Transistors? You don't know how good you had it. In my day we had to poke the dopant atoms into the silicon one at a time with the point of a needle. -

Re: When I need classes?

2016-01-12 Thread Gregory Ewing
Chris Angelico wrote: So start simplistic, and then look into it like this: "Hey, see how you're doing this five times? There HAS to be a better way!" (With acknowledgement to Raymond Hettinger.) That gave me visions of a little animated cartoon of Raymond popping up in the corner of the screen

Re: Stop writing Python 4 incompatible code

2016-01-13 Thread Gregory Ewing
Steven D'Aprano wrote: Quote: if six.PY2: # Python 2 code elif six.PY3: # Python 3 code In this case, no code will get executed on Python 4 at all! Which is good, because if no code is executed, it can't exhibit any bugs. Everyone should write thei

Re: Stop writing Python 4 incompatible code

2016-01-14 Thread Gregory Ewing
Steven D'Aprano wrote: Maybe Guido will change his mind and we'll have 3.10. 3.11, 3.12, ... Who says that version numbers have to be base 10? After 3.9 we could have 3.A, 3.B, ... 3.Z, and then we have a long list of Unicode characters to work through before we're forced to bump the major num

Re: Stop writing Python 4 incompatible code

2016-01-15 Thread Gregory Ewing
On 1/14/2016 3:55 PM, Rick Johnson wrote: And if the owners refuse to sell, no problem, you offer their customers the same services at bargain basement discounts But... that would require you to develop your own version, which is what you're trying to avoid! -- Greg -- https://mail.python.org

Re: Stop writing Python 4 incompatible code

2016-01-15 Thread Gregory Ewing
Chris Angelico wrote: and 3.X would wreak havoc with people's heads. The danger there is that 3.X would sound so cool (everything is cooler with an X in it) that nobody would want to move past it. So after 3.X we would get 3.X.1, ... and then 3.X.X.1, ... At some point people would start abbre

Re: Writing a stream of bytes

2016-01-15 Thread Gregory Ewing
Mark Lawrence wrote: On 15/01/2016 15:55, jmp wrote: Hi pyple ! In the UK it's "purple", a bit like "color" is wrong, it's "colour". Now, let's not make fun of people with English as a second language. That was obviously written with a Jäger accent: http://girlgenius.wikia.com/wiki/J%C3%A4

Re: psss...I want to move from Perl to Python

2016-01-29 Thread Gregory Ewing
Random832 wrote: The main source of confusion is that $foo[5] is an element of @foo. $foo{'x'} is an element of %foo. Both of these have absolutely nothing to do with $foo. And this is where Perl seems totally insane to me. Obviously it knows from the square brackets that foo[5] is referring to

Re: psss...I want to move from Perl to Python

2016-01-29 Thread Gregory Ewing
[email protected] wrote: On Thursday, January 28, 2016 at 6:34:34 PM UTC-8, Chris Angelico wrote: https://xkcd.com/353/ I have this comic pinned to the outside wall of my cubicle at work, where I use Python for 98% of my work. Another good thing to pin to your wall: http://www.gentooge

Re: psss...I want to move from Perl to Python

2016-01-30 Thread Gregory Ewing
Rustom Mody wrote: 1. One can use string-re's instead of compiled re's And I gather that string REs are compiled on first use and cached, so you don't lose much by using them most of the time. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Gregory Ewing
Michael Torrie wrote: I'm not sure how SQLite handles it, or even what the SQL spec says, but I know in MySQL you could do something like this: SELECT count(id) as row_count,`tablename`.* FROM `tablename` WHERE condition I don't think that's strictly valid SQL. I know of at least one SQL imple

Re: A sets algorithm

2016-02-08 Thread Gregory Ewing
Chris Angelico wrote: hash_to_filename = defaultdict(list) for fn in files: # Step 1: Hash every file. hash = calculate_hash(fn) # Step 2: Locate all pairs of files with identical hashes hash_to_filename[hash].append(fn) I think you can avoid hashing the files altogether. Firs

Re: How do i instantiate a class_name passed via cmd line

2016-02-13 Thread Gregory Ewing
Veek. M wrote: I'm writing a price parser. I need to do the equivalent of perl's $$var to instantiate a class where $car is the class_name. I'm passing 'Ebay' or 'Newegg' or 'Amazon' via cmd-line. I have a module named ebay.py and a class called Ebay (price parser). I do something like: \> m

Re: Make a unique filesystem path, without creating the file

2016-02-15 Thread Gregory Ewing
Ben Finney wrote: One valid filesystem path each time it's accessed. That is, behaviour equivalent to ‘tempfile.mktemp’. My question is because the standard library clearly has this useful functionality implemented, but simultaneously warns strongly against its use. But it *doesn't*, if your r

Re: Make a unique filesystem path, without creating the file

2016-02-15 Thread Gregory Ewing
Ben Finney wrote: The existing behaviour of ‘tempfile.mktemp’ – actually of its internal class ‘tempfile._RandomNameSequence’ – is to generate unpredictable, unique, valid filesystem paths that are different each time. But that's not documented behaviour, so even if mktemp() weren't marked as

Re: How to properly override the default factory of defaultdict?

2016-02-15 Thread Gregory Ewing
Herman wrote: I want to pass in the key to the default_factory of defaultdict and I found that defaultdict somehow can intercept my call to dict.__getitem__(self, key), What's happening here is that defaultdict doesn't actually override __getitem__ at all. Instead, it overrides __missing__, whi

Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-22 Thread Gregory Ewing
BartC wrote: Our system must have been more advanced then, or designed for training. We used a time-sharing 'dec-system 10' and it was usually accessed via interactive terminals, either teletypes or the odd VDU. According to Wikipedia the first interactive version of Dartmouth BASIC appeared i

Re: How to define what a class is ?

2016-02-24 Thread Gregory Ewing
Ian Kelly wrote: All metaclasses are subclasses of type, so all classes are instances of type. I think that's about the most general definition you can find. Almost everything else that you might think of as being part of the classness of a class can be overridden. Another definition might be

Re: [Python-ideas] How the heck does async/await work in Python 3.5

2016-02-24 Thread Gregory Ewing
王珺 wrote: Suppose io_operation() takes 3 seconds, then how can I write something like future = io_operation() print('Start') time.sleep(1) print('Something') time.sleep(2) print(future.result()) that print 'Start' immediately and the result of io_operation() 3 seconds later. Yes, Python can d

Re: child.before taking almost 1 minute to execute

2016-02-24 Thread Gregory Ewing
pyfreek wrote: The following snippet alone is taking 1 minute to execute. is there any best way to find 'No such file' other than using child.before if not scrutinFile.startswith('/') : scrutinFile = '/'+ scrutinFile scrutinFileFtp = direc

Re: "from module import data; print(data)" vs "import module; print(module.data)"

2016-02-25 Thread Gregory Ewing
[email protected] wrote: Now, I've noticed people talking about importing os.path. Is there any reason to use "import os.path" rather than "import os"? Both of them will still put the "os" module into the global namespace. In the case of os.path it doesn't matter, because the os module im

Re: Everything good about Python except GUI IDE?

2016-02-28 Thread Gregory Ewing
Steven D'Aprano wrote: That's exactly why I miss Hypercard so much. The builder and the runtime are the same thing. Maybe someone would like to resurrect this project: http://pythoncard.sourceforge.net/ -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: A mistake which almost went me mad

2016-03-03 Thread Gregory Ewing
Tim Golden wrote: A few teachers recently were discussing this on Twitter. One suggested that his pupils always add their initials to whatever filename they use. Works well until Lawrence Ian Bernstein writes his own module called "url"... -- Greg -- https://mail.python.org/mailman/listinfo/py

Re: [Off-topic] Requests author discusses MentalHealthError exception

2016-03-03 Thread Gregory Ewing
alister wrote: On Thu, 03 Mar 2016 11:03:55 -0700, Ian Kelly wrote: On Thu, Mar 3, 2016 at 10:21 AM, alister wrote: Antimatter has positive mass. Are you sure? mix 1 atom of hydrogen + 1 of anti hydrogen & you end up with 0 mass That's not because anti-hydrogen has negative mass, though.

Re: [Still off-top] Physics [was Requests author discusses MentalHealthError exception]

2016-03-04 Thread Gregory Ewing
Oscar Benjamin wrote: If we want to be precise then it's pointless to even refer to the "rest mass" of something that is never at rest. Which just shows that the term "rest mass" is a bit silly. It came from some confused thinking very early in the development of relativity. The physicists soon

Re: Simple exercise

2016-03-10 Thread Gregory Ewing
Rodrick Brown wrote: if m.group(1) not in od.keys(): od[m.group(1)] = int(m.group(2)) else: od[m.group(1)] += int(od.get(m.group(1),0)) Others have pointed out what's wrong with this, but here's a general tip: Don't repeat complicated subexpressions such as m.group(1

Re: Encapsulation in Python

2016-03-11 Thread Gregory Ewing
Rick Johnson wrote: I have witnessed the mayhem that occurs when a language does not mandate module encapsulation (Ruby, i'm looking directly at you), and while i agree with the Python designers that modules must *ALWAYS* be mandatory, i am not convinced that module space should be so strictl

Re: Encapsulation in Python

2016-03-13 Thread Gregory Ewing
Rick Johnson wrote: Sure, that's reliable in most cases, but your argument assumes that the actual source code for the symbol exists in the module from which it was imported, when it could just as well exist N-levels below that that module, due to chained imports. Unless the module is doing som

Re: WP-A: A New URL Shortener

2016-03-15 Thread Gregory Ewing
Chris Angelico wrote: There are many places where there are limits (hard or soft) on message lengths. Some of us still use MUDs and 80-character line limits. Business cards or other printed media need to be transcribed by hand. Dictation of URLs becomes virtually impossible when they're arbitrari

Re: Case Statements

2016-03-19 Thread Gregory Ewing
Steven D'Aprano wrote: On Thu, 17 Mar 2016 11:31 am, Chris Angelico wrote: orig = globals()[cls.__name__] I wouldn't want to rely on it working with decorator syntax either. Even if it does now, I'm not sure that's a language guarantee. The following idiom relies on similar behaviour:

Re: Case Statements

2016-03-19 Thread Gregory Ewing
Chris Angelico wrote: So maybe it's a language guarantee that hasn't been written down somewhere, The Language Reference says: [the decorator] is invoked with the function object as the only argument. The returned value is bound to the function name instead of the function object. The "

Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-26 Thread Gregory Ewing
Gene Heskett wrote: But I learned a lot about hot ($2400F) iron too. 2400 dollars farenheit? That's an intriguing unit... Or is it meant to be the temperature in hex? -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: (test) ? a:b

2014-10-22 Thread Gregory Ewing
Chris Angelico wrote: I've seen much MUCH worse... where multiple conditional expressions get combined arithmetically, and then the result used somewhere... In the days of old-school BASIC it was common to exploit the fact that boolean expressions evaluated to 0 or 1 (or -1, depending on your d

Re: (test) ? a:b

2014-10-27 Thread Gregory Ewing
Michael Torrie wrote: As far as I can tell, no BASIC dialect I've looked at (DOS and Linux worlds only), has ever had any logical operators like AND (&&), OR (||), and NOT (!). They only appear to have bitwise operators (&,|,~ C equivalent). The fact that comparison operators returned 0 and -1

Re: Anyone know the solution

2014-10-28 Thread Gregory Ewing
On Monday, October 27, 2014 5:33:17 PM UTC-7, alex23 wrote: It is NP-complete, meaning that there is no easy solution. The correct answer is "Not possible". No, that's not the correct answer. Being NP-complete doesn't mean something is impossible, or even hard to do. All it means is that nobo

Re: Classes

2014-10-31 Thread Gregory Ewing
Seymore4Head wrote: The course is free. You can't beat the price. It is only for a few more weeks. But if it's teaching you things that are blatantly wrong in relation to Python, it may be doing more harm than good. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Classes

2014-11-02 Thread Gregory Ewing
Steven D'Aprano wrote: Like all good Pythonistas[1], we hate Java and think that getter/setter methods are pointless. But come on, they're not *wrong*, What's wrong is the statement that getters and setters are necessary to allow the implementation to change without changing the interface. That

Re: Classes

2014-11-03 Thread Gregory Ewing
Denis McMahon wrote: On Mon, 03 Nov 2014 06:29:39 +, Dan Sommers wrote: What's the difference between a Diamond and a Rhombus? Oops, I was thinking a rhombus was a general parallelogram, my mistake. Some diamonds are neither rhombuses nor parallelograms: http://minecraft.gamepedia.co

Re: Classes

2014-11-03 Thread Gregory Ewing
Jean-Michel Pichavant wrote: Python uses the descriptor protocol which is basically getters and setters. It's is just hidden by a strange decorator syntax. This is about the interface, not the implementation. "Getters and setters" in this context means designing the API of your class to have th

Re: Python has arrived!

2014-11-07 Thread Gregory Ewing
Steve Hayes wrote: On Thu, 6 Nov 2014 15:22:45 + (UTC), Grant Edwards wrote: According to http://www.theregister.co.uk/2014/11/06/hackers_use_gmail_drafts_as_dead_drops_to_control_malware_bots: 404: Page not found Works if you remove the spurious colon from the end of the url. -- Gre

Re: generating 2D bit array variants with specific algorythm

2014-11-07 Thread Gregory Ewing
Robert Voigtländer wrote: I need to generate all variants of a 2D array with variable dimension sizes which fit a specific rule. (up to 200*1000) Um... you realise there are 200**1000 solutions for the 200x1000 case? Are you sure that's really what you want? -- Greg -- https://mail.python.org

Re: [Python-Dev] Dinamically set __call__ method

2014-11-08 Thread Gregory Ewing
Ethan Furman wrote: On 11/06/2014 10:59 PM, dieter wrote: A possibility to get the original approach implemented looks like: make "__call__" a descriptor on the class which looks up the real method on the instance. This still wouldn't get the signatrue correct, though. Why not? O

Re: [Python-Dev] Dinamically set __call__ method

2014-11-09 Thread Gregory Ewing
Ethan Furman wrote: And the thing going on is the normal python behavior (in __getattribute__, I believe) of examining the returned attribute to see if it is a descriptor, and if so invoking it. Only if you look it up through the instance, though. Normally, if you look up an attribute on a cla

Re: What does zip mean?

2014-11-10 Thread Gregory Ewing
Grant Edwards wrote: What the zipper on a coat does is convert two separate sequences into a single sequence where the members alternate between the two input sequences. True, the zipper analogy isn't quite accurate. It's hard to think of an equally concise and suggestive name, however. -- Gr

Re: [Python-Dev] Dinamically set __call__ method

2014-11-12 Thread Gregory Ewing
Fabio Zadrozny wrote: can someone from python-dev give some background of why that's the way it is? It's because, with new-style classes, a class is also an instance (of class "type" or a subclass thereof). So without that rule, it would be ambiguous whether a dunder method applied to instances

Re: How to fix those errors?

2014-11-17 Thread Gregory Ewing
Roy Smith wrote: Wouldn't it make more sense to use four periods? def spam(arg) for x in seq pass Conversely, to save space you should be able to stack one of the dots of an ellipsis on top and write it as either .: or :. Taking this even further, we could allow all charac

Re: PyWart: "Python's import statement and the history of external dependencies"

2014-11-23 Thread Gregory Ewing
Chris Angelico wrote: Just out of curiosity, why does the stdlib need modules for manipulating .wav and other sound files, but we have to go to PyPI to get a PostgreSQL client? I suspect it's mainly for historical reasons. The wave module has been around since the very early days of Python when

Re: python 2.7 and unicode (one more time)

2014-11-23 Thread Gregory Ewing
Marko Rauhamaa wrote: Unicode strings is not wrong but the technical emphasis on Unicode is as strange as a "tire car" or "rectangular door" when "car" and "door" are what you usually mean. The reason Unicode gets emphasised so much is that until relatively recently, it *wasn't* what "string" u

Re: PyEval_GetLocals and unreferenced variables

2014-11-29 Thread Gregory Ewing
Kasper Peeters wrote: I have something like def fun(): cfun_that_creates_q_in_local_scope() def fun2(): cfun_that_wants_to_see_if_q_is_available() So the Python side actually doesn't see 'q' directly at all. I am willing to elaborate on this if you want I think

Re: PyEval_GetLocals and unreferenced variables

2014-12-02 Thread Gregory Ewing
Kasper Peeters wrote: I could in principle decide to make these settings a proper Python object, and ask the user to create one and pass it along at every C-function call. I would make the C functions methods of the object holding the settings. Your nested function example would then look somet

Re: PyEval_GetLocals and unreferenced variables

2014-12-02 Thread Gregory Ewing
Ned Batchelder wrote: I would use thread locals for this: https://docs.python.org/2/library/threading.html#threading.local You could get dynamic scoping that way, but the OP seems to want lexical scoping. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Cherrypy - prevent browser "prefetch"?

2014-12-02 Thread Gregory Ewing
Israel Brewster wrote: Primary because they aren’t forms, they are links. And links are, by definition, GET’s. That said, as I mentioned in earlier replies, if using a form for a simple link is the Right Way to do things like this, then I can change it. I'd look at it another way and say that a

Re: PyEval_GetLocals and unreferenced variables

2014-12-03 Thread Gregory Ewing
Kasper Peeters wrote: That may have been the design plan, but in Python 2.7.6, I definitely am able to inject locals via PyEval_GetLocals() and have them be visible both from the C and Python side; What seems to be happening is that the dict created by PyEval_GetLocals() is kept around, so you

Re: Python Iterables struggling using map() built-in

2014-12-07 Thread Gregory Ewing
Steven D'Aprano wrote: I do not believe that good code must be obviously right. It's okay for code to be subtly right. If you write code as subtly as you can, you're not subtle enough to debug it... -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Python Iterables struggling using map() built-in

2014-12-07 Thread Gregory Ewing
Terry Reedy wrote: However, this 'beautiful' code has a trap. If one gets rid of the seemingly unneeded temporary list res by telescoping the last two lines into a bit too much into yield tuple(next(i) for i in iters) we now have an infinite generator, because tuple() swallows th

Re: numpy question (fairly basic, I think)

2014-12-14 Thread Gregory Ewing
Albert-Jan Roskam wrote: I was trying to change the one-dim array into a two-dim array so I could easily retrieve columns. I now use a pandas DataFrame to do that. Numpy can do that, if I understand what you want correctly, but it requires an unintuitive trick. The trick is to index the array

Re: question on string object handling in Python 2.7.8

2014-12-24 Thread Gregory Ewing
Dave Tian wrote: A: a = ‘h’ > B: b = ‘hh’ According to me understanding, A should be faster as characters would shortcut this 1-byte string ‘h’ without malloc; It sounds like you're expecting characters to be stored "unboxed" like in Java. That's not the way Python works. Objects are used

Re: Python 2.7 segfaults on 'import site'

2014-12-29 Thread Gregory Ewing
Chris Angelico wrote: On Tue, Dec 30, 2014 at 7:17 AM, Ian Kelly wrote: You could try renaming the .pyc instead of deleting it. Hmm, and in doing so I just learned that they don't, after all, have any sort of timestamp in them - I thought they did. I think it contains the timestamp of the

Re: How do I remove/unlink wildcarded files

2015-01-02 Thread Gregory Ewing
Chris Angelico wrote: On Sat, Jan 3, 2015 at 4:15 AM, Rick Johnson wrote: Those who refuse to be a part of the modern world can suffer the troubles of forking the code into their ancient systems -- and i will not loose any sleep over the issue. By the way, is this "loose" part of your "moder

Re: Decimals and other numbers

2015-01-09 Thread Gregory Ewing
Steven D'Aprano wrote: I'm just sketching an informal proof. If you want to make it vigorous I think the usual term is "rigorous", unless the mathematician is taking some kind of stimulant... :-) -- Greg -- https://mail.py

Re: Decimals and other numbers

2015-01-09 Thread Gregory Ewing
Steven D'Aprano wrote: Arguably, *integer* 0**0 could be zero, on the basis that you can't take limits of integer-valued quantities, and zero times itself zero times surely has to be zero. It's far from clear what *anything* multiplied by itself zero times should be. A better way of thinking a

Re: Why do the URLs of posts here change?

2015-01-09 Thread Gregory Ewing
Skip Montanaro wrote: The way this is done, is that the message is removed from the underlying mbox file, and the archive regenerated. That changes the counter for every message after that point Would it help to replace the message with a stub instead of deleting it altogether? -- Greg -- http

Re: Comparisons and sorting of a numeric class....

2015-01-16 Thread Gregory Ewing
Ian Kelly wrote: Wait, are you actually asking why bool is a doubleton? If nobody has answered that, I think probably nobody understood you were asking it, because it shouldn't need to be explained. What does perhaps need explaining is why Python goes out of its way to *enforce* the doubleton-n

Re: Comparisons and sorting of a numeric class....

2015-01-16 Thread Gregory Ewing
Andrew Robinson wrote: I never said subclassing bool is the 'only' solution; I have indicated it's a far better solution than many. An assertion with which we very much disagree. I have spent well over twenty years on and off dealing with boolean values that are very often mixed indistingu

Re: lambdak: multi-line lambda implementation in native Python

2015-01-16 Thread Gregory Ewing
Dennis Lee Bieber wrote: On Fri, 16 Jan 2015 01:50:00 +1100, Chris Angelico declaimed the following: > Problem: You have a smartphone with a 4x4 pixel screen. BIG problem, considering that a late 70s DECWriter needed 5x7 pixels for glyphs in an 8x10 pixel character cell {as I recall.

Re: lambdak: multi-line lambda implementation in native Python

2015-01-16 Thread Gregory Ewing
Marko Rauhamaa wrote: Gregory Ewing : If those are 24-bit RGB pixels, you could encode 3 characters in each pixel. Not since Python3. Characters are Unicode now so you'll need to dedicate a pixel for each character. Depends on which characters you want. With the Flexible Chro

Re: Factories and Builders [was Re: lambdak...]

2015-01-16 Thread Gregory Ewing
Steven D'Aprano wrote: I've never really understand why "abstract factory", "factory method" and "builder" are considered different design patterns. They're variants on the same idea. I think it's because they address different problems. Factories are for hiding the details of how an object is

Re: lambdak: multi-line lambda implementation in native Python

2015-01-16 Thread Gregory Ewing
Chris Angelico wrote: Is this to get around style guides that reject this kind of model: x = Foo( opt1=True, opt2=True, color=Yellow, ) It's to get around the fact that you *can't* do that in Java, because it doesn't have keyword arguments. This is a source of a lot of the complex

Re: recursive function: use a global or pass a parameter?

2015-01-16 Thread Gregory Ewing
Tim wrote: I have this type of situation and wonder if I should use a global variable outside the recursive function instead of passing the updated parameter through. No! Globals are evil, at least for that sort of thing. The way you're doing it is fine. The only thing I would change is to wra

Re: recursive function: use a global or pass a parameter?

2015-01-17 Thread Gregory Ewing
Roy Smith wrote: I will commonly put something like: import logging logger = logging.getLogger("logger-name-for-my-module") But that's not really a global variable, it's a global constant. There's nothing wrong with those, we use them all the time -- classes, functions, etc. If you were to re

Re: recursive function: use a global or pass a parameter?

2015-01-17 Thread Gregory Ewing
Yawar Amin wrote: Cool ... but it looks like this can still potentially hit the max recursion limit? It depends on the nature of your data. If the data is a tree, it's very unlikely you'll reach the recursion limit unless the tree is massively unbalanced. If there's a chance of that, or if th

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Gregory Ewing
Steven D'Aprano wrote: def a(x=4) x+2 end a + b => 7 a+b => 7 a+ b => 7 a +b => 3 A shiny new penny for any non-Ruby coder who can explain that! Seems pretty obvious to me: the Ruby interpreter is infested with demons. DWIM = Demonic Whim Infers Meaning -- Greg -- https://mail.pyth

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Gregory Ewing
Chris Angelico wrote: Every once in a while, someone looks at Py2's print statement and Py3's print function and says, "why not allow function calls without parentheses". This right here is why not. There's also the fact that the parens are needed to distinguish between calling a function and u

Re: Why do the URLs of posts here change?

2015-01-17 Thread Gregory Ewing
Albert van der Horst wrote: Knowing that the source is an mbox file, I don't need to follow that link to conclude that one is not very inventive. It suffices to replace the content of the message by a repetition of '\n'. Editing the mbox file isn't the problem. From what I gather, telling m

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Gregory Ewing
Jussi Piitulainen wrote: I prefer parentheses. They are not nearly as fragile. So do I, but the other day I had occasion to write a small piece of VBScript, and I discovered that it actually *forbids* parens around the arguments to procedure calls (but not function calls). Fortunately, it requ

Re: Fwd: Re: Comparisons and sorting of a numeric class....

2015-01-27 Thread Gregory Ewing
Andrew Robinson wrote: The spelling caveat is great -- and in Python the object named in bool's honor is spelled bool (lowercase too). ;) That doesn't change the fact that the man was called George Boole (not Charles!). If you're going to refer to him by name, it's only courteous to make some

Re: An object is an instance (or not)?

2015-01-27 Thread Gregory Ewing
Mario Figueiredo wrote: That error message has me start that thread arguing that the error is misleading because the Sub object does have the __bases__ attribute. It's the Sub instance object that does not have it. Some of the answers that were given argued that in Python object = instance.

Re: An object is an instance (or not)?

2015-01-28 Thread Gregory Ewing
Mario Figueiredo wrote: I couldn't think of a way to demonstrate that a class object does not participate in its own inheritance rules. Only instances of it can. I think I may see where your reasoning is going astray. You think that an instance "inherits" methods from its class in the same way

Re: An object is an instance (or not)?

2015-01-28 Thread Gregory Ewing
Mario Figueiredo wrote: An instance of an object is capable of doing so, per its class definitions. Whereas a Python class object is not. >>> class Master: def func(self): pass >>> class Sub(Master): pass >>> Sub.func() TypeError: func()

Re: An object is an instance (or not)?

2015-01-28 Thread Gregory Ewing
Steven D'Aprano wrote: In fairness, "inherit" is standard terminology for the way instances get their behaviour from their class. I'm not sure that's true, but even if it is, it's not the same kind of inheritance relationship as exists between a class and a base class, which was my point. Al

Re: An object is an instance (or not)?

2015-01-30 Thread Gregory Ewing
Steven D'Aprano wrote: Actually, if you look at my example, you will see that it is a method and it does get the self argument. Here is the critical code again: from types import MethodType polly.talk = MethodType( lambda self: print("Polly wants a spam sandwich!"), polly) Doing it by han

Re: [OT] fortran lib which provide python like data type

2015-01-30 Thread Gregory Ewing
Michael Torrie wrote: On 01/30/2015 10:31 AM, Rustom Mody wrote: And what about the grey area between lightweight and heavyweight? That's what the smart pointers are for. I'd say it's what higher-level languages are for. :-) I'm completely convinced nowadays that there is *no* use case for

Re: dunder-docs (was Python is DOOMED! Again!)

2015-02-01 Thread Gregory Ewing
Steven D'Aprano wrote: [quote] If the object has a method named __dir__(), this method will be called and must return the list of attributes. [end quote] The first inaccuracy is that like all (nearly all?) dunder methods, Python only looks for __dir__ on the class, not the inst

Re: Python is DOOMED! Again!

2015-02-01 Thread Gregory Ewing
Steven D'Aprano wrote: If I have an arbitrary pointer, and I want to check if it is safe to dereference, how do I do it? Surely I'm not expected to write something like: if type(ptr) == A: if ptr != Anil: ... if type(ptr) == B: if ptr != Bnil: ... etc. That would be insane. So how doe

Re: Python is DOOMED! Again!

2015-02-01 Thread Gregory Ewing
Devin Jeanpierre wrote: I answered my own question later, by accident: Java nulls are castable to each other if you do it explicitly (routing through Object -- e.g. (Something)((Object) ((SomeOtherThing) null. So in that sense, there is only one null, just with some arbitrary compiler distin

Re: dunder-docs (was Python is DOOMED! Again!)

2015-02-03 Thread Gregory Ewing
Steven D'Aprano wrote: Both K.f and K.g are methods, even though only one meets the definition given in the glossary. The glossary is wrong. Or rather, it is not so much that it is *wrong*, but that it is incomplete and over-simplified. I agree with that; a more complete definition would be "a

Re: dunder-docs (was Python is DOOMED! Again!)

2015-02-03 Thread Gregory Ewing
Steven D'Aprano wrote: In Python 2, they are methods. In Python 3, they are functions, and aren't converted into methods until you access them via the instance: They're methods in both cases. They don't have to be "converted into methods"; they already are, by virtue of their location and inte

<    5   6   7   8   9   10   11   12   13   14   >