Re: Lost in descriptor land

2016-06-30 Thread Ian Kelly
On Thu, Jun 30, 2016 at 7:06 PM, Ankush Thakur wrote: > Hello, > > There's something I don't understand about descriptors. On a StackOverflow > discussion > (http://stackoverflow.com/questions/12846116/python-descriptor-vs-property) > one of the answers provides the following descriptors exampl

Re: Descriptor: class name precedence over instance name

2016-07-01 Thread Ian Kelly
On Fri, Jul 1, 2016 at 10:27 PM, Veek. M wrote: > Trying to make sense of this para: > > -- > Also, the attribute name used by the class to hold a descriptor takes > prece- dence over attributes stored on instances. > > In the previous example, > thi

Re: Meta decorator with parameters, defined in explicit functions

2016-07-01 Thread Ian Kelly
On Fri, Jul 1, 2016 at 4:08 PM, Lawrence D’Oliveiro wrote: > On Tuesday, June 28, 2016 at 5:03:08 PM UTC+12, Ben Finney wrote: >> There is a clever one-line decorator that has been copy-pasted without >> explanation in many code bases for many years:: >> >> decorator_with_args = lambda decorat

Re: Meta decorator with parameters, defined in explicit functions

2016-07-01 Thread Ian Kelly
On Fri, Jul 1, 2016 at 11:32 PM, Ben Finney wrote: > Ian Kelly writes: > >> You should use functools.wraps instead of clobbering the decorated >> function's name and docstring: >> >> @functools.wraps(decorator) >> def decorate(*args, **kw

Re: Descriptor: class name precedence over instance name

2016-07-02 Thread Ian Kelly
On Sat, Jul 2, 2016 at 3:34 AM, Veek. M wrote: > So essentially from what Ian said: > data_descriptor_in_instance -> instance_attribute -> non- > data_descriptor_in_instance -->__mro__ > > is how the search takes place. Correct? Close, but I would write it as: data_descriptor_in_class_including_m

Re: Lost in descriptor land

2016-07-02 Thread Ian Kelly
On Sat, Jul 2, 2016 at 5:32 AM, Ankush Thakur wrote: > On Friday, July 1, 2016 at 9:13:19 AM UTC+5:30, Lawrence D’Oliveiro wrote: >> >> > Shouldn't we be instead using self.celcius in, say, __init__() and then >> > everything will work fine? >> >> I guess it might. But this way, using descriptors,

Re: Meta decorator with parameters, defined in explicit functions

2016-07-02 Thread Ian Kelly
On Sat, Jul 2, 2016 at 12:40 AM, Lawrence D’Oliveiro wrote: > On Saturday, July 2, 2016 at 5:10:06 PM UTC+12, Ian wrote: >> You should use functools.wraps instead of clobbering the decorated >> function's name and docstring: > > Where am I doing that? Using the implementation you posted: >>> @de

Re: Meta decorator with parameters, defined in explicit functions

2016-07-03 Thread Ian Kelly
On Sat, Jul 2, 2016 at 11:37 PM, Lawrence D’Oliveiro wrote: > On Sunday, July 3, 2016 at 4:49:15 PM UTC+12, Ian wrote: >> >> On Sat, Jul 2, 2016 at 12:40 AM, Lawrence D’Oliveiro wrote: >>> >>> On Saturday, July 2, 2016 at 5:10:06 PM UTC+12, Ian wrote: You should use functools.wraps inste

Re: Special attributes added to classes on creation

2016-07-03 Thread Ian Kelly
On Sun, Jul 3, 2016 at 10:02 AM, Steven D'Aprano wrote: > If I then try it against two identical (apart from their names) classes, I > get these results: > > > py> @process > ... class K: > ... x = 1 > ... > ['__dict__', '__doc__', '__module__', '__weakref__', 'x'] > py> class Q(metaclass=proc

Re: Meta decorator with parameters, defined in explicit functions

2016-07-03 Thread Ian Kelly
On Sun, Jul 3, 2016 at 3:17 PM, Lawrence D’Oliveiro wrote: > On Sunday, July 3, 2016 at 11:53:46 PM UTC+12, Ian wrote: >> On Sat, Jul 2, 2016 at 11:37 PM, Lawrence D’Oliveiro wrote: >>> That is a function that I am generating, so naturally I want to give it a >>> useful docstring. Am I “clobbering

Re: Meta decorator with parameters, defined in explicit functions

2016-07-03 Thread Ian Kelly
On Sun, Jul 3, 2016 at 5:25 PM, Lawrence D’Oliveiro wrote: > On Monday, July 4, 2016 at 10:39:30 AM UTC+12, Ian wrote: >> Sorry, but you're the one who doesn't seem to get it. Because it's a >> decorator, "your" function is replacing the caller's function in the >> caller's namespace. > > No it is

Re: Meta decorator with parameters, defined in explicit functions

2016-07-03 Thread Ian Kelly
On Sun, Jul 3, 2016 at 6:06 PM, Lawrence D’Oliveiro wrote: > On Monday, July 4, 2016 at 12:02:23 PM UTC+12, Ian wrote: >> I'm talking about the docstring of the *decorator*, not func. > > *Sigh*. Originally somebody was complaining that the lambda version didn’t > allow for good (or any) docstrin

Re: Nested class doesn't see class scope

2016-07-04 Thread Ian Kelly
On Mon, Jul 4, 2016 at 9:42 PM, Paul Rubin wrote: > Steven D'Aprano writes: >> ... class B: >> ... x = var > > x = A.var Nope. A doesn't exist yet at this point. -- https://mail.python.org/mailman/listinfo/python-list

Re: Nested class doesn't see class scope

2016-07-04 Thread Ian Kelly
On Mon, Jul 4, 2016 at 9:20 PM, Steven D'Aprano wrote: > I got this in Python 3.6: > > > py> class A: > ... var = 999 > ... print(var) # succeeds > ... class B: > ... x = var > ... > 999 > Traceback (most recent call last): > File "", line 1, in > File "", line 3, in A >

Re: Nested class doesn't see class scope

2016-07-04 Thread Ian Kelly
On Mon, Jul 4, 2016 at 10:41 PM, Ian Kelly wrote: > On Mon, Jul 4, 2016 at 9:20 PM, Steven D'Aprano wrote: >> I got this in Python 3.6: >> >> >> py> class A: >> ... var = 999 >> ... print(var) # succeeds >> ... class B: >>

Re: Making Classes Subclassable

2016-07-05 Thread Ian Kelly
On Tue, Jul 5, 2016 at 2:31 AM, Steven D'Aprano wrote: > On Monday 04 July 2016 18:34, Lawrence D’Oliveiro wrote: > >> On Monday, July 4, 2016 at 7:58:07 PM UTC+12, dieter wrote: >>> --> "type(obj)" or "obj.__class__" (there are small differences) >>> give you the type/class of "obj". >> >> When w

Re: Making Classes Subclassable

2016-07-05 Thread Ian Kelly
On Mon, Jul 4, 2016 at 1:57 AM, dieter wrote: > Lawrence D’Oliveiro writes: > >> Some of the classes in Qahirah, my Cairo binding >> I found handy to reuse elsewhere, for >> example in my binding for Pixman . >> Subclassing

Re: Making Classes Subclassable

2016-07-05 Thread Ian Kelly
On Mon, Jul 4, 2016 at 2:34 AM, Lawrence D’Oliveiro wrote: > On Monday, July 4, 2016 at 7:58:07 PM UTC+12, dieter wrote: >> --> "type(obj)" or "obj.__class__" (there are small differences) >> give you the type/class of "obj". > > When would it not be the same? I think the only remaining differenc

Re: Curious Omission In New-Style Formats

2016-07-10 Thread Ian Kelly
On Sat, Jul 9, 2016 at 11:54 PM, Lawrence D’Oliveiro wrote: > In printf-style formats, you can specify the number of digits for an integer > separately from the field width. E.g. > > >>> "%#0.5x" % 0x123 > '0x00123' > > but not in new-style formats: > > >>> "{:#0.5x}".format(0x123) >

Re: Quick poll: gmean or geometric_mean

2016-07-10 Thread Ian Kelly
On Sat, Jul 9, 2016 at 3:45 PM, Chris Angelico wrote: > On Sat, Jul 9, 2016 at 3:26 PM, Steven D'Aprano wrote: >> I'd like to get a quick show of hands regarding the names. Which do you >> prefer? >> >> hmean and gmean >> >> harmonic_mean and geometric_mean > > I'd prefer the shorter names. I'd

Re: Quick poll: gmean or geometric_mean

2016-07-10 Thread Ian Kelly
On Sun, Jul 10, 2016 at 8:29 AM, Rustom Mody wrote: > Newton's law F = -Gm₁m₂/r² > > Better seen in its normal math form: > https://en.wikipedia.org/wiki/Newton%27s_law_of_universal_gravitation#Modern_form > > De-abbreviated > > Force is given by the negative of the universal_gravitational_constan

Re: Quick poll: gmean or geometric_mean

2016-07-10 Thread Ian Kelly
On Sun, Jul 10, 2016 at 2:01 AM, Jussi Piitulainen wrote: > Ian Kelly writes: > >> On Sat, Jul 9, 2016 at 3:45 PM, Chris Angelico wrote: >>> On Sat, Jul 9, 2016 at 3:26 PM, Steven D'Aprano wrote: >>>> I'd like to get a quick show of hands re

Re: Quick poll: gmean or geometric_mean

2016-07-10 Thread Ian Kelly
On Sun, Jul 10, 2016 at 9:03 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> That's still excessive by any reasonable standards. Names should be >> descriptive, but no more verbose than necessary. How about: >> >> force_N = -G * mass1_kg * mass2_kg / distance_m *

Re: one command on backslash and space for review

2016-07-10 Thread Ian Kelly
On Sun, Jul 10, 2016 at 9:19 AM, Ganesh Pal wrote: > Hello Team, > > I am on python 2.7 and Linux , I want to form the below sample > command so that I could run it on the shell. > > Command is --> run_parallel -za1 -s 'daemon -cf xyz; sleep 1' > > Here is how I formed the command and it seems

Re: Curious Omission In New-Style Formats

2016-07-11 Thread Ian Kelly
On Sun, Jul 10, 2016 at 6:34 PM, Lawrence D’Oliveiro wrote: > On Sunday, July 10, 2016 at 7:22:42 PM UTC+12, Ian wrote: >> On Sat, Jul 9, 2016 at 11:54 PM, Lawrence D’Oliveiro wrote: >>> In printf-style formats, you can specify the number of digits for an >>> integer separately from the field widt

Re: Curious Omission In New-Style Formats

2016-07-11 Thread Ian Kelly
On Mon, Jul 11, 2016 at 10:28 AM, Steven D'Aprano wrote: > On Tue, 12 Jul 2016 01:04 am, Ian Kelly wrote: >> Your example showed a 3-digit number being formatted with a requested >> precision of 5 digits. The way this was done was by left-padding the >> number with 0s

Re: Curious Omission In New-Style Formats

2016-07-11 Thread Ian Kelly
On Mon, Jul 11, 2016 at 12:54 PM, Terry Reedy wrote: > In any case, I think it an improvement to say that '0x00123' has a field > width of 7 rather than a 'precision' of 5. > '{:#07x}'.format(0x123) # specifiy field width > '0x00123' "%#0.5x" % 0x123 # specify int precision > '0x00123'

Re: Curious Omission In New-Style Formats

2016-07-11 Thread Ian Kelly
On Mon, Jul 11, 2016 at 5:47 PM, Gregory Ewing wrote: > Ethan Furman wrote: >> >> I will readily admit to not having a maths degree, and so of course to me >> saying the integer 123 has a precision of 5, 10, or 99 digits seems like >> hogwash to me. > > > Seems to me insisting that the number afte

Re: Compression of random binary data

2016-07-12 Thread Ian Kelly
On Tue, Jul 12, 2016 at 11:35 AM, wrote: > > No it is only compressible down to a limit given by the algorithm. Then your algorithm does not compress random data as you claimed. For some input, determine the limiting output that it ultimately compresses down to. Take that output and feed it thr

Re: Curious Omission In New-Style Formats

2016-07-12 Thread Ian Kelly
On Mon, Jul 11, 2016 at 9:38 PM, Steven D'Aprano wrote: > For integers, printf and % interpret the so-called "precision" field of the > format string not as a measurement precision (number of decimal places), > but as the number of digits to use (which is different from the total field > width). F

Re: Python Byte Code Hacking

2016-07-13 Thread Ian Kelly
On Wed, Jul 13, 2016 at 12:48 PM, Vijay Kumar wrote: > Hi Everyone, > I wrote an article on Python byte code hacking. The article is available > from http://www.bravegnu.org/blog/python-byte-code-hacks.html The article > uses an incremental approach for explaining Python's code objects and how to

Re: Clean Singleton Docstrings

2016-07-13 Thread Ian Kelly
On Wed, Jul 13, 2016 at 5:54 PM, Peter Otten <__pete...@web.de> wrote: > Lawrence D’Oliveiro wrote: > >> On Friday, July 8, 2016 at 7:38:56 PM UTC+12, Peter Otten wrote: >> >>> There is a test >>> >>> if not object: >>> raise ImportError('no Python documentation found for %r' % thing) >>> >>> i

Re: Curious Omission In New-Style Formats

2016-07-13 Thread Ian Kelly
On Wed, Jul 13, 2016 at 4:24 PM, Lawrence D’Oliveiro wrote: > On Wednesday, July 13, 2016 at 6:22:31 PM UTC+12, Ian wrote: > >> ... don't call it "precision". > > How about “mantissa length”, then. That sufficiently neutral for you? That makes even less sense for integers. -- https://mail.python

Re: Curious Omission In New-Style Formats

2016-07-13 Thread Ian Kelly
On Wed, Jul 13, 2016 at 9:39 PM, Lawrence D’Oliveiro wrote: > On Thursday, July 14, 2016 at 12:46:26 PM UTC+12, Ian wrote: >> On Wed, Jul 13, 2016 at 4:24 PM, Lawrence D’Oliveiro wrote: >>> On Wednesday, July 13, 2016 at 6:22:31 PM UTC+12, Ian wrote: >>> ... don't call it "precision". >>> >>>

Re: Curious Omission In New-Style Formats

2016-07-14 Thread Ian Kelly
On Jul 14, 2016 1:52 AM, "Steven D'Aprano" wrote: > > On Thursday 14 July 2016 15:18, Ian Kelly wrote: > > > Side note, neither do floating point numbers, really; what is often > > called the mantissa is more properly known as the significand. But > >

Re: Curious Omission In New-Style Formats

2016-07-14 Thread Ian Kelly
On Thu, Jul 14, 2016 at 10:02 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> The significand of -3.14159 is the sequence of digits 314159. The >> mantissa of -3.14159 is the number 0.85841. > > Fight it all you want. However: > >In American English, the original w

Re: Curious Omission In New-Style Formats

2016-07-14 Thread Ian Kelly
On Jul 14, 2016 11:37 AM, "Marko Rauhamaa" wrote: > > Ian Kelly : > > On Thu, Jul 14, 2016 at 10:02 AM, Marko Rauhamaa wrote: > >>In American English, the original word for [significand] seems to > >>have been mantissa (Burks[1] et al.), and this u

Re: What exactly is "exact" (was Clean Singleton Docstrings)

2016-07-18 Thread Ian Kelly
On Mon, Jul 18, 2016 at 3:29 AM, Steven D'Aprano wrote: > On Monday 18 July 2016 14:16, Rustom Mody wrote: >> In short one could think of inexact and exact — in scheme's intended >> semantics — as better called scientific (or science-ic) and mathematic >> numbers. > > I don't think so. "Science" u

Re: What exactly is "exact" (was Clean Singleton Docstrings)

2016-07-18 Thread Ian Kelly
On Mon, Jul 18, 2016 at 9:55 AM, Marko Rauhamaa wrote: > Marko Rauhamaa : > >> Ian Kelly : >>> Off-topic, c being a fundamental constant is actually in the latter >>> category. Its *exact* value is 299792458 m/s. >>> >>> The length of the mete

Re: an error

2016-07-18 Thread Ian Kelly
On Tue, Jul 19, 2016 at 12:07 AM, WePlayGames WeEnjoyIt wrote: >pygame1.blit(image3,(143,146) This line is missing a closing parenthesis. -- https://mail.python.org/mailman/listinfo/python-list

Re: What exactly is "exact" (was Clean Singleton Docstrings)

2016-07-19 Thread Ian Kelly
On Tue, Jul 19, 2016 at 2:35 PM, Gene Heskett wrote: > And I am not familiar with this foot-poundals per second that you > question about, but just from the wording I'd say it is a fifty dollar > way to say horsepower. https://en.wikipedia.org/wiki/Foot-poundal > Which is defined in the area of

reversed(enumerate(x))

2016-07-20 Thread Ian Kelly
I had occasion to write something like this: for i, n in reversed(enumerate(x)): pass Of course this fails with "TypeError: argument to reversed() must be a sequence". I ended up using this instead: for i, n in zip(reversed(range(len(x))), reversed(x)): pass This works but is extraordin

Re: reversed(enumerate(x))

2016-07-21 Thread Ian Kelly
On Wed, Jul 20, 2016 at 1:16 PM, Random832 wrote: > On Wed, Jul 20, 2016, at 13:42, Ian Kelly wrote: >> I had occasion to write something like this: >> >> for i, n in reversed(enumerate(x)): pass >> >> How would you write this? > > I'd write my o

Re: reversed(enumerate(x))

2016-07-21 Thread Ian Kelly
On Wed, Jul 20, 2016 at 11:54 AM, Brendan Abel <007bren...@gmail.com> wrote: > You could create your own generator that wraps enumerate > > def reverse_enumerate(iterable): > for i, val in enumerate(reversed(iterable)): > yield len(iterable) - 1 - i, val > > for i, val in reverse_enumer

Re: How asyncio works? and event loop vs exceptions

2016-07-23 Thread Ian Kelly
On Fri, Jul 22, 2016 at 6:27 PM, Marco S. via Python-list wrote: > Furthermore I have a question about exceptions in asyncio. If I > understand well how it works, tasks exceptions can be caught only if > you wait for task completion, with yield from, await or > loop.run_until_complete(future). But

Re: Python Print Error

2016-07-28 Thread Ian Kelly
On Thu, Jul 28, 2016 at 11:40 AM, Cai Gengyang wrote: > How to debug this ? > print "This line will be printed." This is Python 2 print statement syntax. > SyntaxError: Missing parentheses in call to 'print' This indicates that you're trying to run the above in Python 3. -- https://mail.p

Re: Why not allow empty code blocks?

2016-07-29 Thread Ian Kelly
On Jul 29, 2016 7:22 AM, "BartC" wrote: > > On 29/07/2016 12:14, D'Arcy J.M. Cain wrote: >> >> On Fri, 29 Jul 2016 10:58:35 +0200 >> Antoon Pardon wrote: >>> >>> As BartC already mentions it happens fairly often during debugging. >>> Something like. >>> >>> try: >>>Some code >>> except Some_E

Re: Call function via literal name

2016-07-29 Thread Ian Kelly
On Fri, Jul 29, 2016 at 2:35 PM, TUA wrote: > Rather than do this: > > if test['method'] == 'GET': > res = requests.get(test['endpoint'],auth=test['auth'], > verify=False) > elif test['method'] == 'POST': > res = requests.post(test['endpoint'],

Re: Why not allow empty code blocks?

2016-07-31 Thread Ian Kelly
On Sun, Jul 31, 2016 at 1:51 AM, Marko Rauhamaa wrote: > It is quite astounding how Lisp is steadily being reinvented by the > down-to-earth programming community. It was famously observed by Paul > Graham in 2002 (http://www.paulgraham.com/icad.html>). The > evolution has kept on going since then

Re: Learning Descriptors

2016-07-31 Thread Ian Kelly
On Sun, Jul 31, 2016 at 6:33 AM, Gerald Britton wrote: > Today, I was reading RH's Descriptor HowTo Guide at > > https://docs.python.org/3/howto/descriptor.html?highlight=descriptors > > I just really want to fully "get" this. > > So I put together a little test from scratch. Looks like this: > >

Re: use import *

2016-08-01 Thread Ian Kelly
On Mon, Aug 1, 2016 at 9:31 AM, Ganesh Pal wrote: > Hi Team , > > I am a Linux user on python 2,6 . I have a very simple question > > I was going the zen of python by Tim peters and found an example that > demonstrates Explicit is better than implicit > > """Load the cat, dog, and mouse models so

Re: Can math.atan2 return INF?

2016-08-01 Thread Ian Kelly
On Sun, Jul 31, 2016 at 10:05 PM, Rustom Mody wrote: > All starts with the disorder in the middle-east and a whole lot of arbitrary > lines > drawn there > [Going backward in time] > - A line drawn in space called ‘Israel’ > - Based on a line drawn in time called the ‘Exodus of Moses’ I'm no exp

Re: Python slang

2016-08-06 Thread Ian Kelly
On Aug 6, 2016 2:10 PM, "Marco Sulla via Python-list" < python-list@python.org> wrote: Yes, I was thinking manly to SQL. That furthermore is NOT a programming language. Why not? It's claimed to be Turing complete. http://beza1e1.tuxen.de/articles/accidentally_turing_complete.html -- https://m

Re: How do I make a game in Python ?

2016-08-06 Thread Ian Kelly
On Aug 6, 2016 11:57 AM, "Cai Gengyang" wrote: How do I make a game in Python ? import random answer = random.randint(0, 100) while True: guess = input("What number am I thinking of? ") if int(guess) == answer: print("Correct!") break print("Wrong!") And now you've

Re: Python slang

2016-08-06 Thread Ian Kelly
On Aug 6, 2016 3:36 PM, "Michael Torrie" wrote: Sadly it has become an epidemic of late for folks to misuse the word, "myself." I think it comes from people not wanting to sound presumptuous when referring to themselves. It drives me crazy to hear so many people say something like, "this resear

Re: Iterators of iterators

2018-11-16 Thread Ian Kelly
On Fri, Nov 16, 2018 at 8:01 AM Steve Keller wrote: > > I wonder why iterators do have an __iter__() method? I thought > iterable objects would have an __iter__() method (but no __next__()) > to create an iterator for it, and that would have the __next__() > method but no __iter__(). > > $ py

Re: Generators, generator expressions, and loops

2018-11-16 Thread Ian Kelly
On Fri, Nov 16, 2018 at 7:57 AM Steve Keller wrote: > > I have looked at generators, generator expressions, and iterators and > I try to get more familiar with these. > > 1. How would I loop over all (with no upper bound) integers or all > powers of two, for example? > > In C it would be > >fo

Re: on the prng behind random.random()

2018-11-19 Thread Ian Kelly
On Mon, Nov 19, 2018 at 2:12 PM Robert Girault wrote: > > Chris Angelico writes: > > > On Tue, Nov 20, 2018 at 7:31 AM Robert Girault wrote: > >> Nice. So Python's random.random() does indeed use mt19937. Since it's > >> been broken for years, why isn't it replaced by something newer like > >>

Re: Odd truth result with in and ==

2018-11-21 Thread Ian Kelly
On Wed, Nov 21, 2018 at 2:53 PM Serhiy Storchaka wrote: > > 21.11.18 22:17, Cameron Simpson пише: > > Can someone show me a real world, or failing that - sane looking, > > chained comparison using "in"? > > s[0] == s[-1] in '\'"' > > Tests that string s starts and ends with a single or double

Re: Question on difference between LambdaType and FunctionType

2018-11-26 Thread Ian Kelly
On Sun, Nov 25, 2018 at 2:00 PM Chris Angelico wrote: > > On Mon, Nov 26, 2018 at 7:55 AM Iwo Herka wrote: > > > > > class Foo: > > >def setup(self): ... > > >__init__ = lambda self: self.setup() > > > > Sorry, didn't address this. This is fine too, since I'm assuming that > > only method

Re: Why Python don't accept 03 as a number?

2018-12-07 Thread Ian Kelly
On Fri, Dec 7, 2018 at 7:47 PM wrote: > > MRAB at 2018/12/8 UTC+8 AM10:04:51 wrote: > > Before Python 3, a leading 0 in an integer literal would indicate an > > octal (base 8) number. > > So, the reason is historical. > > > The old form is now invalid in order to reduce the chance of bugs. > > I e

Re: Why Python don't accept 03 as a number?

2018-12-08 Thread Ian Kelly
On Fri, Dec 7, 2018 at 11:56 PM Henrik Bengtsson wrote: > > A comment from the sideline: one could imagine extending the Python syntax > with a (optional) 0d prefix that allows for explicit specification of > decimal values. They would "complete" the family: > > * 0b: binary number > * 0o: octal n

Re: Program to keep track of success percentage

2018-12-08 Thread Ian Kelly
On Sat, Dec 8, 2018 at 1:22 PM Alister via Python-list wrote: > > On Sat, 08 Dec 2018 10:02:41 -0800, Musatov wrote: > > > I am thinking about a program where the only user input is win/loss. The > > program let's you know if you have won more than 31% of the time or not. > > Any suggestions about

Re: Why Python don't accept 03 as a number?

2018-12-08 Thread Ian Kelly
On Sat, Dec 8, 2018 at 7:57 PM wrote: > > Grant Edwards於 2018年12月9日星期日 UTC+8上午12時52分04秒寫道: > > Just to be clear: you do _not_ want to use eval on the string. > > > > If you're not the one who created the string, it might wipe your hard > > drive or empty your bank account. If you _are_ the one wh

Re: Why do data descriptors (e.g. properties) take priority over instance attributes?

2018-12-18 Thread Ian Kelly
On Mon, Dec 17, 2018, 12:09 PM Paul Baker When Python looks up an attribute on an object (i.e. when it executes > `o.a`), it uses an interesting priority order [1]. It looks for: > > 1. A class attribute that is a data-descriptor (most commonly a property) > 2. An instance attribute > 3. Any ot

Re: Ask for help about class variable scope (Re: Why doesn't a dictionary work in classes?)

2018-12-27 Thread Ian Kelly
On Wed, Dec 26, 2018 at 11:21 PM Chris Angelico wrote: > > On Thu, Dec 27, 2018 at 1:56 PM wrote: > > > > I saw the code below at stackoverflow. I have a little idea about the scope > > of a class, and list comprehension and generator expressions, but still > > can't figure out why Z4 works and

Re: Question about slight deviations when using integer division with large integers.

2018-12-30 Thread Ian Kelly
On Sun, Dec 30, 2018 at 10:27 PM Cameron Simpson wrote: > > On 30Dec2018 21:14, Christian Seberino wrote: > >What is simplest way to make both those > >prints give same values? Any slicker way > >than an if statement? > > If your post had an attachment, be aware that the python-list list drops >

Re: Question about slight deviations when using integer division with large integers.

2018-12-30 Thread Ian Kelly
On Sun, Dec 30, 2018 at 10:18 PM Christian Seberino wrote: > > What is simplest way to make both those > prints give same values? Any slicker way > than an if statement? Stack Overflow has a few suggestions: https://stackoverflow.com/questions/19919387/in-python-what-is-a-good-way-to-round-towar

Re: Type hinting of Python is just a toy ?

2019-01-04 Thread Ian Kelly
On Fri, Jan 4, 2019 at 1:20 AM Chris Angelico wrote: > > Pep484 is too complex. Typle should not a seperate type, in fact it should > > be just a class. Like this in other programming language > > Python: Tuple(id: int, name: string, age: int) > > Other: class someClass { > > public int i

Re: Type hinting of Python is just a toy ?

2019-01-04 Thread Ian Kelly
On Fri, Jan 4, 2019 at 10:44 AM iamybj--- via Python-list wrote: > > { id: 1, name:’abc’, age:99, address:{province:’CA’, city:’SA’}} Those are nested dicts, not tuples, which leaves your argument really unclear. A dict is essentially a hash map. Java and C# (it's unclear what language you're co

Re: the python name

2019-01-04 Thread Ian Kelly
On Fri, Jan 4, 2019 at 10:59 AM Dennis Lee Bieber wrote: > > On Fri, 4 Jan 2019 01:12:42 -0500, "Avi Gross" > declaimed the following: > > > >language, Formula Translator? (I recall using the What For version). > > WATFOR => WATerloo FORtran And then there was WATFIV, which stands for WA

Re: Pythonic Y2K

2019-01-17 Thread Ian Kelly
On Wed, Jan 16, 2019 at 9:57 PM Avi Gross wrote: > > The forthcoming UNIX 2038 problem will, paradoxically happen on January 19. I wonder what they will do long before then. Will they just add a byte or four or 256 and then make a date measurable in picoseconds? Or will they start using a number f

Re: What is your experience porting Python 2.7.x scripts to Python 3.x?

2019-01-23 Thread Ian Kelly
On Wed, Jan 23, 2019 at 1:36 PM Stefan Behnel wrote: > > Cameron Simpson schrieb am 23.01.19 um 00:21: > > from __future__ import absolute_imports, print_function > > > > gets you a long way. > > ... and: division. All right, but apart from absolute imports, the print function, and true division

Re: The slash "/" as used in the documentation

2019-02-10 Thread Ian Kelly
On Sat, Feb 9, 2019 at 1:19 PM Terry Reedy wrote: > > This is the result of Python being a project of mostly unpaid volunteers. > > See my response in this thread explaining how '/' appears in help output > and IDLE calltips. '/' only appears for CPython C-coded functions that > have been modifie

Re: The slash "/" as used in the documentation

2019-02-10 Thread Ian Kelly
On Sun, Feb 10, 2019 at 9:34 AM Chris Angelico wrote: > > On Mon, Feb 11, 2019 at 2:49 AM Ian Kelly wrote: > > > > On Sat, Feb 9, 2019 at 1:19 PM Terry Reedy wrote: > > > > > > This is the result of Python being a project of mostly unpaid volunteers. > &

Re: The slash "/" as used in the documentation

2019-02-10 Thread Ian Kelly
On Sun, Feb 10, 2019 at 2:18 PM Avi Gross wrote: > I am not sure how python implements some of the functionality it does as > compared to other languages with similar features. But I note that there are > rules, presumably some for efficiency, such as requiring all keyword > arguments to be placed

Re: The slash "/" as used in the documentation

2019-02-10 Thread Ian Kelly
On Mon, Feb 11, 2019 at 12:19 AM Terry Reedy wrote: > The pass-by-position limitation is not in CPython, it is the behavior of > C functions, which is the behavior of function calls in probably every > assembly and machine language. Allowing the flexibility of Python > function calls take extra c

Re: The slash "/" as used in the documentation

2019-02-11 Thread Ian Kelly
On Mon, Feb 11, 2019 at 1:35 PM Chris Angelico wrote: > > On Tue, Feb 12, 2019 at 7:26 AM Avi Gross wrote: > > If you want to talk about recent or planned changes, fine. But make that > > clear. I was talking about how in the past positional arguments did not have > > defaults available at the de

Re: The slash "/" as used in the documentation

2019-02-11 Thread Ian Kelly
On Mon, Feb 11, 2019 at 1:56 PM boB Stepp wrote: > > On Mon, Feb 11, 2019 at 2:34 PM Chris Angelico wrote: > > > Calling on the D'Aprano Collection of Ancient Pythons for confirmation > > here, but I strongly suspect that positional arguments with defaults > > go back all the way to 1.x. > > Has

Re: Generator question

2019-03-13 Thread Ian Kelly
You're basically running into this: https://docs.python.org/3/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result To see why, let's try disassembling your function. I'm using Python 3.5 here, but it shouldn't make much of a difference. py> import

Re: Why can't access the property setter using the super?

2019-03-19 Thread Ian Kelly
Here's the thing: the result of calling super() is not an instance of the base class. It's just a proxy object with a __getattribute__ implementation that looks up class attributes in the base class, and knows how to pass self to methods to simulate calling base class methods on an instance. This w

Re: Determining latest stable version for download

2019-03-20 Thread Ian Kelly
1) https://www.python.org/downloads/ has release information. Based on that you would currently want 3.7.2. Make sure you actually download 3.7.2 and not 3.7.2rc1. 2) The tarfiles are not distro-specific. For Linux there are really only two options: Python-3.7.2.tar.xz and Python-3.7.2.tgz. The onl

Re: Potential Security Bug

2019-03-20 Thread Ian Kelly
On Wed, Mar 20, 2019 at 5:14 AM Laish, Amit (GE Digital) wrote: > > Hello, > I’m Amit Laish, a security researcher from GE Digital. > During one of our assessments we discovered something that we consider a bug with security implications which can cause a denial of service by disk exhausting, and

Re: array of characters?

2019-03-22 Thread Ian Kelly
I don't know the answer, and PEP 393 doesn't talk about the array('u') deprecation directly. But it seems to me that with Py_UNICODE going away this array type code would have to be completely reimplemented, and also at that point array('u') is just equivalent to array('L') with some extra conversi

Re: Syntax for one-line "nonymous" functions in "declaration style"

2019-03-28 Thread Ian Kelly
On Wed, Mar 27, 2019 at 3:13 AM Paul Moore wrote: > > On Wed, 27 Mar 2019 at 08:25, Alexey Muranov wrote: > > > > Whey you need a simple function in Python, there is a choice between a > > normal function declaration and an assignment of a anonymous function > > (defined by a lambda-expression) t

Re: Syntax for one-line "nonymous" functions in "declaration style"

2019-03-28 Thread Ian Kelly
On Thu, Mar 28, 2019 at 2:30 PM Alexey Muranov wrote: > > On jeu., mars 28, 2019 at 8:57 PM, Terry Reedy wrote: > > Throwing the name away is foolish. Testing functions is another > > situation in which function names are needed for proper report. > > My idea however was to have it as an exact s

Re: Syntax for one-line "nonymous" functions in "declaration style"

2019-03-30 Thread Ian Kelly
On Sat, Mar 30, 2019, 5:32 AM Alexey Muranov wrote: > > On ven., Mar 29, 2019 at 4:51 PM, python-list-requ...@python.org wrote: > > > > There could perhaps be a special case for lambda expressions such > > that, > > when they are directly assigned to a variable, Python would use the > > variable

Re: Syntax for one-line "nonymous" functions in "declaration style"

2019-03-31 Thread Ian Kelly
On Sun, Mar 31, 2019 at 1:09 PM Alexey Muranov wrote: > > On dim., Mar 31, 2019 at 6:00 PM, python-list-requ...@python.org wrote: > > On Sat, Mar 30, 2019, 5:32 AM Alexey Muranov > > > > wrote: > > > >> > >> On ven., Mar 29, 2019 at 4:51 PM, python-list-requ...@python.org > >> wrote: > >> > > >

Re: Syntax for one-line "nonymous" functions in "declaration style"

2019-04-02 Thread Ian Kelly
On Mon, Apr 1, 2019 at 3:52 PM Alexey Muranov wrote: > > I only see a superficial analogy with `super()`, but perhaps it is > because you did not give much details of you suggestion. No, it's because the analogy was not meant to be anything more than superficial. Both are constructs of syntactic

Re: Syntax for one-line "nonymous" functions in "declaration style"

2019-04-02 Thread Ian Kelly
On Tue, Apr 2, 2019 at 1:43 AM Alexey Muranov wrote: > > > On Mon, Apr 1, 2019 at 3:52 PM Alexey Muranov > gmail.com> > > wrote: > > > > > > I only see a superficial analogy with `super()`, but perhaps it is > > > because you did not give much details of you suggestion. > > > > No, it's because t

Re: Conway's game of Life, just because.

2019-05-07 Thread Ian Kelly
On Tue, May 7, 2019 at 1:00 PM MRAB wrote: > > On 2019-05-07 19:29, Eli the Bearded wrote: > > In comp.lang.python, Paul Rubin wrote: > > > > Thanks for posting this. I'm learning python and am very familiar with > > this "game". > > > >> #!/usr/bin/python3 > >> from itertools import chain > >>

Re: How Do You Replace Variables With Their Values?

2019-07-14 Thread Ian Kelly
On Thu, Jul 11, 2019 at 11:10 PM Chris Angelico wrote: > > On Fri, Jul 12, 2019 at 2:30 PM Aldwin Pollefeyt > wrote: > > > > Wow, I'm so sorry I answered on the question : "How do you replace a > > variable with its value". For what i understood with the example values, > > CrazyVideoGamez wants

Re: super or not super?

2019-07-15 Thread Ian Kelly
On Sun, Jul 14, 2019 at 7:14 PM Chris Angelico wrote: > > On Mon, Jul 15, 2019 at 10:51 AM Paulo da Silva > wrote: > > > > Às 15:30 de 12/07/19, Thomas Jollans escreveu: > > > On 12/07/2019 16.12, Paulo da Silva wrote: > > >> Hi all! > > >> > > >> Is there any difference between using the base cl

Re: super or not super?

2019-07-16 Thread Ian Kelly
On Tue, Jul 16, 2019 at 1:21 AM Chris Angelico wrote: > > On Tue, Jul 16, 2019 at 3:32 PM Ian Kelly wrote: > > > > Just using super() is not enough. You need to take steps if you want to > > ensure that you class plays nicely with MI. For example, consider the > &g

Re: if bytes != str:

2019-08-04 Thread Ian Kelly
On Sun, Aug 4, 2019, 9:02 AM Hongyi Zhao wrote: > Hi, > > I read and learn the the following code now: > > https://github.com/shadowsocksr-backup/shadowsocksr-libev/blob/master/src/ > ssrlink.py > > > In this s

Re: Remote/Pair-Programming in-the-cloud

2019-08-04 Thread Ian Kelly
On Sat, Aug 3, 2019, 9:25 AM Bryon Tjanaka wrote: > Depending on how often you need to run the code, you could use a google doc > and copy the code over when you need to run. Of course, if you need linters > and other tools to run frequently this would not work. > I've conducted a number of remo

Re: Enumerate - int object not subscriptable

2019-08-20 Thread Ian Kelly
Or use the "pairwise" recipe from the itertools docs: from itertools import tee def pairwise(iterable): "s -> (s0,s1), (s1,s2), (s2, s3), ..." a, b = tee(iterable) next(b, None) return zip(a, b) for num1, num2 in pairwise(a): print(num1, num2) On Tue, Aug 20, 2019 at 7:42 AM

Re: itertools cycle() docs question

2019-08-21 Thread Ian Kelly
On Wed, Aug 21, 2019 at 12:36 PM Calvin Spealman wrote: > > The point is to demonstrate the effect, not the specific implementation. But still yes, that's pretty much exactly what it does. The main difference between the "roughly equivalent to" code and the actual implementation is that the forme

Re: ``if var'' and ``if var is not None''

2019-09-01 Thread Ian Kelly
On Sun, Sep 1, 2019, 8:58 AM Terry Reedy wrote: > On 9/1/2019 2:12 AM, Hongyi Zhao wrote: > > > The following two forms are always equivalent: > > ``if var'' and ``if var is not None'' > > Aside from the fact that this is false, why would you post such a thing? > Trolling? Did you hit [Send]

Re: To whoever hacked into my Database

2013-11-12 Thread Ian Kelly
On Tue, Nov 12, 2013 at 2:09 AM, Antoon Pardon wrote: > So you are complaining about people being human. Yes that is > how people tend to react when they continualy are frustrated > by someone who refuses to show the slightest cooperation. > So no rejecting such responses, particullarly by the per

<    10   11   12   13   14   15   16   17   18   19   >