Re: Recursive method in class

2019-10-01 Thread ast

Le 30/09/2019 à 13:11, Anders Märak Leffler a écrit :

What do you mean by transformed? This is probably your understanding
already, but a further consequence of when arguments are evaluated
plus what you said about data attributes is that the fib(self, n - 1)
call will follow the standard LEGB-lookup of whatever "fib" is, from
the point of view of the function object. As far as I know, there is
no transformation of these scopes - either when it comes to creating
the class, or creating the instances. (self is just the instance,
passed as an argument.)

Cf when you change a binding:


def factorial(self, n):

... if not n:
... return 1
... else:
... return n * factorial(self, n - 1)
...

Dummy = type("DummyObject", (object, ), {"factorial" : factorial})
instance = Dummy()
def factorial(self, n):

... print("Hello!")
... return 999
...

instance.factorial(5)   # Where will the call go ("old" or "new" factorial?)? 
Where will possible recursive calls go (and why)?

Hello!
4995

Oh, and as others have pointed out on this list - you/whoever runs the
system sending the mail might want to change the return address.
n...@gmail.com is somewhat consistently classed as spam.



//Anders

PS. We could further complicate this by adding a call to
self.factorial in the new function, but let's not go there. :)



I understood your example, but it doesn't answer my initial question.
I try to rewrite my question:

The following code is working well and I don't really understand why

def factorial(self, n):
if not n:
return 1
else:
return n * factorial(self, n - 1)

Dummy = type("DummyObject", (object, ), {"factorial" : factorial})
instance = Dummy()
instance.factorial(3)

6  # correct

The problem is that "factorial" in line
"return n * factorial(self, n - 1)" should not have been found
because there is no factorial function defined in the current
scope.

if you use "class" keyword to define the class

class Dummy:

def factorial(self, n):
if not n:
return 1
else:
return n * factorial(self, n - 1)

instance = Dummy()
instance.factorial(3)

It generate an error because "factorial" in line
"return n * factorial(self, n - 1)" is not found.

Traceback (most recent call last):
  File "", line 1, in 
instance.factorial(3)
  File "", line 7, in factorial
return n * factorial(self, n - 1)
NameError: name 'factorial' is not defined

This is OK to me

The correct way is to write:

class Dummy:

def factorial(self, n):
if not n:
return 1
else:
return n * self.factorial(n - 1)

instance = Dummy()
instance.factorial(3)

6 # correct

So, to summarize, if you create a class with type(name, bases, dict_)
or with the "class" keyword, recursive methods can't be writen
in the same way. This is what puzzle me.

--
https://mail.python.org/mailman/listinfo/python-list


Re: pathlib

2019-10-01 Thread Chris Angelico
On Tue, Oct 1, 2019 at 3:26 PM DL Neil via Python-list
 wrote:
>
> On 1/10/19 1:09 AM, Chris Angelico wrote:
> > I don't think it represents the actual file. If it did, equality would
> > be defined by samefile, NOT by the file name.
> >
>  from pathlib import Path
>  import os
>  open("file1", "w").close()
>  os.link("file1", "file2")
>  Path("file1") == Path("file2")
> > False
>  Path("file1").samefile(Path("file2"))
> > True
>  Path("file1") == Path("file1")
> > True
>
>  >>> f1 = pathlib.Path( "file1" )
>  >>> f2 = pathlib.Path( "file2" )
>  >>> f1 == f2
> False
> ### they are not the same path (by name) - due only to the last character

Correct. The paths are not equal, regardless of whether they represent
the same file.

> Let's try something similar, but the other-way-around:
>
>  >>> f1 = pathlib.Path( "file1" )
>  >>> f1.stat()
> os.stat_result(st_mode=33204, st_ino=1049466, st_dev=64769, st_nlink=1,
> st_uid=1000, st_gid=1000, st_size=0, st_atime=1569903409,
> st_mtime=1569903409, st_ctime=1569903851)
> ### this path exists in the FS
>
>  >>> f1.rename( f2 )
> ### here's a rename operation per the manual!
>  >>> f2.stat()
> os.stat_result(st_mode=33204, st_ino=1049466, st_dev=64769, st_nlink=1,
> st_uid=1000, st_gid=1000, st_size=0, st_atime=1569903409,
> st_mtime=1569903409, st_ctime=1569904293)
> ### f2 is a path which represents a real-world file though
> ### where have we seen those numbers before?

And as you see, f2 now points to that file. So the Path objects
haven't changed, but the underlying file has moved from one to the
other.

The Path does not represent the file; it represents one means of locating it.

