Re: Data model and attribute resolution in subclasses

2020-03-01 Thread Adam Preble
Based on what I was seeing here, I did some experiments to try to understand 
better what is going on:

class BaseClass:
def __init__(self):
self.a = 1

def base_method(self):
return self.a

def another_base_method(self):
return self.a + 1


class SubClass(BaseClass):
def __init__(self):
super().__init__()
self.b = 2


c = SubClass()
print(c.__dict__)
print(c.__class__.__dict__)
print(c.__class__.__subclasses__())
print(c.__class__.mro())
print(c.__class__.mro()[1].__dict__)
print(getattr(c, "base_method"))
print(c.b)
print(c.a)

With some notes:
print(c.__dict__)
{'a': 1, 'b': 2}
So the instance directly has a. I am guessing that the object's own dictionary 
is directly getting these are both __init__'s are run.

print(c.__class__.__dict__)
{'__module__': '__main__', '__init__': , '__doc__': None}
I am guessing this is what is found and stuffed into the class' namespace when 
the class is built; that's specifically the BUILD_CLASS opcode doing its thing.

print(c.__class__.__subclasses__())
[]
What?! Why isn't this []?

print(c.__class__.mro())
[, , ]
This is more like what I expected to find with subclasses. Okay, no, method 
resolution order is showing the entire order.

print(c.__class__.mro()[1].__dict__)
{'__module__': '__main__', '__init__': , 'base_method': , 'another_base_method': , '__dict__': , '__weakref__': , '__doc__': None}
No instance-level stuff. Looks like it's the base class namespace when the 
BUILD_CLASS opcode saw it. Okay, looking good.

print(getattr(c, "base_method"))
>
I'm guessing here it didn't find it in the object's __dict__ nor the class' 
__dict__ so it went in mro and found it in BaseClass.

So I need a __dict__ for the class based on the code defined for it when the 
class is defined. That's associated with the class. I need another dictionary 
for each instance. That will get stuffed with whatever started getting dumped 
into it in __init__ (and possibly elsewhere afterwards).

What __dict__ actually is can vary. The mappingproxy helps make sure that 
strings are given as keys (among other things?).
-- 
https://mail.python.org/mailman/listinfo/python-list


Multiple turtles

2020-03-01 Thread Giuseppe

Hi,

I am new to Python.
I already tried turtle and it works well for my needs.

I would like to draw fractals using turtle module. There are many ways 
to do that but I would like to use multiple turtles drawing in parallel 
but I don't know how.


My first idea is to use clones as I do with Scratch (the problem with 
Scratch is the maximum number of simultaneous clones is set to 300) : 
each clone draw a part of the fractal and each clone (before being 
deleted) create clones who do the same thing and so on and so on...


1/ Is it possible to clone turtles ?
2/ Is it possible to make them work simultaneously ?
3/ Should I use multiple turtles instead ?
4/ Are there special things I should read first ?

Thank you.


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


Re: php to python code converter

2020-03-01 Thread Souvik Dutta
Use this instead (I know the name is misleading)
https://pypi.org/project/convert2php/

On Sun, Mar 1, 2020, 11:25 AM  wrote:

> On Friday, May 8, 2009 at 3:38:25 AM UTC-7, bvidinli wrote:
> > if anybody needs:
> > http://code.google.com/p/phppython/
>
> this link doesn't work
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: EuroPython 2020: Call for Proposals opens on March 9th

2020-03-01 Thread Souvik Dutta
I would like to see a bit of modernisation of the tkinter module. Like use
of style sheets and opening images in a better way like not relying on
bitmaps and thing like that. I would also like pip to check for PGP
signature as that would certainly ensure security.  And I generally use
python for making apps. Thank you.

On Wed, Feb 26, 2020, 10:21 PM M.-A. Lemburg  wrote:

> We are happy to announce that the Call for Proposals will open on
> March 9. It will be left open for three weeks and then close on:
>
> Sunday, March 29 23:59:59 CEST
>
> While you wait for submissions to open, please check out the Call for
> Proposals details on our pre-launch website:
>
> https://ep2020.europython.eu/call-for-proposals/
>
> We’re looking for proposals on every aspect of Python: all levels of
> programming from novice to advanced, applications, frameworks, data
> science, Python projects, internals or topics which you’re excited
> about, your experiences with Python and its ecosystem, creative or
> artistic things you’ve done with Python, to name a few.
>
> EuroPython is a community conference and we are eager to hear about
> your use of Python.
>
> Since feedback shows that our audience is very interested in advanced
> topics, we’d appreciate more entries in this category for EuroPython
> 2020.
>
> Please help spread word about Call for Proposals to anyone who might
> be interested. Thanks.
>
>
> Some additional updates:
> 
>
> - We’re working on launching the website, CfP and ticket sales in
>   March.
>
> - We are also preparing the sponsorship packages and should have them
>   ready early in March as well. Early bird sponsors will again receive
>   a 10% discount on the package price. If you’re interested in
>   becoming a launch sponsor, please contact our sponsor team at
>   [email protected].
>
>
> 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/611042486524280832/europython-2020-call-for-proposals-opens-on-march
>
> Tweet:
>
> https://twitter.com/europython/status/1232708258525302784
>
>
> Enjoy,
> --
> EuroPython 2020 Team
> https://ep2020.europython.eu/
> https://www.europython-society.org/
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: php to python code converter

2020-03-01 Thread Terry Reedy

On 3/1/2020 12:53 AM, [email protected] wrote:

On Friday, May 8, 2009 at 3:38:25 AM UTC-7, bvidinli wrote:

if anybody needs:
http://code.google.com/p/phppython/


this link doesn't work


I believe free code.google.com was shut down a few years ago.  I have a 
file there and was emailed to make sure I had a copy before it was deleted.



--
Terry Jan Reedy

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


Re: Data model and attribute resolution in subclasses

2020-03-01 Thread Terry Reedy

On 3/1/2020 4:49 AM, Adam Preble wrote:

Based on what I was seeing here, I did some experiments to try to understand 
better what is going on:

class BaseClass:
 def __init__(self):
 self.a = 1

 def base_method(self):
 return self.a

 def another_base_method(self):
 return self.a + 1


class SubClass(BaseClass):
 def __init__(self):
 super().__init__()
 self.b = 2


c = SubClass()
print(c.__dict__)
print(c.__class__.__dict__)
print(c.__class__.__subclasses__())
print(c.__class__.mro())
print(c.__class__.mro()[1].__dict__)
print(getattr(c, "base_method"))
print(c.b)
print(c.a)



print(c.__class__.__subclasses__())
[]
What?! Why isn't this []?


Because BaseClass is the superclass of SubClass.


--
Terry Jan Reedy

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


Have you some experience / link about difference between Python builded with gcc and clang?

2020-03-01 Thread Marco Sulla via Python-list
As title. Currently I'm using gcc 9.2.0 and its compilation seems to
work well and fast. But I would know by your experience if clang can
produce, on a *nix system, a "faster Python".
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Multiple turtles

2020-03-01 Thread Terry Reedy

On 3/1/2020 4:54 AM, Giuseppe wrote:

Hi,

I am new to Python.
I already tried turtle and it works well for my needs.

I would like to draw fractals using turtle module. There are many ways 
to do that but I would like to use multiple turtles drawing in parallel 
but I don't know how.


My first idea is to use clones as I do with Scratch (the problem with 
Scratch is the maximum number of simultaneous clones is set to 300) : 
each clone draw a part of the fractal and each clone (before being 
deleted) create clones who do the same thing and so on and so on...


1/ Is it possible to clone turtles ?
2/ Is it possible to make them work simultaneously ?
3/ Should I use multiple turtles instead ?
4/ Are there special things I should read first ?


1 & 3.  I don't know what a Scratch clone is so I don't know the 
difference between 1 and 3.  I suspect the answer is 3.  Note that 
turtle provides a default turtle.  Then one can create more with Turtle().


2. Truly in parallel? no.  Turtle module uses a tk Canvas and one can 
only draw to a canvas from one process.  One can instead rotate among 
turtles so it looks like they move 'simultaneously'.


4. Run 'python -m turtle' and watch the two demos, especially the last 
part of the second.  Then read demo2() starting with


tri = getturtle()  # Default turtle, chaser.
tri.resizemode("auto")  # New turtle, chased.
# ... and loop.
while tri.distance(turtle) > 4:
turtle.fd(3.5)
turtle.lt(0.6)
tri.setheading(tri.towards(turtle))
tri.fd(4)

For your purpose, you should, for instance, make a Turtle subclass with 
additional data and an extra 'tick' method to move according to the 
extra instance data.  Remember that modifying collections while 
iterating through them is either prohibited or tricky.



