Re: What is wrong with this regex for matching emails?

2017-12-17 Thread Ned Batchelder
On 12/17/17 10:29 AM, Peng Yu wrote: Hi, I would like to extract "a...@efg.hij.xyz". But it only shows ".hij". Does anybody see what is wrong with it? Thanks. $ cat main.py #!/usr/bin/env python # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8: import re email_re

Re: Python goto

2017-12-28 Thread Ned Batchelder
On 12/28/17 6:43 AM, jorge.conr...@cptec.inpe.br wrote: Hi, I would like to know if there is a goto command or something similar that I can use in Python. Python does not have a goto statement. You have to use structured statements: for, while, try/except, yield, return, etc. If you sh

Re: you shortened it, but you broke it too... ;-)

2018-01-01 Thread Ned Batchelder
On 12/31/17 8:15 PM, Wu Xi wrote: def neighbours(point): x,y = point yield x + 1 , y yield x - 1 , y yield x , y + 1 yield x , y - 1 #this is proof that life can emerge inside of computers and cellular automatons, yield x + 1 , y + 1

Re: Copy-on-write friendly Python garbage collection (Posting On Python-List Prohibited)

2018-01-01 Thread Ned Batchelder
On 1/1/18 1:49 PM, Niles Rogoff wrote: On Mon, 01 Jan 2018 10:42:58 -0800, breamoreboy wrote: On Monday, January 1, 2018 at 10:14:59 AM UTC, wxjm...@gmail.com wrote: Le lundi 1 janvier 2018 08:35:53 UTC+1, Lawrence D’Oliveiro a écrit : On Monday, January 1, 2018 at 7:52:48 AM UTC+13, Paul Rub

Re: Simple graphic library for beginners

2018-01-11 Thread Ned Batchelder
On 1/11/18 10:23 AM, Chris Angelico wrote: On Fri, Jan 12, 2018 at 12:38 AM, bartc wrote: On 11/01/2018 05:16, Michael Torrie wrote: On 01/10/2018 01:13 PM, bartc wrote: Yes the link didn't have the simple examples I hoped for. How's this: - import pygame import

Re: Simple graphic library for beginners

2018-01-11 Thread Ned Batchelder
On 1/11/18 8:21 PM, bartc wrote: On 11/01/2018 23:23, Chris Angelico wrote: On Fri, Jan 12, 2018 at 10:11 AM, bartc wrote: I'm almost ready to plonk you, but I think there is still SOME value in your posts. But please, stop denigrating what you don't understand. And please try to see thing

Re: Where is the usage of (list comprehension) documented?

2018-01-15 Thread Ned Batchelder
On 1/14/18 9:57 PM, Dan Stromberg wrote: On Sun, Jan 14, 2018 at 3:01 PM, Peng Yu wrote: Hi, I see the following usage of list comprehension can generate a generator. Does anybody know where this is documented? Thanks. Here's the (a?) generator expression PEP: https://www.python.org/dev/peps/

Re: documentation on read.encode

2018-01-16 Thread Ned Batchelder
On 1/16/18 2:19 PM, Larry Martell wrote: On Tue, Jan 16, 2018 at 12:00 PM, Larry Martell wrote: Looking for 2.7 docs on read.encode - googling did not turn up anything. Specifically, looking for the supported options for base64, and how to specify them, e.g. Base64.NO_WRAP So I just realized

Re: Speeding up the implementation of Stochastic Gradient Ascent in Python

2018-01-17 Thread Ned Batchelder
On 1/17/18 9:29 AM, leutrim.kal...@gmail.com wrote: Hello everyone, I am implementing a time-dependent Recommender System which applies BPR (Bayesian Personalized Ranking), where Stochastic Gradient Ascent is used to learn the parameters of the model. Such that, one iteration involves sampling

Re: Speeding up the implementation of Stochastic Gradient Ascent in Python

2018-01-17 Thread Ned Batchelder
On 1/17/18 2:45 PM, Chris Angelico wrote: On Thu, Jan 18, 2018 at 6:28 AM, Ned Batchelder wrote: You'll have to replace random.choice() with random.choice(list(...)), since you can't random.choice from a set. Side point: why can't you? You can random.sample from a set, bu

Re: exec and traceback