One thing that might be nice - although it'd probably be a nightmare
to try to work with across platforms - would be a Path that, rather
than being either absolute (anchored at the root) or relative to the
current directory (not anchored), is relative to a specific other
directory. It'd be described something like "<142857>/path/to/file"
and would reference an open FD. That would give a Path power that a
normal string doesn't have - the power to combine both the arguments
of openat.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pathlib

2019-10-01 Thread Chris Angelico
On Tue, Oct 1, 2019 at 3:05 PM DL Neil via Python-list
 wrote:
> BUT... Path() does keep track of changes in the file system for other
> attributes! So, why not also name?

Does it actually track changes?

> Here's a code-snippet illustrating both of the above points:
>
> import pathlib
> p = pathlib.Path( "data-file" )
> p
> # PosixPath('data-file')
> p.stat()
> os.stat_result(... st_mtime=1569898467, st_ctime=1569898467)
> # ... = excised results, leaving two data-points worth observing
>
> with p.open("w") as f:
>  f.write("new stuff")
> # 9
>
> p.stat()
> os.stat_result(... st_mtime=1569898572, st_ctime=1569898572)
> # hey look, this reflects REAL and CHANGED data from the FS

This is a method. And it is implemented with an actual call to the OS.

$ strace python3 -c 'from pathlib import Path; p =
Path("asdfasdf.py"); print("1"); p.stat();
print("22"); p.stat(); print("33")'
[ chomp tons of strace output ]
write(1, "1\n", 101
) = 10
stat("asdfasdf.py", {st_mode=S_IFREG|0644, st_size=146, ...}) = 0
write(1, "22\n", 1122
)= 11
stat("asdfasdf.py", {st_mode=S_IFREG|0644, st_size=146, ...}) = 0
write(1, "33\n", 1133
)= 11

Every time you check p.stat(), there is a system call to actually stat
the file. The Path object is not tracking anything. It is not in any
way "reflecting changes", other than the same way that a string
literal can reflect changes in the FS.

> Looking at the PEP, it didn't alleviate my confusion because:
> (a) <<<
> Why an object-oriented API
> ... form of filesystem handling abstraction
>  >>>
> (b) <<<
> Immutability
> Path objects are immutable, which makes them hashable and also prevents
> a class of programming errors.
>  >>>
> (c) <<<
> Concrete paths API
> In addition to the operations of the pure API, concrete paths provide
> additional methods which actually access the filesystem to query or
> mutate information.
>  >>>
>
> I liked the OOP aims in point (a) but it clearly says "filesystem".

Yes - a pathlib.Path is designed for a file system path, not a UUCP
bang path, not a URI path, not a yellow brick road, but a file system
path. So it clearly says this.

> Point (c) appears to suggest (as written above) that whereas the Pure
> API can be immutable and separate from any physical file system, the
> Concrete paths will perform actions and thus mutate with the real FS.

No, concrete paths are simply bound to your current FS. It doesn't
make sense, on my Linux system, to have a concrete path of
"c:/foo/bar". I *am* allowed to instantiate an abstract WindowsPath,
but it doesn't make sense to ask if that's the same file as "c:/quux",
since I don't have a file system.

I think you're assuming far too much from the word "concrete". It's
not tracking an actual file. It's still just a path - it just now has
some methods attached to it.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Announcing colour-text and colour-print

2019-10-01 Thread Gisle Vanem

Barry Scott wrote:


Here is an example:

from colour_text import ColourText
ct = ColourText()
ct.initTerminal()

print( ct( "The next section is in green: <>green example<>." ) )