--
Terry Jan Reedy

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


Re: EuroPython 2020: Call for Proposals opens on March 9th

2020-03-01 Thread Barry


> On 1 Mar 2020, at 14:51, Souvik Dutta  wrote:
> 
> I would like to see a bit of modernisation of the tkinter module. Like use
> of style sheets and opening images in a better way like not relying on
> bitmaps and thing like that. I would also like pip to check for PGP
> signature as that would certainly ensure security.  And I generally use
> python for making apps. Thank you.

Have a look at PyQt5. It OO and cross platform with few quirks.

Barry


> 
>> On Wed, Feb 26, 2020, 10:21 PM M.-A. Lemburg  wrote:
>> 
>> We are happy to announce that the Call for Proposals will open on
>> March 9. It will be left open for three weeks and then close on:
>> 
>>Sunday, March 29 23:59:59 CEST
>> 
>> While you wait for submissions to open, please check out the Call for
>> Proposals details on our pre-launch website:
>> 
>>https://ep2020.europython.eu/call-for-proposals/
>> 
>> We’re looking for proposals on every aspect of Python: all levels of
>> programming from novice to advanced, applications, frameworks, data
>> science, Python projects, internals or topics which you’re excited
>> about, your experiences with Python and its ecosystem, creative or
>> artistic things you’ve done with Python, to name a few.
>> 
>> EuroPython is a community conference and we are eager to hear about
>> your use of Python.
>> 
>> Since feedback shows that our audience is very interested in advanced
>> topics, we’d appreciate more entries in this category for EuroPython
>> 2020.
>> 
>> Please help spread word about Call for Proposals to anyone who might
>> be interested. Thanks.
>> 
>> 
>> Some additional updates:
>> 
>> 
>> - We’re working on launching the website, CfP and ticket sales in
>>  March.
>> 
>> - We are also preparing the sponsorship packages and should have them
>>  ready early in March as well. Early bird sponsors will again receive
>>  a 10% discount on the package price. If you’re interested in
>>  becoming a launch sponsor, please contact our sponsor team at
>>  [email protected].
>> 
>> 
>> 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/611042486524280832/europython-2020-call-for-proposals-opens-on-march
>> 
>> Tweet:
>> 
>> https://twitter.com/europython/status/1232708258525302784
>> 
>> 
>> Enjoy,
>> --
>> EuroPython 2020 Team
>> https://ep2020.europython.eu/
>> https://www.europython-society.org/
>> 
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Have you some experience / link about difference between Python builded with gcc and clang?

2020-03-01 Thread Skip Montanaro
> As title. Currently I'm using gcc 9.2.0 and its compilation seems to
> work well and fast. But I would know by your experience if clang can
> produce, on a *nix system, a "faster Python".

I took a quick run at this as I was wanting to give pyperformance
 a try. Comparing GCC 9 with CLANG 8 on
my Ubuntu laptop here's what I got. It seems that GCC was a bit faster than
CLANG pretty much across the board.