2018-01-22 Thread Ned Batchelder
On 1/22/18 3:22 AM, ken...@gameofy.com wrote: (BTW, I've written a simple secure eval()) You have accurately guessed our interest!  Would you mind starting a new thread to show us your simple secure eval? --Ned. -- https://mail.python.org/mailman/listinfo/python-list

Re: python to C code generator

2018-01-23 Thread Ned Batchelder
On 1/23/18 8:48 AM, kushal bhattacharya wrote: On Tuesday, January 23, 2018 at 7:05:02 PM UTC+5:30, bartc wrote: On 23/01/2018 13:23, kushal bhattacharya wrote: On Wednesday, January 17, 2018 at 4:34:23 PM UTC+5:30, kushal bhattacharya wrote: Hi, Is there any python framework or any tool as

Re: exec and traceback

2018-01-25 Thread Ned Batchelder
On 1/22/18 3:22 AM, ken...@gameofy.com wrote: I'm using exec() to run a (multi-line) string of python code. If an exception occurs, I get a traceback containing a stack frame for the string. I've labeled the code object with a "file name" so I can identify it easily, and when I debug, I find

Re: Please help on print string that contains 'tab' and 'newline'

2018-01-27 Thread Ned Batchelder
On 1/27/18 3:15 PM, Jason Qian via Python-list wrote: HI I am a string that contains \r\n\t [Ljava.lang.Object; does not exist*\r\n\t*at com.livecluster.core.tasklet I would like it print as : [Ljava.lang.Object; does not exist tat com.livecluster.core.tasklet It looks like

Re: PyPy support breaking CPython compatibility?

2018-01-30 Thread Ned Batchelder
On 1/30/18 2:35 PM, Etienne Robillard wrote: Hi, I managed to patch Schevo and Durus to run under PyPy 5.9. However, I'm afraid the changes is breaking Python 2.7 compatibility. I'm curious what you had to change for PyPy? (Unless it's a Py2/Py3 thing as Chris mentions.) I'm not sure how I

Re: PyPy support breaking CPython compatibility?

2018-01-30 Thread Ned Batchelder
On 1/30/18 4:08 PM, Chris Angelico wrote: On Wed, Jan 31, 2018 at 7:58 AM, Etienne Robillard wrote: Hi Ned, Le 2018-01-30 à 15:14, Ned Batchelder a écrit : I'm curious what you had to change for PyPy? (Unless it's a Py2/Py3 thing as Chris mentions.) Please take a look at the

Re: PyPy support breaking CPython compatibility?

2018-01-31 Thread Ned Batchelder
On 1/30/18 3:58 PM, Etienne Robillard wrote: Hi Ned, Le 2018-01-30 à 15:14, Ned Batchelder a écrit : I'm curious what you had to change for PyPy? (Unless it's a Py2/Py3 thing as Chris mentions.) Please take a look at the changesets: https://bitbucket.org/tkadm30/libsche

Re: Django-hotsauce 1.0 commercial edition looking for beta testers!

2018-02-13 Thread Ned Batchelder
On 2/13/18 6:41 PM, Etienne Robillard wrote: Hello everyone, Django-hotsauce 1.0 commercial edition (LTS) is now available for preorder :) Checkout: https://www.livestore.ca/product/django-hotsauce/ I'm also looking for expert Django and Python programmers to test and review the design and

Re: Python GIL vs CAS

2018-02-15 Thread Ned Batchelder
On 2/15/18 9:35 AM, Chris Angelico wrote: On Thu, Feb 15, 2018 at 2:40 PM, Oleg Korsak wrote: Hi. While hearing about GIL every time... is there any real reason why CAS doesn't help to solve this problem? https://en.wikipedia.org/wiki/Compare-and-swap Because the GIL is not a problem. It's a

Re: Are the critiques in "All the things I hate about Python" valid?

2018-02-18 Thread Ned Batchelder
On 2/18/18 6:33 AM, bartc wrote: On 18/02/2018 01:39, Chris Angelico wrote: On Sun, Feb 18, 2018 at 12:31 PM, bartc wrote: On 18/02/2018 00:45, Chris Angelico wrote: On Sun, Feb 18, 2018 at 11:13 AM, bartc wrote: It's text, but it is an intermediate or "object" file. It's not doing poin

Re: Are the critiques in "All the things I hate about Python" valid?

2018-02-18 Thread Ned Batchelder
On 2/18/18 6:57 AM, bartc wrote: On 18/02/2018 11:45, Ned Batchelder wrote: Let's not go down this path yet again. We've heard it all before. Bart: stop it.  Everyone else: stop it. :) Well, this was a rare instance of someone admitting that a simple and smaller codebase has b

Re: Are the critiques in "All the things I hate about Python" valid?

2018-02-19 Thread Ned Batchelder
On 2/19/18 9:54 AM, Steven D'Aprano wrote: On Mon, 19 Feb 2018 13:28:26 +, Paul Moore wrote: [1] The most basic question, which people making such claims often can't answer, is "Do you mean that values are strongly typed, or that names are? Or did you mean that variables are, because if so

Re: Are the critiques in "All the things I hate about Python" valid?

2018-02-19 Thread Ned Batchelder
On 2/19/18 10:39 AM, Paul Moore wrote: On 19 February 2018 at 15:18, Ned Batchelder wrote: On 2/19/18 9:54 AM, Steven D'Aprano wrote: On Mon, 19 Feb 2018 13:28:26 +, Paul Moore wrote: [1] The most basic question, which people making such claims often can't answer, is "D

Re: Are the critiques in "All the things I hate about Python" valid?

2018-02-19 Thread Ned Batchelder
On 2/19/18 1:01 PM, Paul Moore wrote: On 19 February 2018 at 17:11, Ned Batchelder wrote: On 2/19/18 10:39 AM, Paul Moore wrote: I'm curious - How would you explain Python's "variables" to someone who knows how C variables work, in a way that ensures they don't car

Re: Are the critiques in "All the things I hate about Python" valid?