Looking at the sources, it seems 'win32' should be
supported. But no; with the above example:
  c:\>py -3 example.py
  The next section is in green: ←[32mexample←[m.

No colours, just the pesky SGI-codes.

BTW. it fails completely in Python 2.7.

--
--gv
--
https://mail.python.org/mailman/listinfo/python-list


Re: pathlib

2019-10-01 Thread DL Neil via Python-list

On 1/10/19 2:58 PM, Dan Sommers wrote:

On 9/30/19 3:56 PM, Barry Scott wrote:
On 30 Sep 2019, at 16:49, Dan Sommers 
<2qdxy4rzwzuui...@potatochowder.com 
> wrote:



In the totality of a Path object that claims to represent paths
to files,


It represents string that *should* in most cases work in the APIs
that work on files. Not the same idea.


I'm not sure the documentation supports your view.  Components
of paths are strings, but IMO the Path object represents a file.


Worse! There may be an argument for suggesting that the documentation 
supports both descriptions...




including the arguably troublesome read_bytes and
write_bytes methods, and a rename method, however, it's not
unreasonable expect the object to track *itself* when I use *its*
own rename method (backwards compatibility restraints
notwithstanding).


"the object" did track the changes its just that "the object" is not
the Path object, it's in the operating system and/or the file system.
For the rename it's the directory that the name is recorded in.


So which is it?  Does the Path object represent a string, the
name of a file (whether that file exists or not), or the file
itself?  A moment ago, you claimed that a Path object represents
a string that should work in the APIs that work on files.  Now,
you're claiming that the Path object is a proxy for something in
the filesystem.  I don't mean to be combative or confrontational,
but I think that this fuzziness/inconsistency is at or near the
root of the differing expectations.


Yes, see earlier comment about "confusion" - in both the minds of 
learners/newcomers and those who are 'experienced'.




There was an interest talk at this years PYCON UK about the
the errors that people new to python make. Misunderstand syntax
is about 1/3 of the problems, but 2/3 was having the wrong model.

This discussion seems to fall into the "wrong model" world that
leads to a expectation failure.


On this (that there's something about the model of Path objects
that leads to expectation failures) we agree.  :-)


Are we talking about "Here's Your Mistake" 
(https://www.youtube.com/watch?v=7gMOaWdzDSw)?


You've strayed into my research area: cognitive psychology - 
understanding how people learn. Whilst we do indeed talk about "models" 
- a person's understanding of how things work and/or how they fit together.


"Models" in the computing world are more often called "abstractions". 
Every?most computer program(mes) are, by definition, an abstraction of 
some real-world event, calculation, or whatever. A Person() class might 
have the name of a real-person, but it is definitely not that (or any 
other) person. It is an abstraction (and likely only of 'part' of that 
person). That said, if the person changes his/her name by Deed Poll 
(legal process) to "Slinky Python", then it would be insulting to use 
the previous name(s)! (and if someone has divorced and re-married, 
never, never, NEVER use the names of the original him+her when referring 
to the 'new' him+her!!!)

(PC alert: traditional pairing described)

You will observe that the original post attempts to paint a picture of 
the model I expected. Since then, several folk have taken me up on the 
request for "good reasons ... why not", and thus, as you say, enabled 
the replacement (education) of my "wrong model", with "the real thing".


From where do people acquire their models? The YouTube video briefly 
touched-on this. Most commonly: previous experience - thus math students 
write formulae as description, and can come to grief when Python code 
insists upon a sequence of instructions.


So, next time someone tells you to 'read the code' you will wonder why 
the built-in 'documentation' isn't up-to-snuff; and when someone says 
RTFM you'll also realise that you've invited the person to construct 
their own model - an error-prone process at best; and that is why, if 
one examines the rate of adoption for (open source) languages and 
libraries, the greatest influence is the presence/absence of quality 
tutorials - materials designed to encourage the building of congruent 
mental models!



In this discussion we've heard people comparing pathlib with previous 
facilities in os and sys. That's unfortunate because reading the PEP 
shows an intention to diverge.


At the same time, and again reviewing this discussion, you can observe 
two models: one more abstract ("Pure") and the other more oriented to 
reflecting the FS ("concrete"). The gap between is the importance one 
places on each of the two models. Favoring the abstract means seeing the 
Pure constructs as important and the concrete as lesser. The more 
practical view asking for a means to access the file system, sees the 
Pure model as a foundation.



Have we moved on to how we can improve the situation?


Absolutely.

Documenting the fact that calling rename on a Path object does
not update that object, and at least an acknowledgement of the
b

EuroPython 2019 - Videos for Friday available

2019-10-01 Thread M.-A. Lemburg
We are pleased to announce the third and final batch of cut videos
from EuroPython 2019 in Basel, Switzerland, with another 49 videos.

 * EuroPython 2019 on our YouTube Channel *

http://europython.tv/

In this batch, we have included all videos for Friday, July 12 2019,
the third conference day.

In total, we now have 133 videos available for you to watch.

All EuroPython videos, including the ones from previous conferences,
are available on our EuroPython YouTube Channel.


Help spread the word


Please help us spread this message by sharing it on your social
networks as widely as possible. Thank you !

Link to the blog post:

https://blog.europython.eu/post/188061778527/europython-2019-videos-for-friday-available

Tweet:

https://twitter.com/europython/status/1178961272261545984


Enjoy,
--
EuroPython 2019 Team
https://ep2019.europython.eu/
https://www.europython-society.org/

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pathlib

2019-10-01 Thread Richard Damon
On 10/1/19 1:24 AM, DL Neil via Python-list wrote:
> On 1/10/19 1:09 AM, Chris Angelico wrote:
>> On Mon, Sep 30, 2019 at 9:54 PM Dan Sommers
>> <2qdxy4rzwzuui...@potatochowder.com> wrote:
>>> I would have said the same thing, but the docs⁰ disagree:  a
>>> PurePath represents the name of (or the path to) a file, but a
>>> Path represents the actual file.
>>>
>>>
>>> ⁰ https://docs.python.org/3/library/pathlib.html
>>
>> I don't think it represents the actual file. If it did, equality would
>> be defined by samefile, NOT by the file name.
>>
> from pathlib import Path
> import os
> open("file1", "w").close()
> os.link("file1", "file2")
> Path("file1") == Path("file2")
>> False
> Path("file1").samefile(Path("file2"))
>> True
> Path("file1") == Path("file1")
>> True
>
>
> This example involves a "hard link" in Linux - can't recall if it
> applies under MS-Win...
>
> On a Linux system the 'two' files share the same inode, and thus the
> same 'patch of disk', but one can be deleted without affecting the
> other. Thus, borrowing from the above snippet: 

This is sort of like in Python we have

a = []

b = a

now a and b refer to the same list, On Linux, a file name is NOT a file,
but a reference to it. A file may have many names (or even no names
after you unlink the last name with the file still open),

You can also have a file name (aka a path) that created multiple files
that exist at the same time (create the file and keep it open, unlink or
rename the file, and you can create another with the original name).

We also have relative paths, relative paths specify a file path relative
to something, but don't keep track of that something, and as such may
truly represent multiple real files.

These show that these paths CAN'T actually represent the files,

-- 
Richard Damon

-- 
https://mail.python.org/mailman/listinfo/python-list


"Regular Expression Objects" scanner method

2019-10-01 Thread ast

Hello

I am trying to understand a program which use
a method named scanner on a re compiled object.

This program is named "Simple compiler" here:
https://www.pythonsheets.com/notes/python-generator.html

But unfortunately it is not documented

nor here:
https://docs.python.org/3.7/library/re.html#regular-expression-objects

nor with help

import re
lex = re.compile("foo")
help(lex.scanner)

Help on built-in function scanner:

scanner(string, pos=0, endpos=2147483647) method of _sre.SRE_Pattern 
instance


Does anybody know where to find a doc ?
--
https://mail.python.org/mailman/listinfo/python-list


Re: Recursive method in class

2019-10-01 Thread Terry Reedy

On 10/1/2019 3:37 AM, ast wrote:


The following code is working well and I don't really understand why

def factorial(self, n):
     if not n:
     return 1
     else:
     return n * factorial(self, n - 1)


This creates a function that looks up 'factorial' in the global (module) 
scope when called.



Dummy = type("DummyObject", (object, ), {"factorial" : factorial})


This creates a reference to the function in the class dict.  There is 
now one function object with 2 references.



instance = Dummy()
instance.factorial(3)


instance.factorial still looks up 'factorial' in the global scope, and 
finds it there.  If you delete the global reference after creating the 
class, the lookup will fail, as when





6  # correct



The problem is that "factorial" in line
"return n * factorial(self, n - 1)" should not have been found
because there is no factorial function defined in the current
scope.


Yes there is.  the 'current' scope always includes globals, and globals 
has a reference to the function.



--
Terry Jan Reedy


--
https://mail.python.org/mailman/listinfo/python-list


Re: pathlib

2019-10-01 Thread Rhodri James

On 01/10/2019 06:03, DL Neil via Python-list wrote:

On 30/09/19 9:28 PM, Barry Scott wrote:
On 30 Sep 2019, at 05:40, DL Neil via Python-list 
 wrote:


Should pathlib reflect changes it has made to the file-system?


I think it should not.


The term "concrete" is applied to Path(), PosixPath(), and WindowsPath() 
- whereas the others are differentiated with the prefix "Pure".


I take "concrete" to mean 'existing in reality or real experience'. 
Thus, I saw the Pure* entities as supporting abstract paths, but the 
concrete entities as representing (and reflecting) real-world (file 
system) entities.


Thus, there is no need for .exists() to be available in the Pure paths, 
but there is when utilising their concrete implementations.


Sorry but your logic is inconsistent here.  For starters, it's not that 
there's no need for .exists() in Pure paths, it's that .exists() is 
meaningless.  Pure paths aren't related to any actual filing system (to 
paraphrase you), so existence isn't an option.


However if you insist that "concrete" means "existing in reality", then 
.exists() is unnecessary because by your very definition the path must 
exist.  The very act of creating the Path object would create the 
corresponding file or directory.  So either pathlib does something 
horrific, or your definition is wrong.


Consider for a moment:

rhodri@scrote:~$ cat /home/rhodri/foo.txt
cat: /home/rhodri/foo.txt: No such file or directory

cat "concatenates files" to quote its man page.  Does that mean it 
creates them if they don't exist, just because I typed the name into the 
command?  No.  I wouldn't expect it either.  In exactly the same way I 
don't expect a concrete file*name* to necessarily refer to an actual file.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Recursive method in class

2019-10-01 Thread Rhodri James

On 01/10/2019 08:37, ast wrote:

I understood your example, but it doesn't answer my initial question.
I try to rewrite my question:

The following code is working well and I don't really understand why

def factorial(self, n):
     if not n:
     return 1
     else:
     return n * factorial(self, n - 1)

Dummy = type("DummyObject", (object, ), {"factorial" : factorial})
instance = Dummy()
instance.factorial(3)

6  # correct

The problem is that "factorial" in line
"return n * factorial(self, n - 1)" should not have been found
because there is no factorial function defined in the current
scope.


Not so.  "factorial" is in the global scope of your module, which is 
always available.




if you use "class" keyword to define the class

class Dummy:

     def factorial(self, n):
     if not n:
     return 1
     else:
     return n * factorial(self, n - 1)

instance = Dummy()
instance.factorial(3)

It generate an error because "factorial" in line
"return n * factorial(self, n - 1)" is not found.

Traceback (most recent call last):
   File "", line 1, in 
     instance.factorial(3)
   File "", line 7, in factorial
     return n * factorial(self, n - 1)
NameError: name 'factorial' is not defined

This is OK to me


Here, "factorial" is *not* in scope.  It's an attribute of the Dummy 
class, which is in scope, so you have to access it via Dummy (or more 
usually "self", because "self" is an instance of Dummy so has access).




The correct way is to write:

class Dummy:

     def factorial(self, n):
     if not n:
     return 1
     else:
     return n * self.factorial(n - 1)

instance = Dummy()
instance.factorial(3)

6 # correct

So, to summarize, if you create a class with type(name, bases, dict_)
or with the "class" keyword, recursive methods can't be writen
in the same way. This is what puzzle me.


On the contrary, recursive methods are written in exactly the same way. 
What you aren't getting at the moment is what scope names exist in.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


How can I set the value of the textedit box and slider of ui with the value from a config file when it has been created?

2019-10-01 Thread Spencer Du
Hi
How can I set the value of the textedit box and slider of ui with the value 
from a config file when it has been created meaning if a configuration file 
exists then set the UI with value from the config file otherwise load ui with 
nothing set to any value.
ui.py
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QSlider, QLineEdit, 
QPushButton
from PyQt5.QtCore import Qt
import myconfig
config=myconfig.Config()
import os
import configparser

ui.py

class Example(QMainWindow):

def __init__(self):
super().__init__()

self.textbox = QLineEdit(self)
self.textbox.move(20, 25)
self.textbox.resize(60,30)

button = QPushButton('Button', self)
button.setToolTip('This is an example button')
button.clicked.connect(self.printValue)
button.move(100,25)

self.mySlider = QSlider(Qt.Horizontal, self)
self.mySlider.setGeometry(30, 140, 200, 30)
self.mySlider.setMinimum(0)
self.mySlider.setMaximum(100)

# self.textbox.setText(str(config.getminValue()))
# textboxValue = self.textbox.text()
# self.mySlider.setValue(int(textboxValue) + 30)
   
self.setGeometry(50,50,320,200)
self.setWindowTitle("Checkbox Example")
self.show()

#def changeValue(self, value):
#print(value)

def printValue(self):
if not os.path.exists('445nm.ini'):
textboxValue = self.textbox.text()
print(textboxValue) 
f = open('445nm.ini', 'w+')
config = configparser.RawConfigParser()
config.add_section('445nm')
config.set('445nm', 'intensity', textboxValue)
config.write(f)
if self.textbox.text() == "":
self.mySlider.setValue(0)
else:
self.mySlider.setValue(int(textboxValue))
else:
self.mySlider.setValue(config.get('445nm', 'intensity'))

# if self.textbox.text() == "":
# self.mySlider.setValue(0)
# else:
# self.mySlider.setValue(config.get('445nm', 'intensity'))

if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())