+-+-+---+
| Benchmark   | gcc | clang |
+=+=+===+
| 2to3| 403 ms  | 440 ms: 1.09x slower (+9%)|
+-+-+---+
| chameleon   | 12.6 ms | 13.5 ms: 1.07x slower (+7%)   |
+-+-+---+
| chaos   | 148 ms  | 169 ms: 1.14x slower (+14%)   |
+-+-+---+
| crypto_pyaes| 145 ms  | 157 ms: 1.08x slower (+8%)|
+-+-+---+
| deltablue   | 9.79 ms | 11.4 ms: 1.17x slower (+17%)  |
+-+-+---+
| django_template | 69.9 ms | 77.6 ms: 1.11x slower (+11%)  |
+-+-+---+
| dulwich_log | 89.3 ms | 92.6 ms: 1.04x slower (+4%)   |
+-+-+---+
| fannkuch| 590 ms  | 602 ms: 1.02x slower (+2%)|
+-+-+---+
| float   | 150 ms  | 160 ms: 1.07x slower (+7%)|
+-+-+---+
| genshi_text | 35.9 ms | 39.4 ms: 1.10x slower (+10%)  |
+-+-+---+
| genshi_xml  | 74.8 ms | 81.8 ms: 1.09x slower (+9%)   |
+-+-+---+
| go  | 339 ms  | 390 ms: 1.15x slower (+15%)   |
+-+-+---+
| hexiom  | 12.9 ms | 14.3 ms: 1.11x slower (+11%)  |
+-+-+---+
| json_dumps  | 16.4 ms | 17.6 ms: 1.07x slower (+7%)   |
+-+-+---+
| json_loads  | 32.9 us | 34.6 us: 1.05x slower (+5%)   |
+-+-+---+
| logging_format  | 13.9 us | 15.2 us: 1.09x slower (+9%)   |
+-+-+---+
| logging_silent  | 253 ns  | 298 ns: 1.18x slower (+18%)   |
+-+-+---+
| logging_simple  | 12.6 us | 14.1 us: 1.12x slower (+12%)  |
+-+-+---+
| mako| 21.8 ms | 24.2 ms: 1.11x slower (+11%)  |
+-+-+---+
| meteor_contest  | 128 ms  | 133 ms: 1.04x slower (+4%)|
+-+-+---+
| nbody   | 181 ms  | 190 ms: 1.05x slower (+5%)|
+-+-+---+
| nqueens | 128 ms  | 135 ms: 1.05x slower (+5%)|
+-+-+---+
| pathlib | 26.3 ms | 27.1 ms: 1.03x slower (+3%)   |
+-+-+---+
| pickle  | 13.3 us | 13.5 us: 1.01x slower (+1%)   |
+-+-+---+
| pickle_dict | 33.8 us | 33.6 us: 1.01x faster (-1%)   |
+-+-+---+
| pickle_list | 4.82 us | 5.18 us: 1.07x slower (+7%)   |
+-+-+---+
| pickle_pure_python  | 613 us  | 725 us: 1.18x slower (+18%)   |
+-+-+---+
| pidigits| 210 ms  | 218 ms: 1.04x slower (+4%)|
+-+-+---+
| pyflate | 871 ms  | 1.00 sec: 1.15x slower (+15%) |
+-+-+---+
| python_startup  | 10.3 ms | 10.4 ms: 1.01x slower (+1%)   |
+-+-+---+
| python_startup_no_site  | 7.16 ms | 7.39 ms: 1.03x slower (+3%)   |
+-+-+---+

Re: Have you some experience / link about difference between Python builded with gcc and clang?

2020-03-01 Thread Marco Sulla via Python-list
Good! Have you compiled it optimized (--enable-optimizations --with-lto)?

On Sun, 1 Mar 2020 at 23:48, Skip Montanaro  wrote:
>
> > As title. Currently I'm using gcc 9.2.0 and its compilation seems to
> > work well and fast. But I would know by your experience if clang can
> > produce, on a *nix system, a "faster Python".
>
> I took a quick run at this as I was wanting to give pyperformance a try. 
> Comparing GCC 9 with CLANG 8 on my Ubuntu laptop here's what I got. It seems 
> that GCC was a bit faster than CLANG pretty much across the board.
>
> +-+-+---+
> | Benchmark   | gcc | clang |
> +=+=+===+
> | 2to3| 403 ms  | 440 ms: 1.09x slower (+9%)|
> +-+-+---+
> | chameleon   | 12.6 ms | 13.5 ms: 1.07x slower (+7%)   |
> +-+-+---+
> | chaos   | 148 ms  | 169 ms: 1.14x slower (+14%)   |
> +-+-+---+
> | crypto_pyaes| 145 ms  | 157 ms: 1.08x slower (+8%)|
> +-+-+---+
> | deltablue   | 9.79 ms | 11.4 ms: 1.17x slower (+17%)  |
> +-+-+---+
> | django_template | 69.9 ms | 77.6 ms: 1.11x slower (+11%)  |
> +-+-+---+
> | dulwich_log | 89.3 ms | 92.6 ms: 1.04x slower (+4%)   |
> +-+-+---+
> | fannkuch| 590 ms  | 602 ms: 1.02x slower (+2%)|
> +-+-+---+
> | float   | 150 ms  | 160 ms: 1.07x slower (+7%)|
> +-+-+---+
> | genshi_text | 35.9 ms | 39.4 ms: 1.10x slower (+10%)  |
> +-+-+---+
> | genshi_xml  | 74.8 ms | 81.8 ms: 1.09x slower (+9%)   |
> +-+-+---+
> | go  | 339 ms  | 390 ms: 1.15x slower (+15%)   |
> +-+-+---+
> | hexiom  | 12.9 ms | 14.3 ms: 1.11x slower (+11%)  |
> +-+-+---+
> | json_dumps  | 16.4 ms | 17.6 ms: 1.07x slower (+7%)   |
> +-+-+---+
> | json_loads  | 32.9 us | 34.6 us: 1.05x slower (+5%)   |
> +-+-+---+
> | logging_format  | 13.9 us | 15.2 us: 1.09x slower (+9%)   |
> +-+-+---+
> | logging_silent  | 253 ns  | 298 ns: 1.18x slower (+18%)   |
> +-+-+---+
> | logging_simple  | 12.6 us | 14.1 us: 1.12x slower (+12%)  |
> +-+-+---+
> | mako| 21.8 ms | 24.2 ms: 1.11x slower (+11%)  |
> +-+-+---+
> | meteor_contest  | 128 ms  | 133 ms: 1.04x slower (+4%)|
> +-+-+---+
> | nbody   | 181 ms  | 190 ms: 1.05x slower (+5%)|
> +-+-+---+
> | nqueens | 128 ms  | 135 ms: 1.05x slower (+5%)|
> +-+-+---+
> | pathlib | 26.3 ms | 27.1 ms: 1.03x slower (+3%)   |
> +-+-+---+
> | pickle  | 13.3 us | 13.5 us: 1.01x slower (+1%)   |
> +-+-+---+
> | pickle_dict | 33.8 us | 33.6 us: 1.01x faster (-1%)   |
> +-+-+---+
> | pickle_list | 4.82 us | 5.18 us: 1.07x slower (+7%)   |
> +-+-+---+
> | pickle_pure_python  | 613 us  | 725 us: 1.18x slower (+18%)   |
> +-+-+---+
> | pidigits| 210 ms  | 218 ms: 1.04x slower (+4%)|
> +-+-+---+
> | pyflate | 871 ms  | 1.00 sec: 1.15x slower (+15%) |
> +-+-+---+
> | python_startup  | 10.3 ms | 10.4 ms: 1.01