2018-02-20 Thread Ned Batchelder
On 2/20/18 5:47 AM, Antoon Pardon wrote: On 19-02-18 16:18, Ned Batchelder wrote: On 2/19/18 9:54 AM, Steven D'Aprano wrote: On Mon, 19 Feb 2018 13:28:26 +, Paul Moore wrote: [1] The most basic question, which people making such claims often can't answer, is "Do you mean

Re: How to make Python run as fast (or faster) than Julia

2018-02-22 Thread Ned Batchelder
On 2/22/18 11:00 AM, bartc wrote: On 22/02/2018 12:03, bartc wrote: On the fib(20) test, it suggests using this to get a 30,000 times speed-up: BTW while doing my tests, I found you could redefine the same function with no error: def fred(): pass def fred(): pass def fred():

Re: How to make Python run as fast (or faster) than Julia

2018-02-23 Thread Ned Batchelder
On 2/23/18 3:02 PM, bartc wrote: On 23/02/2018 19:47, Chris Angelico wrote: On Sat, Feb 24, 2018 at 6:25 AM, bartc wrote: The difference between Python and another dynamic language might be a magnitude, yet you say it doesn't matter. Thanks, that makes me feel much better about my own work!

Re: How to only get \n for newline without the single quotes?

2018-02-24 Thread Ned Batchelder
On 2/24/18 2:08 PM, Peng Yu wrote: On Sat, Feb 24, 2018 at 12:45 PM, Wildman via Python-list wrote: On Sat, 24 Feb 2018 11:41:32 -0600, Peng Yu wrote: I would like to just get the escaped string without the single quotes. Is there a way to do so? Thanks. x='\n' print repr(x) '\n' Python 3

Re: How to make Python run as fast (or faster) than Julia

2018-02-26 Thread Ned Batchelder
On 2/26/18 7:13 AM, bartc wrote: On 26/02/2018 11:40, Chris Angelico wrote: On Mon, Feb 26, 2018 at 10:13 PM, bartc wrote: Below is the first draft of a Python port of a program to do with random numbers. (Ported from my language, which in turned ported it from a C program by George Marsaglia

Re: How to make Python run as fast (or faster) than Julia

2018-02-26 Thread Ned Batchelder
On 2/26/18 10:09 AM, Chris Angelico wrote: On Tue, Feb 27, 2018 at 2:02 AM, bartc wrote: On 26/02/2018 14:04, bartc wrote: On 26/02/2018 13:42, Ned Batchelder wrote: Well, once you notice that the Python code had N=1e5, and the C code had N=1e9 :) If you want to experiment, with N

Re: Questions about `locals` builtin

2018-02-27 Thread Ned Batchelder
On 2/27/18 3:52 AM, Kirill Balunov wrote: a. Is this restriction for locals desirable in the implementation of CPython in Python 3? b. Or is it the result of temporary fixes for Python 2? My understanding is that the behavior of locals() is determined mostly by what is convenient for the imp

Re: Detection of ultrasonic side channels in mobile devices with Python?

2018-02-28 Thread Ned Batchelder
On 2/28/18 4:13 PM, Etienne Robillard wrote: I want to know why this question is being silently ignored by this group. If no one has any information about your topic, then no one will say anything.  Python on Android is very specialized as it is, and I have no idea what ultrasonic side channe

Re: Detection of ultrasonic side channels in mobile devices with Python?

2018-02-28 Thread Ned Batchelder
On 2/28/18 7:01 PM, Etienne Robillard wrote:  What do rats find rewarding in play fighting? This is well outside the topics for this list. --Ned. Le 2018-02-28 à 18:29, Chris Angelico a écrit : On Thu, Mar 1, 2018 at 10:23 AM, Steven D'Aprano wrote: I'd go further... what gave you the i

Re: Functions unnecessarily called in Python/pylifecycle.c:_Py_InitializeCore() ?

2018-03-01 Thread Ned Batchelder
On 3/1/18 7:40 AM, Thomas Nyberg wrote: On 03/01/2018 12:46 PM, bartc wrote: If they're only called once, then it probably doesn't matter too much in terms of harming performance. Oh yeah there's no way this has any affect on performance. A smart compiler might even be able optimize the call aw

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Ned Batchelder
On 3/2/18 10:36 AM, Paul Moore wrote: Or (real Python): def fn(): for i in range(1): with open(f"file{i}.txt", "w") as f: f.write("Some text") How would you write this in your RAII style - without leaving 10,000 file descriptors open until the end

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-03 Thread Ned Batchelder
On 2/28/18 6:53 PM, ooom...@gmail.com wrote: On Wednesday, February 28, 2018 at 11:45:24 PM UTC, ooo...@gmail.com wrote: On Wednesday, February 28, 2018 at 11:02:17 PM UTC, Chris Angelico wrote: On Thu, Mar 1, 2018 at 9:51 AM, ooomzay wrote: [snip] Taking a really simple situation: class Foo:

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Ned Batchelder
On 3/4/18 8:26 AM, Ooomzay wrote: On Sunday, 4 March 2018 03:16:31 UTC, Paul Rubin wrote: Chris Angelico writes: Yep, cool. Now do that with all of your smart pointers being on the heap too. You are not allowed to use ANY stack objects. ANY. Got it? That's both overconstraining and not even

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Ned Batchelder
On 3/4/18 7:37 AM, Ooomzay wrote: On Sunday, 4 March 2018 04:23:07 UTC, Steven D'Aprano wrote: [...] [This PEP] imposes enormous burdens on the maintainers of at least five interpreters (CPython, Stackless, Jython, IronPython, PyPy) all of which will need to be re-written to have RAII semantics

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Ned Batchelder
On 3/4/18 9:11 AM, Ooomzay wrote: I am well aware of what it will mean for interpreters. For some interpreters it will have zero impact (e.g. CPython) ... There's no point continuing this if you are just going to insist on falsehoods like this.  CPython doesn't currently do what you want, but

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-04 Thread Ned Batchelder
On 3/4/18 5:25 PM, Ooomzay wrote: On Sunday, 4 March 2018 14:37:30 UTC, Ned Batchelder wrote: Are you including cyclic references in your assertion that CPython behaves as you want? Yes. Because the only behaviour required for RAII is to detect and debug such cycles in order to eliminate