config.py

[445nm]
intensity = 4

Thanks
Spencer
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Recursive method in class

2019-10-01 Thread ast

Le 01/10/2019 à 13:18, Rhodri James a écrit :

On 01/10/2019 08:37, ast wrote:




The problem is that "factorial" in line
"return n * factorial(self, n - 1)" should not have been found
because there is no factorial function defined in the current
scope.


Not so.  "factorial" is in the global scope of your module, which is 
always available.




yes, you rae right. It is clear now
--
https://mail.python.org/mailman/listinfo/python-list


Re: How can I set the value of the textedit box and slider of ui with the value from a config file when it has been created?

2019-10-01 Thread Michael Torrie
On 10/1/19 9:51 AM, Spencer Du wrote:
> Hi
> How can I set the value of the textedit box and slider of ui with the value 
> from a config file when it has been created meaning if a configuration file 
> exists then set the UI with value from the config file otherwise load ui with 
> nothing set to any value.

Your code appears to try to do all this in the printValue() method of
your class, however nothing calls that method.  Most likely you'd want
to move that code to the __init__() initializer.  I can't really comment
further since your code cannot be run as posted, since it imports a
"myconfig" module that is not provided.

More specific help regarding PyQt perhaps may be found at the PyQt
mailing list that Riverbank Software (the makers of PyQt) host).
-- 
https://mail.python.org/mailman/listinfo/python-list