Re: Have you some experience / link about difference between Python builded with gcc and clang?

2020-03-01 Thread Skip Montanaro via Python-list
I didn't have clang installed. It was just "sudo apt install clang-8". From
there all I had to do was build Python from scratch twice, install
pyperformance using pip after the first build, then run it after each
build. It's not difficult. Going beyond that right now is not an itch I
need to scratch though. I have other things on my plate.

Skip

On Sun, Mar 1, 2020, 6:11 PM Marco Sulla <
[email protected]> wrote:

> Oooohhh uff, I have to install latest clang... or better, compile
> it as I did for gcc. And I have to read the install docs to see if
> there's some trick to optimize it... and I have to read the docs of
> pyperformance too (I only used pyperf until now)...
>
> Oh well, tomorrow :-D
>
> On Mon, 2 Mar 2020 at 00:58, Skip Montanaro 
> wrote:
> >>
> >> Have you compiled it optimized (--enable-optimizations --with-lto)?
> >
> >
> > Nope, just ./configure. Further investigation is left as an exercise for
> the reader. :-)
> >
> > Skip
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 【Regarding Performance of a Python Script....】

2020-03-01 Thread Cameron Simpson

On 28Feb2020 19:24, Kenzi  wrote:

I have a question regarding a simple code snippet in Python:

from subprocess import check_output
for i in range(1024):
   check_output(['/bin/bash', '-c', 'echo 42'], close_fds=True)

*I wonder why running it in Python 3.7 is much faster than Python 2.7? *
(Python 3.7 is still faster, after I used *xrange * in Python 2.7)


On a lot of UNIX systems you can use the strace command to inspect what 
is happening. I am personally surprised there's a significant difference 
between the Pythons because I'd expect the expense of invoking bash to 
dominate the cost here (consider using /bin/sh, which on many systems 
isn't bash but something smaller/faster for noninteractive shell 
scripting).


Write a script running just the check_output() call one, and strace it:

   strace python -c "from subprocess import check_output; check_output(['/bin/bash', 
'-c', 'echo 42'], close_fds=True)"

See if your 2 Pythons are doing something difference at the system call 
level.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Data model and attribute resolution in subclasses

2020-03-01 Thread Adam Preble
On Sunday, March 1, 2020 at 3:08:29 PM UTC-6, Terry Reedy wrote:

> Because BaseClass is the superclass of SubClass.

So there's a mechanism for parent classes to know all their children?
-- 
https://mail.python.org/mailman/listinfo/python-list