Re: New Python implementation

2021-02-13 Thread Ned Batchelder
On Saturday, February 13, 2021 at 7:19:58 PM UTC-5, Chris Angelico wrote: > On Sun, Feb 14, 2021 at 11:14 AM Mr Flibble > wrote: > > > > On 13/02/2021 23:30, Igor Korot wrote: > > > Hi, > > > But most importantly - what is the reason for this ? > > > I mean - what problems the actual python

Re: Change first occurrence of character x in a string - how?

2021-02-14 Thread Ned Batchelder
with_at = with_dots.replace(".", "@", 1) https://docs.python.org/3/library/stdtypes.html#str.replace --Ned. On Sunday, February 14, 2021 at 4:18:22 PM UTC-5, Chris Green wrote: > What's the easiest way to change the first occurrence of a specified > character in a string? > > E.g. I want to c

Re: Dynamically import specific names from a module vs importing full module

2016-08-22 Thread Ned Batchelder
On Monday, August 22, 2016 at 4:22:09 PM UTC-4, Malcolm Greene wrote: > Python 3.5: Is there a way to dynamically import specific names from a > module vs importing the full module? > > By dynamic I mean via some form of importlib machinery, eg. I'm looking > for the dynamic "from import " equiva

Re: Is duck-typing misnamed?

2016-08-27 Thread Ned Batchelder
On Saturday, August 27, 2016 at 5:50:30 AM UTC-4, ROGER GRAYDON CHRISTMAN wrote: > "If it walks like a duck, quacks like a duck,... " > > so there is indeed precedence for this so-called 'duck typing' > > > but wouldn't it be more Pythonic to call this 'witch typing'? > > "How do you know sh

Re: Extend unicodedata with a name/pattern/regex search for character entity references?

2016-09-04 Thread Ned Batchelder
On Saturday, September 3, 2016 at 7:55:48 AM UTC-4, Veek. M wrote: > https://mail.python.org/pipermail//python-ideas/2014-October/029630.htm > > Wanted to know if the above link idea, had been implemented and if > there's a module that accepts a pattern like 'cap' and give you all the > instance

Re: Extend unicodedata with a name/pattern/regex search for character entity references?

2016-09-04 Thread Ned Batchelder
On Sunday, September 4, 2016 at 7:52:44 PM UTC-4, Chris Angelico wrote: > FWIW, hex is much more common for displaying Unicode codepoints than > decimal is. So I'd print it like this (incorporating the 'not CAPITAL' > filter): You are right, I went too quickly, and didn't realize until after I pos

Re: Extend unicodedata with a name/pattern/regex search for character entity references?

2016-09-05 Thread Ned Batchelder
On Monday, September 5, 2016 at 2:15:58 AM UTC-4, Thomas 'PointedEars' Lahn wrote: > How can I trust a person > who does not even have the decency and the courage to stand by their > statements with their real name? Feel free to ignore people you don't trust. We'll help them. --Ned. -- https

Re: dictionary total sum

2016-09-07 Thread Ned Batchelder
On Wednesday, September 7, 2016 at 8:25:42 PM UTC-4, p...@blacktoli.com wrote: > Hello, > > any ideas why this does not work? > > >>> def add(key, num): > ... a[key] += num > ... > >>> a={} > >>> a["007-12"] = 22 if not a.has_key("007-12") else add("007-12",22) > >>> a > {'007-12': 22} # OK h

Re: How to extend a tuple of tuples?