[RELEASE] Python 3.8.0rc1 is now available

2019-10-01 Thread Łukasz Langa
Python 3.8.0 is almost ready. After a rather tumultuous few days, we are very 
happy to announce the availability of the release candidate:

https://www.python.org/downloads/release/python-380rc1/ 


This release, 3.8.0rc1, is the final planned release preview. Assuming no 
critical problems are found prior to 2019-10-14, the scheduled release date for 
3.8.0, no code changes are planned between this release candidate and the final 
release.
Please keep in mind that this is not the gold release yet and as such its use 
is not recommended for production environments.

Major new features of the 3.8 series, compared to 3.7

Some of the new major new features and changes in Python 3.8 are:

PEP 572 , Assignment expressions
PEP 570 , Positional-only arguments
PEP 587 , Python Initialization 
Configuration (improved embedding)
PEP 590 , Vectorcall: a fast calling 
protocol for CPython
PEP 578 , Runtime audit hooks
PEP 574 , Pickle protocol 5 with 
out-of-band data
Typing-related: PEP 591  (Final 
qualifier), PEP 586  (Literal types), 
and PEP 589  (TypedDict)
Parallel filesystem cache for compiled bytecode
Debug builds share ABI as release builds
f-strings support a handy = specifier for debugging
continue is now legal in finally: blocks
on Windows, the default asyncio event loop is now ProactorEventLoop
on macOS, the spawn start method is now used by default in multiprocessing
multiprocessing can now use shared memory segments to avoid pickling costs 
between processes
typed_ast is merged back to CPython
LOAD_GLOBAL is now 40% faster
pickle now uses Protocol 4 by default, improving performance
(Hey, fellow core developer, if a feature you find important is missing from 
this list, let Łukasz know .)
Call to action: focus on the docs now