2016-09-09 Thread Ned Batchelder
On Friday, September 9, 2016 at 6:13:37 AM UTC-4, Frank Millman wrote: > "Frank Millman" wrote in message news:nqtlue$unj$1...@blaine.gmane.org... > > > Assume you have a tuple of tuples - > > > a = ((1, 2), (3, 4)) > > > You want to add a new tuple to it, so that it becomes - > > > ((1,

Re: Expression can be simplified on list

2016-09-12 Thread Ned Batchelder
On Monday, September 12, 2016 at 5:21:51 PM UTC-4, Thomas 'PointedEars' Lahn wrote: > Chris Angelico wrote: > > > On Mon, Sep 12, 2016 at 9:14 PM, Daiyue Weng wrote: > > If you know that 'errors' is always going to be a list, you can check > > for emptiness thus: > > > > if not errors: > > If

Re: How to extend a tuple of tuples?

2016-09-12 Thread Ned Batchelder
On Monday, September 12, 2016 at 4:31:37 PM UTC-4, Thomas 'PointedEars' Lahn wrote: > Ben Finney wrote: > > So instead, you want a different tuple. You do that by creating it, > > explicitly constructing a new sequence with the items you want:: > > > > b = tuple([ > > item for ite

Re: Global variable is undefined at the module level

2016-09-13 Thread Ned Batchelder
On Tuesday, September 13, 2016 at 6:42:56 AM UTC-4, Daiyue Weng wrote: > Hi, I defined a global variable in some function like this, > > def some_function(self): > > global global_var > > PyCharm inspection gave me, > > Global variable is undefined at the module level > > How to fix this?

Re: Expression can be simplified on list

2016-09-14 Thread Ned Batchelder
On Wednesday, September 14, 2016 at 5:00:02 PM UTC-4, Lawrence D’Oliveiro wrote: > On Thursday, September 15, 2016 at 8:13:05 AM UTC+12, Terry Reedy wrote: > > Because True is the default, object need not and at least in CPython > > does not have a __bool__ (or __len__) method. > > If they had to

Re: How to get the source code of python function being decorated?

2016-09-16 Thread Ned Batchelder
On Friday, September 16, 2016 at 3:20:15 PM UTC-4, Peng Yu wrote: > Hi, See the following example, I am not able to get the source code of > the actual function that does the calculation of partial_ratio. Does > anybody know what is the correct way of getting the source? > > /tmp$ ./main.py >

Re: Is there something similar to `set -v` of bash in python

2016-09-17 Thread Ned Batchelder
On Saturday, September 17, 2016 at 2:37:42 AM UTC-4, Steve D'Aprano wrote: > On Sat, 17 Sep 2016 12:31 pm, Peng Yu wrote: > > > Hi, `set -v` in bash allows the print of the command before print the > > output of the command. > > > > I want to do the similar thing --- print a python command and th

Re: Is there something similar to `set -v` of bash in python

2016-09-17 Thread Ned Batchelder
On Saturday, September 17, 2016 at 4:41:32 PM UTC-4, Peng Yu wrote: > > python -m trace -t yourprogram.py > > If I want to add some command in yourprogram.py to show the commands > used it instead of calling trace from the command line, can it be > done? I don't know of a way to do that, but

Re: Is there something similar to `set -v` of bash in python

2016-09-18 Thread Ned Batchelder
On Saturday, September 17, 2016 at 11:09:04 PM UTC-4, Peng Yu wrote: > The manual says the following. > > "The trace function is invoked (with event set to 'call') whenever a > new local scope is entered; it should return a reference to a local > trace function to be used that scope, or None if th

Re: Is there something similar to `set -v` of bash in python

2016-09-18 Thread Ned Batchelder
On Sunday, September 18, 2016 at 8:29:38 AM UTC-4, Peng Yu wrote: > On Sunday, September 18, 2016, Ned Batchelder wrote: > > > On Saturday, September 17, 2016 at 11:09:04 PM UTC-4, Peng Yu wrote: > > > The manual says the following. > > > > > > "The

Re: how to automate java application in window using python

2016-09-18 Thread Ned Batchelder
On Sunday, September 18, 2016 at 6:45:32 PM UTC-4, Lawrence D’Oliveiro wrote: > A CLI gives the user power over the computer. While a GUI is a great way to > give the computer, and proprietary software companies, power over the user. This is completely beside the point of the original question.

Re: how to automate java application in window using python

2016-09-19 Thread Ned Batchelder
On Monday, September 19, 2016 at 4:24:31 PM UTC-4, Lawrence D’Oliveiro wrote: > On Monday, September 19, 2016 at 11:29:24 AM UTC+12, Ned Batchelder wrote: > > > > On Sunday, September 18, 2016 at 6:45:32 PM UTC-4, Lawrence D’Oliveiro > > wrote: > >> > >&

Re: Linear Time Tree Traversal Generator

2016-09-21 Thread Ned Batchelder
On Tuesday, September 20, 2016 at 12:48:55 PM UTC-4, ROGER GRAYDON CHRISTMAN wrote: > I am trying to find a better (i.e. more efficient) way to implement a > generator > that traverses a tree. > > The current model of the code (which is also used by a textbook I am teaching > from does this) >

Re: strings and ints consistency - isinstance

2016-09-21 Thread Ned Batchelder
On Wednesday, September 21, 2016 at 10:27:15 AM UTC-4, Sayth Renshaw wrote: > Hi > > Trying to clarify why ints and strings arent treated the same. > > You can get a valuerror from trying to cast a non-int to an int as in > int(3.0) however you cannot do a non string with str(a). > > Which mean

Re: strings and ints consistency - isinstance

2016-09-22 Thread Ned Batchelder
On Wednesday, September 21, 2016 at 11:41:42 PM UTC-4, Sayth Renshaw wrote: > This ends being the code I can use to get it to work, seems clear and > pythonic, open to opinion on that :-) > > > answer = input("\t >> ") > if isinstance(int(answer), int) is True: > raise ValueError("Ints aren'

Re: PyImport_AddModule vs PyImport_Import

2016-09-27 Thread Ned Batchelder
On Tuesday, September 27, 2016 at 3:54:01 AM UTC-4, dl l wrote: > What is the difference between PyImport_AddModule and PyImport_Import? > > When need to use PyImport_AddModule? > > When need to use PyImport_Import? Does this paragraph from the docs help? > Note > > This function does not load

Re: how to automate java application in window using python

2016-09-29 Thread Ned Batchelder
On Wednesday, September 28, 2016 at 8:00:09 PM UTC-4, Lawrence D’Oliveiro wrote: > On Thursday, September 29, 2016 at 11:54:46 AM UTC+13, Emile van Sebille > wrote: > > Which worked for me! You should try it. Sloppy programming has always > > been unreliable. > > So it is clear you don’t have an

Re: What is a mechanism equivalent to "trace variable w ..." in Tcl for Python?

2016-09-30 Thread Ned Batchelder
On Friday, September 30, 2016 at 2:16:10 PM UTC-4, Les Cargill wrote: > A really interesting design approach in Tcl is to install a callback > when a variable is written to. This affords highly event-driven > programming. > > Example ( sorry; it's Tcl ) : > > (I can't read Tcl, sorry) > > W

Re: Byte code descriptions somewhere?

2016-10-01 Thread Ned Batchelder
On Saturday, October 1, 2016 at 7:48:09 PM UTC-4, Cem Karan wrote: > Cool, thank you! Quick experimentation suggests that I don't need to worry > about marking anything for garbage collection, correct? The next question > is, how do I create a stream of byte codes that can be interpreted by CPy

Re: ConfigParser: use newline in INI file

2016-10-01 Thread Ned Batchelder
On Saturday, October 1, 2016 at 6:25:16 PM UTC-4, Thorsten Kampe wrote: > * Ben Finney (Sun, 02 Oct 2016 07:12:46 +1100) > > > > Thorsten Kampe writes: > > > > > ConfigParser escapes `\n` in ini values as `\\n`. > > Indenting solves the problem. I'd rather keep it one line per value > but it s

Re: Merecurial and Python-2.7.x, Python-3.Y

2016-10-02 Thread Ned Batchelder
On Saturday, October 1, 2016 at 9:25:57 PM UTC-4, Michael Felt wrote: > Finally, I got to where I understood what needed to be done to get both > Mercurial built - and the the new SSL requirements met. > > So, running: > > # hg clone https://hg.python.org/cpython > > works. What is the next ste

Re: Doubled backslashes in Windows paths

2016-10-07 Thread Ned Batchelder
On Friday, October 7, 2016 at 8:39:55 AM UTC-4, BartC wrote: > On 07/10/2016 06:30, Oz-in-DFW wrote: > > I'm using Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC > > v.1900 32 bit (Intel)] on Windows 7 > > > > I'm trying to write some file processing that looks at file size, > > ext

Re: Different behaviour of regexp in 3.6.0b2

2016-10-14 Thread Ned Batchelder
On Friday, October 14, 2016 at 12:50:44 PM UTC-4, Lele Gaifax wrote: > Chris Angelico writes: > > > There's a shift as of 3.6 to make unrecognized alphabetic escapes into > > errors, or at least warnings. > > But we are talking about raw strings here, specifically r'\s+'. > > I agree that with

Re: Different behaviour of regexp in 3.6.0b2

2016-10-14 Thread Ned Batchelder
On Friday, October 14, 2016 at 1:00:12 PM UTC-4, Chris Angelico wrote: > On Sat, Oct 15, 2016 at 3:45 AM, Lele Gaifax wrote: > > Chris Angelico writes: > > > >> There's a shift as of 3.6 to make unrecognized alphabetic escapes into > >> errors, or at least warnings. > > > > But we are talking abo

Re: Different behaviour of regexp in 3.6.0b2

2016-10-14 Thread Ned Batchelder
On Friday, October 14, 2016 at 1:27:09 PM UTC-4, Chris Angelico wrote: > On Sat, Oct 15, 2016 at 4:12 AM, Ned Batchelder > wrote: > > There doesn't seem to be a change to string literals at all. It's only a > > change in the regex engine. > > > > Pyt

Re: How to sort this without 'cmp=' in python 3?

2016-10-14 Thread Ned Batchelder
On Friday, October 14, 2016 at 7:49:33 PM UTC-4, Robin Koch wrote: > Am 15.10.2016 um 01:33 schrieb 38016226...@gmail.com: > > nums=['3','30','34','32','9','5'] > > I need to sort the list in order to get the largest number string: > > '953433230' > > > > nums.sort(cmp=lambda a,b: cmp(a+b, b+a), r

Re: Build desktop application using django

2016-10-17 Thread Ned Batchelder
On Sunday, October 16, 2016 at 10:53:45 PM UTC-4, Mario R. Osorio wrote: > On Sunday, October 16, 2016 at 1:42:23 PM UTC-4, Ayush Saluja wrote: > > Hello I want to build a desktop application which retrieves data from > > server and stores data on server. I have basic experience of python and I >

Re: Sphinx + autodoc + apidoc

2016-10-24 Thread Ned Batchelder
On Monday, October 24, 2016 at 5:00:47 PM UTC-4, Dan Stromberg wrote: > Hi folks. > > I'm attempting to set up Sphinx to document several API's based on docstrings. > > I've got something browseable for one example API using Sphinx + > autodoc + apidoc. > > However, we aren't really a PEP8 shop;

Re: Sphinx + autodoc + apidoc

2016-10-24 Thread Ned Batchelder
On Monday, October 24, 2016 at 7:02:11 PM UTC-4, Dan Stromberg wrote: > On Mon, Oct 24, 2016 at 2:39 PM, Ned Batchelder > wrote: > > On Monday, October 24, 2016 at 5:00:47 PM UTC-4, Dan Stromberg wrote: > > >> However, we aren't really a PEP8 shop; we use hard ta

Re: Pre-pep discussion material: in-place equivalents to map and filter

2016-11-03 Thread Ned Batchelder
On Thursday, November 3, 2016 at 4:30:00 AM UTC-4, Steven D'Aprano wrote: > On Thursday 03 November 2016 17:56, arthurhavli...@gmail.com wrote: > > I would propose this syntax. (TODO: find appropriate keywords I guess): > > > > lst.map x: x*5 > > lst.filter x: x%3 == 1 > > I think the chances of

Re: help on "from deen import *" vs. "import deen"

2016-11-14 Thread Ned Batchelder
On Sunday, November 13, 2016 at 9:39:12 PM UTC-5, jf...@ms4.hinet.net wrote: > Running the following codes (deen.py) under Win32 python 3.4.4 terminal: > > tbli = [0x66, 0x27, 0xD0] > tblm = [0 for x in range(3)] > def gpa(data): > td = data ^ tblm[2] > return td The function gpa referenc

Re: how to control formatting of a namedtuple in a list

2016-11-17 Thread Ned Batchelder
On Thursday, November 17, 2016 at 6:50:07 PM UTC-5, Boylan, Ross wrote: > Thank you; I can confirm that overriding __repr__ makes the list display as I > wanted. > > The decision to use repr inside the list seems very odd, given the context, > namely formatting something for display or looking f

Re: What exactly is a python variable?

2016-11-17 Thread Ned Batchelder
On Thursday, November 17, 2016 at 8:35:15 PM UTC-5, BartC wrote: > That Py2's dis.dis() accepts a string argument but treats it as compiled > byte-code sounds like a bug. Unless it's a feature. In Python 2, plain-old strings are byte-strings, so there's no way for dis.dis to distinguish between a

Re: Guido? Where are you?

2016-11-20 Thread Ned Batchelder
On Sunday, November 20, 2016 at 7:24:43 AM UTC-5, Tristan B. Kildaire wrote: > Is Guido active on this newsgroup. Sorry for the off-topic ness. He is definitely not active on this list. The most recent message from him here (not cross-posted) seems to be in September 2014. Maybe there's something

Re: help on "from deen import *" vs. "import deen"

2016-11-20 Thread Ned Batchelder
On Sunday, November 20, 2016 at 6:47:35 AM UTC-5, Bev in TX wrote: > From the Python 3.5.2 docs: > > 6.15. Evaluation order > Python evaluates expressions from left to right. Notice that while > evaluating an assignment, the right-hand side is evaluated before the > left-hand side. > > Thus, sp

Re: Which of two variants of code is better?

2016-11-21 Thread Ned Batchelder
On Monday, November 21, 2016 at 12:48:25 PM UTC-5, Victor Porton wrote: > Which of two variants of code to construct an "issue comment" object (about > BitBucket issue comments) is better? > > 1. > > obj = IssueComment(Issue(IssueGroup(repository, 'issues'), id1), id2) > > or > > 2. > > list

Re: How to you convert list of tuples to string

2016-11-23 Thread Ned Batchelder
On Wednesday, November 23, 2016 at 3:43:05 AM UTC-5, Larry Hudson wrote: > On 11/22/2016 08:51 AM, Michiel Overtoom wrote: > > Hi Ganesh, > > > >> Any better suggestion to improve this piece of code and make it look more > >> pythonic? > > > > > > import random > > > > # A list of tuples. Note tha

Re: Immutability of Floats, Ints and Strings in Python

2016-11-25 Thread Ned Batchelder
On Friday, November 25, 2016 at 6:24:47 AM UTC-5, Nikunj wrote: > Hi All, > > Out of curiosity, I wanted to understand the reason behind having different > memory location for two identical floats . This is unlike ints or strings. > Tried googling but couldn't find anything concrete. Any links o

Re: Immutability of Floats, Ints and Strings in Python

2016-11-25 Thread Ned Batchelder
On Friday, November 25, 2016 at 6:34:00 AM UTC-5, Ned Batchelder wrote: > On Friday, November 25, 2016 at 6:24:47 AM UTC-5, Nikunj wrote: > > Hi All, > > > > Out of curiosity, I wanted to understand the reason behind having different > > memory location for two identi

Re: Immutability of Floats, Ints and Strings in Python

2016-11-25 Thread Ned Batchelder
On Friday, November 25, 2016 at 7:17:08 AM UTC-5, BartC wrote: > On 25/11/2016 11:24, Nikunj wrote: > > > > Out of curiosity, I wanted to understand the reason behind having different > > memory location for two identical floats . This is unlike ints or strings. > > Tried googling but couldn't fi

Re: A Rebuttal For Python 3

2016-11-25 Thread Ned Batchelder
On Friday, November 25, 2016 at 3:45:37 AM UTC-5, Rustom Mody wrote: > On Friday, November 25, 2016 at 1:27:18 AM UTC+5:30, bream...@gmail.com wrote: > > https://eev.ee/blog/2016/11/23/a-rebuttal-for-python-3/ is one of > > presumably many responses to the article I posted about under the subject

Re: A Rebuttal For Python 3

2016-11-25 Thread Ned Batchelder
On Friday, November 25, 2016 at 11:26:09 AM UTC-5, Ned Batchelder wrote: > > --Ned. > against Python 3 is Umm, no idea where that "signature" came from... I am not against Python 3... :) -- https://mail.python.org/mailman/listinfo/python-list

Re: dictionary mutability, hashability, __eq__, __hash__

2016-11-27 Thread Ned Batchelder
On Sunday, November 27, 2016 at 4:53:20 AM UTC-5, Veek M wrote: > I was reading this: > http://stackoverflow.com/questions/4418741/im-able-to-use-a-mutable-object-as-a-dictionary-key-in-python-is-this-not-disa > > In a User Defined Type, one can provide __hash__ that returns a integer > as a key

Re: The Case Against Python 3

2016-12-01 Thread Ned Batchelder
On Thursday, December 1, 2016 at 9:03:46 AM UTC-5, Paul Moore wrote: > While I agree that f-strings are more dangerous than people will immediately > realise (the mere fact that we call them f-*strings* when they definitely > aren't strings is an example of that), the problem here is clearly (IM

Re: correct way to catch exception with Python 'with' statement

2016-12-01 Thread Ned Batchelder
On Thursday, December 1, 2016 at 2:31:11 PM UTC-5, DFS wrote: > After a simple test below, I submit that the above scenario would never > occur. Ever. The time gap between checking for the file's existence > and then trying to open it is far too short for another process to sneak > in and dele

Re: correct way to catch exception with Python 'with' statement

2016-12-01 Thread Ned Batchelder
On Thursday, December 1, 2016 at 7:26:18 PM UTC-5, DFS wrote: > On 12/01/2016 06:48 PM, Ned Batchelder wrote: > > On Thursday, December 1, 2016 at 2:31:11 PM UTC-5, DFS wrote: > >> After a simple test below, I submit that the above scenario would never > >> occur.

Re: sets anomaly

2016-12-07 Thread Ned Batchelder
On Wednesday, December 7, 2016 at 10:18:32 AM UTC-5, Rustom Mody wrote: > Trying to write some code using sets (well frozen sets) > And was hit by this anomaly > > This is the behavior of lists I analogously expect in sets: > > >>> [] > [] > >>> [[]] > [[]] > >>> > > ie the empty list and the l

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Ned Batchelder
On Monday, December 12, 2016 at 12:58:30 PM UTC-5, Juan C. wrote: > Since we are talking about Python terminology I believe that calling > `__init__` a constructor is also wrong. I've already seem some > discussions regarding it and the general consensus is that `__init__` > shouldn't be called con

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Ned Batchelder
On Monday, December 12, 2016 at 4:31:00 PM UTC-5, Gregory Ewing wrote: > Ned Batchelder wrote: > > In C++, you don't have an object of type T until the > > constructor has finished. In Python, you have an object of type T before > > __init__ has been entered. > &

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Ned Batchelder
On Monday, December 12, 2016 at 6:17:43 PM UTC-5, Ben Finney wrote: > Ned Batchelder writes: > > > Claiming that __init__ isn't a constructor seems overly pedantic to > > me. > > Whereas to me, claiming that ‘Foo.__init__’ is a constructor seems > needlessly con

Re: Wrong release date in 3.6 whats new docs?

2016-12-14 Thread Ned Batchelder
On Wednesday, December 14, 2016 at 9:09:22 AM UTC-5, Nick Sarbicki wrote: > Afternoon everyone. > > Might be missing something obvious but the 3.6 What's New docs point to the > release date being the 12th. > > https://docs.python.org/3.6/whatsnew/3.6.html#what-s-new-in-python-3-6 > > I got the

Re: python list index - an easy question

2016-12-19 Thread Ned Batchelder
On Sunday, December 18, 2016 at 11:21:38 AM UTC-5, BartC wrote: > On 18/12/2016 10:59, Paul Götze wrote: > > Hi John, > > > > there is a nice short article by E. W. Dijkstra about why it makes sense > > to start numbering at zero (and exclude the upper given bound) while > > slicing a list. Might g

<    1   2   3   4   5   6   7   8   9   >