Are all your changes properly documented?
Did you notice other changes you know of to have insufficient documentation?
Can you help with the “What’s New 
” document?

- Ł



signature.asc
Description: Message signed with OpenPGP
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Recursive method in class

2019-10-01 Thread Timur Tabi
Could you please fix your email software so that it shows a legitimate
email address in the From: line?  Your emails all show this:

From: ast 

All of your emails are being caught in my spam filter because of this
address.  I would email you privately, but I know n...@gmail.com isn't
your real email address.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Announcing colour-text and colour-print

2019-10-01 Thread Barry


> On 1 Oct 2019, at 10:12, Gisle Vanem  wrote:
> 
> Barry Scott wrote:
> 
>> Here is an example:
>> from colour_text import ColourText
>> ct = ColourText()
>> ct.initTerminal()
>> print( ct( "The next section is in green: <>green example<>." ) )
> 
> Looking at the sources, it seems 'win32' should be
> supported. But no; with the above example:
>  c:\>py -3 example.py
>  The next section is in green: ←[32mexample←[m.

 That are two posibility.
1. You did not call initTerminal
2. You are on an old version of windows that does not understand SGI.

Barry

> 
> No colours, just the pesky SGI-codes.
> 
> BTW. it fails completely in Python 2.7.
> 
> -- 
> --gv
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Recursive method in class

2019-10-01 Thread Grant Edwards
On 2019-10-01, Timur Tabi  wrote:
> Could you please fix your email software so that it shows a legitimate
> email address in the From: line?  Your emails all show this:
>
> From: ast 
>
> All of your emails are being caught in my spam filter because of this
> address.  I would email you privately, but I know n...@gmail.com isn't
> your real email address.

Worse yet, it's probably _somebody_else's_real_email_address_

-- 
Grant Edwards   grant.b.edwardsYow! In Newark the
  at   laundromats are open 24
  gmail.comhours a day!

-- 
https://mail.python.org/mailman/listinfo/python-list


python socket dns query will get the correct result while the dig will not.

2019-10-01 Thread Hongyi Zhao
Hi,

See my following test:

With ipython:

In [1]: import 
socket   

In [2]: socket.gethostbyname
('www.vpngate.net') 
Out[2]: '130.158.75.44'


With dig:

$ dig www.vpngate.net @114.114.114.114 +short
31.13.65.1
$ dig www.vpngate.net @8.8.8.8 +short
46.82.174.68

Any hints?
-- 
https://mail.python.org/mailman/listinfo/python-list


[RELEASE] Python 3.7.5rc1 is now available for testing

2019-10-01 Thread Ned Deily
Python 3.7.5rc1 is now available for testing. 3.7.5rc1 is the release preview 
of the next maintenance release of Python 3.7, the latest feature release of 
Python. Assuming no critical problems are found prior to 2019-10-14, no code 
changes are planned between now and the final release. This release candidate 
is intended to give you the opportunity to test the new security and bug fixes 
in 3.7.5. We strongly encourage you to test your projects and report issues 
found to bugs.python.org as soon as possible. Please keep in mind that this is 
a preview release and, thus, its use is not recommended for production 
environments.

You can find the release files, a link to the changelog, and more information 
here:
https://www.python.org/downloads/release/python-375rc1/

--
  Ned Deily
  n...@python.org -- []

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Recursive method in class

2019-10-01 Thread ast

Le 01/10/2019 à 20:56, Timur Tabi a écrit :

Could you please fix your email software so that it shows a legitimate
email address in the From: line?  Your emails all show this:

 From: ast 

All of your emails are being caught in my spam filter because of this
address.  I would email you privately, but I know n...@gmail.com isn't
your real email address.



Do "legitimate" means and address with a dot ?
But your own email address doesn't have a dot.

I don't want to show my real email address
because I don't want to be flooded with spam.

I choose: ast.donotans...@gmail.com
Hope it will convenient for you

--
https://mail.python.org/mailman/listinfo/python-list


pymysql.err.InterfaceError after some hours of usage

2019-10-01 Thread Νίκος Βέργος
Hello, i use 'module pymysql' for connectivity in my wsgi scripts. For some 
reason after some hours of i.e. 'http://superhost.gr/files' i get the following 
error when the script tries to run:
Do you know why this is happening?!


Error: 500 Internal Server Error
Sorry, the requested URL 'http://superhost.gr/files/' caused an error:

Internal Server Error
Exception:
InterfaceError("(0, '')",)
Traceback:
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/bottle.py", line 862, in _handle
return route.call(**args)
  File "/usr/lib/python3.6/site-packages/bottle.py", line 1740, in wrapper
rv = callback(*a, **ka)
  File "/home/nikos/wsgi/files.py", line 143, in displayall
convert()
  File "/home/nikos/wsgi/files.py", line 93, in convert
cur.execute('''SELECT file FROM files''')
  File "/usr/lib64/python3.6/site-packages/pymysql/cursors.py", line 170, in 
execute
result = self._query(query)
  File "/usr/lib64/python3.6/site-packages/pymysql/cursors.py", line 328, in 
_query
conn.query(q)
  File "/usr/lib64/python3.6/site-packages/pymysql/connections.py", line 516, 
in query
self._execute_command(COMMAND.COM_QUERY, sql)
  File "/usr/lib64/python3.6/site-packages/pymysql/connections.py", line 750, 
in _execute_command
raise err.InterfaceError("(0, '')")
pymysql.err.InterfaceError: (0, '')



I only use this opening statement in the beginning of my scripts.

conn = pymysql.connect( host='localhost', user='user', password='pass', 
db='counters' )
cur = conn.cursor()

Then i execute insert and update sql statements but i never close the 
connection. I presume python closes the connection when the script ends. 
Doesn't it?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pymysql.err.InterfaceError after some hours of usage

2019-10-01 Thread Inada Naoki
MySQL connection can be closed automatically by various reasons.
For example, `wait_timeout` is the most common but not only reason for
closing the connection.

You should connect and close MySQL connection for each HTTP request.

Or you can use more smart connection pool (e.g. Engine in SQLAlchemy).
It provides `pool_recycle` and `pool_pre_ping` options.

https://docs.sqlalchemy.org/en/13/core/pooling.html#setting-pool-recycle
https://docs.sqlalchemy.org/en/13/core/engines.html#sqlalchemy.create_engine.params.pool_pre_ping

On Wed, Oct 2, 2019 at 2:16 PM Νίκος Βέργος  wrote:
>
> Hello, i use 'module pymysql' for connectivity in my wsgi scripts. For some 
> reason after some hours of i.e. 'http://superhost.gr/files' i get the 
> following error when the script tries to run:
> Do you know why this is happening?!
>
>
> Error: 500 Internal Server Error
> Sorry, the requested URL 'http://superhost.gr/files/' caused an error:
>
> Internal Server Error
> Exception:
> InterfaceError("(0, '')",)
> Traceback:
> Traceback (most recent call last):
>   File "/usr/lib/python3.6/site-packages/bottle.py", line 862, in _handle
> return route.call(**args)
>   File "/usr/lib/python3.6/site-packages/bottle.py", line 1740, in wrapper
> rv = callback(*a, **ka)
>   File "/home/nikos/wsgi/files.py", line 143, in displayall
> convert()
>   File "/home/nikos/wsgi/files.py", line 93, in convert
> cur.execute('''SELECT file FROM files''')
>   File "/usr/lib64/python3.6/site-packages/pymysql/cursors.py", line 170, in 
> execute
> result = self._query(query)
>   File "/usr/lib64/python3.6/site-packages/pymysql/cursors.py", line 328, in 
> _query
> conn.query(q)
>   File "/usr/lib64/python3.6/site-packages/pymysql/connections.py", line 516, 
> in query
> self._execute_command(COMMAND.COM_QUERY, sql)
>   File "/usr/lib64/python3.6/site-packages/pymysql/connections.py", line 750, 
> in _execute_command
> raise err.InterfaceError("(0, '')")
> pymysql.err.InterfaceError: (0, '')
>
>
>
> I only use this opening statement in the beginning of my scripts.
>
> conn = pymysql.connect( host='localhost', user='user', password='pass', 
> db='counters' )
> cur = conn.cursor()
>
> Then i execute insert and update sql statements but i never close the 
> connection. I presume python closes the connection when the script ends. 
> Doesn't it?
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Inada Naoki  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python socket dns query will get the correct result while the dig will not.

2019-10-01 Thread Chris Angelico
On Wed, Oct 2, 2019 at 2:31 PM Hongyi Zhao  wrote:
>
> Hi,
>
> See my following test:
>
> With ipython:
>
> In [1]: import
> socket
>
> In [2]: socket.gethostbyname
> ('www.vpngate.net')
> Out[2]: '130.158.75.44'
>
>
> With dig:
>
> $ dig www.vpngate.net @114.114.114.114 +short
> 31.13.65.1
> $ dig www.vpngate.net @8.8.8.8 +short
> 46.82.174.68
>
> Any hints?

When you ask dig, you are always asking for a DNS lookup. But
gethostbyname does a lot of other things too. My guess is that your
/etc/hosts has an entry for that domain. It's also possible that your
DNS resolver is misconfigured, especially since the authoritative
servers for that domain disagree with your dig results.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python socket dns query will get the correct result while the dig will not.

2019-10-01 Thread Hongyi Zhao
On Wed, 02 Oct 2019 16:28:40 +1000, Chris Angelico wrote:

> When you ask dig, you are always asking for a DNS lookup. But
> gethostbyname does a lot of other things too. 

What other things, could you please give more detailed hints?

> My guess is that your
> /etc/hosts has an entry for that domain.

No.

> It's also possible that your
> DNS resolver is misconfigured, especially since the authoritative
> servers for that domain disagree with your dig results.

As you can see, I use the public dns servers for the dig, and I cannot do 
any config on these dns resolvers.

> 
> ChrisA

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python socket dns query will get the correct result while the dig will not.

2019-10-01 Thread Chris Angelico
On Wed, Oct 2, 2019 at 4:41 PM Hongyi Zhao  wrote:
>
> On Wed, 02 Oct 2019 16:28:40 +1000, Chris Angelico wrote:
>
> > When you ask dig, you are always asking for a DNS lookup. But
> > gethostbyname does a lot of other things too.
>
> What other things, could you please give more detailed hints?

Start with /etc/nsswitch.conf and see how far down the rabbit hole you
want to go...

http://man7.org/linux/man-pages/man5/nsswitch.conf.5.html

> > My guess is that your
> > /etc/hosts has an entry for that domain.
>
> No.
>
> > It's also possible that your
> > DNS resolver is misconfigured, especially since the authoritative
> > servers for that domain disagree with your dig results.
>
> As you can see, I use the public dns servers for the dig, and I cannot do
> any config on these dns resolvers.
>

Actually I'm not sure that you are, since you're getting completely
different results to mine. It's possible you have something
intercepting your DNS requests.

Hmm. The first IP you posted (which purportedly came back from
114.114.114.114) belongs to Facebook. That's pretty suspicious.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list