Re: Trouble trying to get started with pygame

2019-11-15 Thread René Dudfield
Hi,

it's possible to have multiple processes running with separate pygame
windows.

However you need to communicate with an inter process mechanism.
For example by running a web server over TCP/ip/sockets, or UDP with OSC,
or shared memory with mmap, or even via clipboard copy/paste, the humble
file, or a database (Sqlite, PostgreSQL).
Each method has different trade offs.

However with pygame > pygame version 2 it is possible to have multiple OS
windows controlled by a single process.

The reason SDL and pygame do this is they come from a world where taking
over the whole screen (and OS) was common.
Also having multiple windows is mostly bad UX. If people are paying for
your UX, then probably you want good UX.

Note, that you can split the screen up inside a single OS window.
In pygame this is done easily with a subsurface, or by manually positioning
things with rects.


cheerio,




On Fri, Nov 15, 2019 at 3:36 AM  wrote:

> On Tuesday, November 12, 2019 at 7:05:16 PM UTC-5, Terry Reedy wrote:
> > On 11/12/2019 2:32 PM, originallmo...@gmail.com wrote:
> > > I'm curious: I've been seeing people having multiple pygame programs
> open at once (Where each one is a component of a main program, obviously).
> >
> > Multiple programs open at once on modern machines is normal.  Do you
> > mean multiple windows for one program?  As is possible with IDLE?
> >
> > --
> > Terry Jan Reedy
>
> Well, the example I was seeing, the person had one window which contained
> a portion of the larger pygame program controlling the display, another for
> controlling the characters, and another for the main program (Plus, I
> think, two others whose purpose I forget). I'm just concerned because, I
> can't imagine that's possible from the command prompt, but, I don't know
> what they had that would allow them to have multiple subprograms open at
> once in Python. I'm used to that in Visual Studio C++, but, I don't know of
> such a thing for Python.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: nonlocal fails ?

2019-11-15 Thread Pieter van Oostrum
"R.Wieser"  writes:

> Jan,
>
>> So what you want to do is dynamic scope?
>
> No, not really.I was looking for method to let one procedure share a 
> variable with its caller - or callers, selectable by me.   And as a "by 
> reference" argument does not seem to exist in Python ...
>
> And yes, I am a ware that procedures can return multiple results.  I just 
> didn'want to go that way (using the same variable twice in a single 
> calling).

Do you mean, if Proc1() is called from Func1, it uses MyVar defined in Func1, 
and if it is called from Func2, it uses MyVar from Func2?

If that is what you mean, that would be dynamic scope.
-- 
Pieter van Oostrum 
WWW: http://pieter.vanoostrum.org/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to delay until a next increment of time occurs ?

2019-11-15 Thread Bev In TX


> On Nov 14, 2019, at 8:42 PM, MRAB  wrote:
> 
> Objective-C++?
> 
> I knew that Objective-C is C with objects.
> 
> I knew that C++ is C with objects.
> 
> But C with both?

Per Wikipedia...
Objective-C++ is a language variant accepted by the front-end to the GNU 
Compiler Collection and Clang, which can compile source files that use a 
combination of C++ and Objective-C syntax. Objective-C++ adds to C++ the 
extensions that Objective-C adds to C. As nothing is done to unify the 
semantics behind the various language features, certain restrictions apply:

Bev in TX
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to delay until a next increment of time occurs ?

2019-11-15 Thread R.Wieser
Dave,

> OK I'm old enough cancer to know what X10 is. :-)

Ah, so that is the name I forgot. :-)

> I wouldn't think this is too difficult to do as you're only sending.

You're right, codewise it isn't.

> For this application IMO there is too much going on inside python that can 
> interrupt the cycle of modulation. (Intra and Extra python; garbage 
> collection, other processes, etc)

Actually, it seems to work rather well.   Ofcourse, that is with just the 
python program running, and sending the code a couple of times for good 
measure.

> I would drop back to a simple program in C that you execute from python

A program I wrote before even thinking of doing the same in Python. :-)

My goal here was to see if I could do the same in pure python.   I can, but 
barily.

> Let me stress, my advise is doing this *reliably*.

:-) Not possible without any kind of "is it on?" checking/feed-back 
mechanism.   As such a one-way signalling as is used for those wall-warts is 
"best effort" at best.

> Once you have this working reliably, you could then look to convert
> it to a python c-module to more tightly integrate it.

Interfacing Python with C{something} was already on the agenda.   Using this 
as a goal is a likely candidate. :-)

Regards,
Rudy Wieser


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


Re: nonlocal fails ?

2019-11-15 Thread Antoon Pardon
On 14/11/19 18:46, R.Wieser wrote:
> Jan,
>
>> So what you want to do is dynamic scope?
> No, not really.I was looking for method to let one procedure share a 
> variable with its caller - or callers, selectable by me.   And as a "by 
> reference" argument does not seem to exist in Python ...

If you start thinking about what kind of argument passing mechanisme
Python has,
you should first think about what kind of assignment semantics Python has.

In some sense all parameter passing in Python is by reference, but it is
the assignment
semantics that cause it to not have the effect people expect.

The preffered terminology is call by sharing, but if you mutate the
parameter it has the
same effect as call by reference.

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


Re: How to delay until a next increment of time occurs ?

2019-11-15 Thread R.Wieser
Rob,

> On an actually practical note; ever since they started baking the 
> quasi-realtime stuff into the Linux kernel, you've been able to use the 
> whole sched_setscheduler(2) family of calls (from C) to set a process's 
> real-time priority.

Its something worth to look into.  Thanks.

Regards,
Rudy Wieser


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


Re: py2 vs py3: zlib.adler32/crc32

2019-11-15 Thread Karsten Hilbert
Hello MRAB,

yes, like that :-)

Thanks,
Karsten

On Thu, Nov 14, 2019 at 09:11:37PM +, MRAB wrote:
> Date: Thu, 14 Nov 2019 21:11:37 +
> From: MRAB 
> To: python-list@python.org
> Subject: Re: py2 vs py3: zlib.adler32/crc32
> User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101
>  Thunderbird/60.9.1
>
> On 2019-11-14 19:22, Karsten Hilbert wrote:
> > Hi all,
> >
> > I am unsure how to solve: I use adler32/crc32 to generate integer values 
> > from data
> > for setting up an advisory lock in PostgreSQL.
> >
> > The PG function pg_try_advisory_lock()
> >
> >
> > https://www.postgresql.org/docs/12/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS
> >
> > takes two PG ints which are defined as:
> >
> > integer 4 bytes typical choice for integer  
> > -2147483648 to +2147483647
> >
> > Now, in Py > 2.5 zlib.adler32/crc32 will return suitable integers.
> >
> > However, in Py3 the return range has been changed to
> >
> > The return value is unsigned and in the range [0, 2**32-1] regardless 
> > of platform.
> >
> > which will overflow the PostgreSQL function.
> >
> > Is there a way to convert/modify/shift the py3 value such that it shows the
> > same representation as the py2 value ?   What I am looking for is:
> >
> >v2 = py2.zlib.adler32(data)
> >v3 = some_magic(py3.zlib.adler32(data))
> >if v2 == v3:
> >   print('same')
> >
> > I am sure there's something obvious with struct/< > such like which I am overlooking.
> >
> > Note that I can't simply do
> >
> > v2 = py2.zlib.adler32(data) & 0x
> >
> > because that can overflow the PostgreSQL integer. I think I need
> > the reverse, in a sense, but I am too dense, ATM.
> >
> Unsigned 32-bit to signed 32-bit:
>
> unsigned - (unsigned & 0x8000) * 2
>
> Signed 32-bit to unsigned 32-bit:
>
> signed & 0x
> --
> https://mail.python.org/mailman/listinfo/python-list

--
GPG  40BE 5B0E C98E 1713 AFA6  5BC0 3BEA AC80 7D4F C89B
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: nonlocal fails ?

2019-11-15 Thread R.Wieser
Chris,

> That doesn't really answer the question.

The problem is that you want to solve /this/ problem, while I'm looking for 
replies that are applicable to similar ones too.

To be blunt about it: I consider solutions that only solve a single problem 
most always as a waste of my time (exceptions to the rule, yadayadayada). 
Solutions that I can expand and build upon are the ones I'm looking for 
(read: learn from).

But as lot of people will respond like you and than pick something from the 
/supporting information/ and go off on a tangent with it that doesn't aim to 
answer /my/ question I have become rather carefull about what I post in 
regard to specifics.

> The point of your new car isn't to push the pedal - it's to get you some 
> place.

And thats your problem in a nutshell: You think in forms of "get you some 
place".

What about just /learning how to drive/ ?

Regards,
Rudy Wieser


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


Re: nonlocal fails ?

2019-11-15 Thread R.Wieser
Terry,

> This is discouraged for anything very complex.

Complex things do not exist.  If you think you have something like it you've 
just not yet broken it down in its components yet. :-)

> This is the standard way in Python and other OO languages.  By 'excluded', 
> do you mean 'rejected', or 'tried that, what else is there?'

The latter.  Although I've pretty-much rejected the "global" method.

> Closures are standard in functional languages and are less limited than 
> you seem to think.

I was talking about the "nonlocal" method of variable inheritance, not 
closures.   I'm not going to comment (much) on the latter until I've had a 
chance to play with them.

Regards,
Rudy Wieser


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


Re: How to delay until a next increment of time occurs ?

2019-11-15 Thread R.Wieser
Dennis,

> No, that addition is a fixed increment on the initial starting
> time, and is NOT relative to the ending of a sleep.

> No, that addition is a fixed increment

Yep.

> on the initial starting time

Nope.

If pythons sleep is worth its salt it ends exactly on the time provided in 
"t".   Thus the subsequent addition to that "t" is releative to the end of 
the sleep just before it.

> The subtraction in the sleep call is what adjusts for the processing
> time between sleeps

Yep.  /All/ the time in between them.   Not just from the "t +=" you 
mentioned onwards (ignoring the time spend on switching the pin and the 
loops jumping-back).

> ??? Not sure what you describe here

My apologies, I should have been clearer.   Its the time difference I saw 
when using a hard 300 uSec delay in the loop (cycle-time longer that 300 
uSec), compared to a drift-compensated delay of the same (cycle time exactly 
300 uSec).   I attributed the difference to the time as spend in the code 
between sleeps (loop jumping, toggeling of the pin and calculation of the 
new end time - possibly the sleeps argument calculation too)

Regards,
Rudy Wieser


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


Re: nonlocal fails ?

2019-11-15 Thread R.Wieser
Michael,

> Well I've only seen this done in languages where other mechanisms
>for returning complex types are not present.

:-) Than you have not seen to many languages I'm afraid.

There are quite a number of languages where /every/ type of argument 
(including values) can be transfered "by reference".  Though some default to 
"by value", where others default to "by reference".

As for "complex types" ?   I don't think a(n ASCII) string can be considered 
any kind of a complex type, but most all languages I know of transfer them 
"by reference" only (though some fake "by value" by using a copy-on-write 
mechanism).

> In C you can either return a pointer to the string (and remember who's
> responsibility it is to free the memory!), or you can allocate memory
> yourself and pass the pointer to a function, like strcpy.

Or pass a reference to an empty pointer, have the procedure allocate the 
memory and return the address of it in that pointer.

And only the second one comes near to what I indicated I asked about: a 
mutable value stored outside the current procedure.

> In Python there is no similar equivalent,

It looks like it

> other than hacks involving passing in mutable objects

The only "hack" I see here is to transfer /mutable/ object, instead of a 
non-mutable one.

> Fair enough, but trying to do 1:1 transliterations isn't going to
> help you learn idiomatic Python.

If I would have wanted that, why would I post here with open questions ? 
But yes, I often refer to how other languages work, in an attempt to get the 
other to tell me whats so special/different about the current languages 
solution for it.

Regards,
Rudy Wieser


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


Re: nonlocal fails ?

2019-11-15 Thread Chris Angelico
On Fri, Nov 15, 2019 at 9:16 PM R.Wieser  wrote:
>
> Chris,
>
> > That doesn't really answer the question.
>
> The problem is that you want to solve /this/ problem, while I'm looking for
> replies that are applicable to similar ones too.
>
> To be blunt about it: I consider solutions that only solve a single problem
> most always as a waste of my time (exceptions to the rule, yadayadayada).
> Solutions that I can expand and build upon are the ones I'm looking for
> (read: learn from).
>
> But as lot of people will respond like you and than pick something from the
> /supporting information/ and go off on a tangent with it that doesn't aim to
> answer /my/ question I have become rather carefull about what I post in
> regard to specifics.
>
> > The point of your new car isn't to push the pedal - it's to get you some
> > place.
>
> And thats your problem in a nutshell: You think in forms of "get you some
> place".
>
> What about just /learning how to drive/ ?
>

The purpose of a car is not to learn how to ride a bicycle. Yes, I am
thinking in terms of an ultimate goal, because the point of coding is
to achieve something. Maybe your goal *right now* is to learn rather
than to create, but surely the purpose of the learning is to be able
to achieve things later?

Rather than try to implement pass-by-reference semantics in Python,
figure out what abstract concept you're actually trying to implement.
Otherwise, all you'll do is come up with convoluted methods of
implementing some other language's semantics in Python, and then write
your code using that other language's idioms, and run it in a Python
interpreter. Far better to actually learn Python's semantics, and how
they can be used to represent your actual goals.

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


Re: nonlocal fails ?

2019-11-15 Thread Chris Angelico
On Fri, Nov 15, 2019 at 11:01 PM R.Wieser  wrote:
>
> As for "complex types" ?   I don't think a(n ASCII) string can be considered
> any kind of a complex type, but most all languages I know of transfer them
> "by reference" only (though some fake "by value" by using a copy-on-write
> mechanism).

"Pass by value" and "pass by reference" become largely irrelevant when
your strings are immutable objects; so I would say that a large number
of languages have broadly "pass-by-value" semantics for strings,
treating them as first-class objects that are defined by value, not
identity.

> > In C you can either return a pointer to the string (and remember who's
> > responsibility it is to free the memory!), or you can allocate memory
> > yourself and pass the pointer to a function, like strcpy.
>
> Or pass a reference to an empty pointer, have the procedure allocate the
> memory and return the address of it in that pointer.

I don't know why you'd do that rather than simply return the new
pointer, but whatever. It's still a lot clunkier than simply returning
a string, which is what happens in all sane high-level languages.

> > In Python there is no similar equivalent,
>
> It looks like it
>
> > other than hacks involving passing in mutable objects
>
> The only "hack" I see here is to transfer /mutable/ object, instead of a
> non-mutable one.

Yes, Python has no concept of pass-by-reference. Python *always*
passes objects around, not variables. But everything that you could do
with "pass by reference" can be done by passing a mutable object, and
everything that you could do by passing mutable objects around can be
done by passing pointers to data structures, or (equivalently) passing
data structures by reference. There's no real difference.

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


Re: nonlocal fails ?

2019-11-15 Thread R.Wieser
Dennis,

> The first thing one needs to learn is that Python does NOT follow the
> common post-office mailbox concept where
>
> x = y
>
> means the /value/ stored at location identified by "y" is /copied/ to the
> location identified by "x".

:-)  Although that is how we humans remember the effect of what we do, there 
is no reason for a programming language to do it exactly like that.  And 
sometimes they don't.

> means /find/ the object (somewhere in memory) that has a note "y"
> stuck to it. Without moving the "y" note, attach an "x" note to that
> same object.

Which you can find back in any language which allows a "by reference" 
passing of arguments to a procedure (and do remember how strings are often 
/only/ passed as such).The caller often uses one name for the "value" 
passed as an argument but in the procedure uses a different one - both 
accessing the same contents.

> In software engineering as I learned it, it is preferable to decouple

... not because its so good for us humans, but that way you can 
mathematically prove that the finished program should work as designed.

... which some languages (mostly the ones which allow only single results 
returned from a function) are starting to turn back from (allowing "by 
reference" access back in - its just too damn usefull).

> All depends upon the scope of those procedures.

I have no idea which circumstances you're hinting at.   But just take it 
that the scope is local - apart from that externally referenced value 
ofcourse.

> The simplest is to use a mutable object as a container at the
> module level.

With some variation of "simple" I guess. :-)

Personally I think I would sooner go for a single-element tuple.

Regards,
Rudy Wieser


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


Re: nonlocal fails ?

2019-11-15 Thread R.Wieser
Pieter,

> Do you mean, if Proc1() is called from Func1, it uses MyVar defined
>in Func1, and if it is called from Func2, it uses MyVar from Func2?

Yep.

> If that is what you mean, that would be dynamic scope.

Thanks for pointing that out (I've learned a new definition today! :-) ).

Regards,
Rudy Wieser


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


Re: nonlocal fails ?

2019-11-15 Thread Richard Damon
On 11/15/19 6:56 AM, R.Wieser wrote:
> There are quite a number of languages where /every/ type of argument 
> (including values) can be transfered "by reference".  Though some default to 
> "by value", where others default to "by reference".

It seems you are stuck in a programming model different than what Python
provides, In a very real sense, the terms call "By Reference" and "By
Value" don't apply to Python. Those concepts presume that a variable
name represents a bucket of bytes that holds some value, and call by
value copies those bytes into a new variable for the subroutine, and
call by Reference creates a pointer value back to original value, and
all uses of that parameter work indirect that pointer.

That is NOT how Python works. In Python, in effect, every name in your
code is just a reference which points to some object (This is called
binding). Multiple names can point to the same object (or no names, at
which point the object is subject to being garbage collected). Names
themselves aren't objects, so you can't really make one name refer to
another, only to the same object that the other one does. (In actuality,
these collections of names are implemented basically in a Dictionary, so
using this sort of implementation details you can sort of get that
result, but I don't think that is defined to work in the language).

In the more classical languages, to draw a model of the variables you
have in memory, you take a big sheet of paper, put down each variable
name, and next to it a box where you put what value is stored in the
variable, and that value is intimately associated with that variable
name. You might have some objects being or containing
pointers/references and in that case you can represent it by an arrow
from the box representing the pointer to the object it is pointing to.
There may be some object that are created without a name (like on the
heap), but many of the objects are directly tied to a name.

In Python you do this differently. On one side of your paper, you put
your variable names, and on the other (perhaps a larger side) all the
values/objects you are working with. Each name gets an arrow to an
object to show what object it is currently bound to. Objects store the
values they hold, and some, like collections) also have arrows to other
objects they reference. An arrow always points to an object, never to a
name on the left side.

An assignment just changes what object a reference points to. If it is a
'top level' name being assigned to (as opposed to referring to a member
of an object or element of a collection), that is changing one of the
names on the left side of the page.

This difference in value model means you have to think about things
differently, and in a very real sense makes the terms 'by value' and 'by
reference' not applicable. You don't get values 'By Value', because you
didn't get a copy of the object reference, so if you mutate it, the
caller sees the change, but also it isn't by reference, as you can't
rebind the callers reference to point to a different object. This isn't
'Wrong' just 'Different'.

It takes some getting used to a different model, and I think it helps to
accept that it is different rather than trying to keep trying to
translate how Python does things into how some other language does it,
as the latter make you focus on the things it can't do, not the things
it can.

-- 
Richard Damon

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


Re: nonlocal fails ?

2019-11-15 Thread Michael Torrie
On 11/15/19 4:56 AM, R.Wieser wrote:
>> Well I've only seen this done in languages where other mechanisms
>> for returning complex types are not present.
> 
> :-) Than you have not seen to many languages I'm afraid.

Careful there.


> If I would have wanted that, why would I post here with open questions ? 
> But yes, I often refer to how other languages work, in an attempt to get the 
> other to tell me whats so special/different about the current languages 
> solution for it.

Yes you can learn a certain amount about a language by doing such 1:1
transliteration exercises.  But you can only go so far.  For example
you'll never master such powerful concepts as generators, closures, list
comprehensions, and so forth by doing this.

I've found a far better way is to do a project in a language, either
something you've done already in another language, or something new.
Instead of doing a low-level transliteration, look at the problem at the
high level, and find out how the language at hand best works to solve
the problem. That's why I and others asked what problem you're trying to
solve.

Also you seem to be comparing traditional, compiled with statically- but
often weakly-typed languages such as C, C++, Pascal, etc, with Python,
which is an interpreted, dynamically-typed language. They are very
different beasts with different strengths and weaknesses and very
different performance characteristics.

The reason you're getting such push back is that over the years on this
list we've seen dozens of new users arrive at Python but never really
learn how to program in Python.  These users insisted on coding in Java,
C#, or C++ (or whatever) in Python.  Some resist strongly when we
suggest this is a recipe for failure.  It was an exercise in frustration
and most of them left thinking what a horrible, limited language Python
is, and unable to understand what makes Python so productive,
expressive, and powerful.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: nonlocal fails ?

2019-11-15 Thread Random832
On Fri, Nov 15, 2019, at 10:48, Richard Damon wrote:
> On 11/15/19 6:56 AM, R.Wieser wrote:
> > There are quite a number of languages where /every/ type of argument 
> > (including values) can be transfered "by reference".  Though some default 
> > to 
> > "by value", where others default to "by reference".
> 
> It seems you are stuck in a programming model different than what Python
> provides, In a very real sense, the terms call "By Reference" and "By
> Value" don't apply to Python. Those concepts presume that a variable
> name represents a bucket of bytes that holds some value, and call by
> value copies those bytes into a new variable for the subroutine, and
> call by Reference creates a pointer value back to original value, and
> all uses of that parameter work indirect that pointer.
> 
> That is NOT how Python works. In Python, in effect, every name in your
> code is just a reference which points to some object (This is called
> binding). Multiple names can point to the same object (or no names, at
> which point the object is subject to being garbage collected). Names
> themselves aren't objects, so you can't really make one name refer to
> another, only to the same object that the other one does. (In actuality,
> these collections of names are implemented basically in a Dictionary, so
> using this sort of implementation details you can sort of get that
> result, but I don't think that is defined to work in the language).

Being abstractly typed objects rather than a bucket of bytes, and having the 
values themselves be a kind of reference or pointer (though to immutable data 
in some important cases), does not in fact change the meaning of the "call by 
reference" concept or its applicability.

It would be entirely reasonable, I think, in the python model, to provide a way 
for making a variable a cell variable, passing the cell object around 
explicitly, and having the called function automatically set/get the value when 
the argument is accessed. I don't think it would solve the OP's problem, since 
his talk about automatically "inheriting" the caller's variable of the same 
name sounds a lot more like dynamic scope than call by reference.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: nonlocal fails ?

2019-11-15 Thread Michael Torrie
On 11/15/19 5:28 AM, R.Wieser wrote:
> :-)  Although that is how we humans remember the effect of what we do, there 
> is no reason for a programming language to do it exactly like that.  And 
> sometimes they don't.

So, in effect he's saying not all languages use the classic variable
model, which you then agree with but then go on to insist that there
must be a way in Python to implement the classic, traditional language
variable model?  I don't understand your point.

> Which you can find back in any language which allows a "by reference" 
> passing of arguments to a procedure (and do remember how strings are often 
> /only/ passed as such).The caller often uses one name for the "value" 
> passed as an argument but in the procedure uses a different one - both 
> accessing the same contents.

Again, which isn't Python.  And come to that such mechanisms should be
used sparingly in languages which offer/require them.

> With some variation of "simple" I guess. :-)
> 
> Personally I think I would sooner go for a single-element tuple.

To each his own.  I rather suspect Python is not a good a fit for you.

Quite a few folks here have showed a lot of patience with your
questions, and posted very insightful and educational comments, which is
a part of the list that I enjoy very much and learn a great deal from.
But you seem to unwilling to internalize any of it.

However, I appreciate that you have kept the tone civil and polite.
Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: nonlocal fails ?

2019-11-15 Thread Richard Damon
On 11/15/19 11:04 AM, Random832 wrote:
> On Fri, Nov 15, 2019, at 10:48, Richard Damon wrote:
>> On 11/15/19 6:56 AM, R.Wieser wrote:
>>> There are quite a number of languages where /every/ type of argument 
>>> (including values) can be transfered "by reference".  Though some default 
>>> to 
>>> "by value", where others default to "by reference".
>> It seems you are stuck in a programming model different than what Python
>> provides, In a very real sense, the terms call "By Reference" and "By
>> Value" don't apply to Python. Those concepts presume that a variable
>> name represents a bucket of bytes that holds some value, and call by
>> value copies those bytes into a new variable for the subroutine, and
>> call by Reference creates a pointer value back to original value, and
>> all uses of that parameter work indirect that pointer.
>>
>> That is NOT how Python works. In Python, in effect, every name in your
>> code is just a reference which points to some object (This is called
>> binding). Multiple names can point to the same object (or no names, at
>> which point the object is subject to being garbage collected). Names
>> themselves aren't objects, so you can't really make one name refer to
>> another, only to the same object that the other one does. (In actuality,
>> these collections of names are implemented basically in a Dictionary, so
>> using this sort of implementation details you can sort of get that
>> result, but I don't think that is defined to work in the language).
> Being abstractly typed objects rather than a bucket of bytes, and having the 
> values themselves be a kind of reference or pointer (though to immutable data 
> in some important cases), does not in fact change the meaning of the "call by 
> reference" concept or its applicability.
>
> It would be entirely reasonable, I think, in the python model, to provide a 
> way for making a variable a cell variable, passing the cell object around 
> explicitly, and having the called function automatically set/get the value 
> when the argument is accessed. I don't think it would solve the OP's problem, 
> since his talk about automatically "inheriting" the caller's variable of the 
> same name sounds a lot more like dynamic scope than call by reference.

It isn't hard to explicitly do this in Python. The caller just puts it
value into a 1 element list, and then the called function mutates that
list (setting parm[0] instead of parm). This appears to align with
standard Python idioms.

The issue with calling it a Reference, is that part of the meaning of a
Reference is that it refers to a Object, and in Python, Names are
conceptually something very much different than an Object. Yes, in the
implementation details, a name is basically a dictionary entry, so it
could be done, the question is should it.

I have learned many computer languages over the years, and can say that
while figuring out how to map constructs from one language to another
has some value to start, you really do want to learn how the language
really working in itself. There is an old saying that you can write
FORTRAN in any language, and in a real sense it is true, and applies to
many languages. In a general sense you can generally take a programming
style from language X, and use it in language Y, and often be able to
get a 'working' and 'valid' program, but your really should be using
language X structures and use them in language X, write language Y using
the normal style for language Y.

In general, if you want to write a 'x' program, use language x, not
language y. The major exception is if language x isn't available on the
platform, but Python is usually the fallback language to go to, that
will more likely be C or C++ as those are what are most often the first
languages that are brought to a platform. (So maybe learning how to
write Python is C is useful, but writing C in Python has less need),

-- 
Richard Damon

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


Re: nonlocal fails ?

2019-11-15 Thread Richard Damon
On 11/15/19 11:26 AM, Dennis Lee Bieber wrote:
> On Fri, 15 Nov 2019 12:56:02 +0100, "R.Wieser" 
> declaimed the following:
>
>> There are quite a number of languages where /every/ type of argument 
>> (including values) can be transfered "by reference".  Though some default to 
>> "by value", where others default to "by reference".
>>
>   Yes -- and in those languages the concept of value vs reference is
> visible at the source code level. In C, everything is passed by value --
> and the programmer uses & to pass (by value) the address of the argument,
> and uses * in the called function to dereference that address back to the
> data item itself. C++ added reference arguments (where the & is used in the
> function declaration) in which the compiler automatically applies the
> "address" and "dereference" operations.

There are languages where pass by reference is the default and not explicit.

I remember in early FORTRAN being able to do something like this (its
been years since I have done this so syntax is probably a bit off)


PROCEDURE foo(i)

i = 2

return


then elsewhere you could do

foo(j)

and after that j is 2

you also could do

foo(1)

and after that if you did

j = 1

then now j might have the value 2 as the constant 1 was changed to the
value 2 (this can cause great confusion)

later I believe they added the ability to specify by value and by
reference, and you weren't allowed to pass constants by reference,

-- 
Richard Damon

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


Re: nonlocal fails ?

2019-11-15 Thread Python

Richard Damon wrote:
...

then elsewhere you could do

foo(j)

and after that j is 2

you also could do

foo(1)

and after that if you did

j = 1

then now j might have the value 2 as the constant 1 was changed to the
value 2 (this can cause great confusion)


Wow! So fubar that such a feature should definitely makes its
way into PHP!



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


Re: nonlocal fails ?

2019-11-15 Thread Random832
On Fri, Nov 15, 2019, at 11:47, Richard Damon wrote:
> The issue with calling it a Reference, is that part of the meaning of a
> Reference is that it refers to a Object, and in Python, Names are
> conceptually something very much different than an Object. Yes, in the
> implementation details, a name is basically a dictionary entry, so it
> could be done, the question is should it.

C# has basically the same issue and does fine calling its thing 'ref'. But 
that's not really the point - my point was that the concept of being able to 
have a function change the value of a variable specified by its caller doesn't 
magically cease being applicable just because the value is a "reference" and 
the variable is a "name binding".

[Similarly, the fact that values are "references" to mutable objects doesn't 
mean that python, or Java or C#, isn't call-by-value. The value is the 
"reference" itself, the fact that it can be used to change data that exists 
elsewhere is beside the point.]
-- 
https://mail.python.org/mailman/listinfo/python-list


What do you use for slides?

2019-11-15 Thread Abdur-Rahmaan Janhangeer
Greetings all,

For slides i use https://yhatt.github.io/marp/, but sometimes i want a more
stylish tool.

What do you use for slides? (besides powerpoint + syntax highlighting
included)

Thanks!

Abdur-Rahmaan Janhangeer
http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ
Mauritius
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What do you use for slides?

2019-11-15 Thread Grant Edwards
On 2019-11-15, Abdur-Rahmaan Janhangeer  wrote:

> For slides i use https://yhatt.github.io/marp/, but sometimes i want a more
> stylish tool.
>
> What do you use for slides? (besides powerpoint + syntax highlighting
> included)

Last time I made slides it was four a 3-day course I was teaching. I
used a package for TeX/LaTeX and produced PDF output for around 200
"slides".  That worked brilliantly.

It may have been SliTeX, but I'm not sure. Yikes, that was almost 20
years ago. :/

It looks like "Beamer" is a sligtly more modern apparoach using LaTeX:

   https://ctan.org/pkg/beamer

The typesetting quality of TeX is still impossible to beat...

--
Grant




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


Re: What do you use for slides?

2019-11-15 Thread Abdur-Rahmaan Janhangeer
Woops latex seems me programming the slides. yaps thanks for sharing. See
this pycon vid for example: https://youtu.be/6uAvHOKofws

It's simple and flexible ( you can add images, coloured syntax and cool
text ) and that's all we need. Don't know what he used.


Abdur-Rahmaan Janhangeer
http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ
Mauritius
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: nonlocal fails ?

2019-11-15 Thread Richard Damon
On 11/15/19 12:21 PM, Random832 wrote:
> On Fri, Nov 15, 2019, at 11:47, Richard Damon wrote:
>> The issue with calling it a Reference, is that part of the meaning of a
>> Reference is that it refers to a Object, and in Python, Names are
>> conceptually something very much different than an Object. Yes, in the
>> implementation details, a name is basically a dictionary entry, so it
>> could be done, the question is should it.
> C# has basically the same issue and does fine calling its thing 'ref'. But 
> that's not really the point - my point was that the concept of being able to 
> have a function change the value of a variable specified by its caller 
> doesn't magically cease being applicable just because the value is a 
> "reference" and the variable is a "name binding".
>
> [Similarly, the fact that values are "references" to mutable objects doesn't 
> mean that python, or Java or C#, isn't call-by-value. The value is the 
> "reference" itself, the fact that it can be used to change data that exists 
> elsewhere is beside the point.]

My understanding is the C# is like the rest of the C* family that
defining a variable x in the code, binds the name x to a specific object
in memory at compile time. That name will ALWAYS refer to that object
and that object can be thought to have that name, and no others in the
same way. The object may be/have a reference to another variable. (C++
references are a bit different at the language level, a reference itself
isn't an object, and taking the address of the reference 'object' give
the address of the object that the reference refers to, C++ references
are still compile time bound to a single object, but that object still
has a concept of the name it was created through) (I will admit that I
don't really know C#, but going from what I understand it as)

This is NOT true in Python. A 'Variable Name' in Python is not
statically bound to given object, but every assignment rebind the name
to object mapping.

Python does NOT use call by value, because a key feature of call by
value is that the value being passed is copied, and the new copy is used
in the subroutine. Name bindings are NOT values, objects have values,
and the value of the object passed is NOT copied to somewhere else. It
is only by misunderstanding the language, and trying to define a name as
being some sort of pointer object that points to the 'real' value of
object that you can create such an idea. This is NOT the model Python is
defined with, and while it might help a bit when starting to understand
how things work, you do need to move from that 'wrong' understanding to
starting to think of it the way Python is defined, or many things in
Python won't make sense.

-- 
Richard Damon

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


Re: nonlocal fails ?

2019-11-15 Thread Bev In TX


> On Nov 15, 2019, at 11:11 AM, Python  wrote:
> 
> Richard Damon wrote:
> ...
>> then elsewhere you could do
>> foo(j)
>> and after that j is 2
>> you also could do
>> foo(1)
>> and after that if you did
>> j = 1
>> then now j might have the value 2 as the constant 1 was changed to the
>> value 2 (this can cause great confusion)
> 
> Wow! So fubar that such a feature should definitely makes its
> way into PHP!

I remember fixing a bug caused by this.
Bev in TX
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: nonlocal fails ?

2019-11-15 Thread Luciano Ramalho
Re: the whole pass by reference discussion.

I've seen Python's argument passing described as "call by value,
except that all values are references". This makes sense, but is
confusing.

Michael Scott, in his textbook Programming Language Pragmatics (4e)
terms the Python way "call by sharing". That is the same mode used in
most OO languages that don't have pointers, including Ruby, SmallTalk,
and Java (this applies to Java reference types; primitive types use
call by value). Call by sharing means that each formal parameter of
the function gets a copy of each reference in the arguments.

Cheers,

Luciano


On Fri, Nov 15, 2019 at 3:58 PM Dennis Lee Bieber  wrote:
>
> On Fri, 15 Nov 2019 11:54:50 -0500, Richard Damon
>  declaimed the following:
>
> >
> >I remember in early FORTRAN being able to do something like this (its
> >been years since I have done this so syntax is probably a bit off)
> >
> >
> >
> >foo(1)
> >
> >and after that if you did
> >
> >j = 1
> >
> >then now j might have the value 2 as the constant 1 was changed to the
> >value 2 (this can cause great confusion)
> >
>
> It was a very early FORTRAN that did that, since literals were stored
> in general R/W memory and the address was passed. Later FORTRAN compilers
> would flag a section of memory for R/O and stored literals in that section
> -- so attempts at modification would result in an error.
>
> >later I believe they added the ability to specify by value and by
> >reference, and you weren't allowed to pass constants by reference,
>
> Many compilers added extensions for interfacing to other languages 
> (DEC
> is famous for %val(), %ref(), %descr() for controlling parameters, and
> %loc() external to parameters. %ref wasn't really useful in FORTRAN since
> that is the native method. %loc returned the address of the target item.
> %descr was a weird one -- things like character strings were passed by
> descriptor: first word was the address [standard reference model], second
> word encapsulated information like the length allocated to the string [not
> the length used, but the size of the memory allocation].
>
> Literals were still passed by reference -- just to read-only memory
> block. Otherwise the called function wouldn't know how to behave!
>
> subroutine xyz(parm)
> integer parm
>
> ...
>
> call xyz(1)
> call xyz(abc)
>
> if the first was passed by value and the second by reference, what was
> "parm" in the called function to do
>
>
> --
> Wulfraed Dennis Lee Bieber AF6VN
> wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
>
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Luciano Ramalho
|  Author of Fluent Python (O'Reilly, 2015)
| http://shop.oreilly.com/product/0636920032519.do
|  Technical Principal at ThoughtWorks
|  Twitter: @ramalhoorg
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: nonlocal fails ?

2019-11-15 Thread Chris Angelico
On Sat, Nov 16, 2019 at 6:20 AM Luciano Ramalho  wrote:
>
> Re: the whole pass by reference discussion.
>
> I've seen Python's argument passing described as "call by value,
> except that all values are references". This makes sense, but is
> confusing.

That's the typical sort of description you get from someone who mostly
understands Python's semantics, but is hung up on the idea that
everything is either call-by-value or call-by-reference, and is trying
to figure out which box Python fits into.

> Michael Scott, in his textbook Programming Language Pragmatics (4e)
> terms the Python way "call by sharing". That is the same mode used in
> most OO languages that don't have pointers, including Ruby, SmallTalk,
> and Java (this applies to Java reference types; primitive types use
> call by value). Call by sharing means that each formal parameter of
> the function gets a copy of each reference in the arguments.
>

I don't think anyone's yet linked to this:

https://nedbatchelder.com/text/names1.html

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


ANN: Wing Python IDE 7.1.3

2019-11-15 Thread Wingware
Wing 7.1.3 has been released.  This version adds improved and expanded 
documentation and support for matplotlib, improves the accuracy of code 
warnings, fixes automatically debugging child processes on Windows with 
Python 3.8, fixes installing the remote agent from .rpm or .deb 
installations, solves several issues with runtime type introspection, 
allows Open from Project and similar navigation commands from non-Browse 
vi mode, improves debugger reliability, and fixes about 30 other minor 
usability issues.


== Some Highlights of Wing 7.1 ==

* Support for Python 3.8: Wing 7.1 supports editing, testing, and 
debugging code written for Python 3.8, so you can take advantage of 
assignment expressions and other improvements introduced in this new 
version of Python.


* Improved Code Warnings: Wing 7.1 adds unused symbol warnings for 
imports, variables, and arguments found in Python code. This release 
also improves code warnings configuration, making it easier to disable 
unwanted warnings.


* Cosmetic Improvements: Wing 7.1 improves the auto-completer, project 
tool, and code browser with redesigned icons that make use of Wing's 
icon color configuration. This release also improves text display on 
some Linux systems, supports Dark Mode on macOS, and improves display of 
Python code and icons found in documentation.


* And More: Wing 7.1 also adds support for Windows 10 native OpenSSH 
installations for remote development, and makes a number of other minor 
improvements. This release drops support for macOS 10.11. System 
requirements remain unchanged on Windows and Linux.


For details see the change log:  
https://wingware.com/pub/wingpro/7.1.3.0/CHANGELOG.txt


For a complete list of new features in Wing 7, see What's New in Wing 
7:  https://wingware.com/wingide/whatsnew


== Downloads ==

Wing Pro: https://wingware.com/downloads/wing-pro/7.1/binaries
Wing Personal:  https://wingware.com/downloads/wing-personal/7.1/binaries
Wing 101: https://wingware.com/downloads/wing-101/7.1/binaries

Compare Products: https://wingware.com/downloads

See Upgrading https://wingware.com/doc/install/upgrading for details on 
upgrading from Wing 6 and earlier, and Migrating from Older Versions 
https://wingware.com/doc/install/migrating for a list of compatibility 
notes.



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


Re: nonlocal fails ?

2019-11-15 Thread Terry Reedy

On 11/15/2019 5:48 AM, R.Wieser wrote:


Closures are standard in functional languages and are less limited than
you seem to think.


I was talking about the "nonlocal" method of variable inheritance, not
closures.
You cannot really separate the two.  A 'nonlocal' declaration can only 
be used in a nested function, and when you do, the function becomes a 
closure (a function with a '__closure__' attribute that is not None).



--
Terry Jan Reedy

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


Speeding up a test process with a local pypi and/or web proxy?

2019-11-15 Thread Dan Stromberg
Hi folks.

I'm looking at a test process that takes about 16 minutes for a full run.

Naturally, I'd like to speed it up.  We've already parallelized it - mostly.

It seems like the next thing to look at is setting up a local pypi, and
building some of the packages that're compiled from C/C++ every time we do
a full test run.  (We're using docker and building dependencies for each
full test run)

Also, we could conceivably set up a web proxy...?

Does having a local pypi obviate the web proxy?

And what local pypi servers do folks recommend for speed?

We need support mostly for CPython 3.x, but we still have a little CPython
2.x we require, and it's possible we'll need the 2.x for a while.

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


Re: What do you use for slides?

2019-11-15 Thread Dan Stromberg
I mostly use Libreoffice Impress, but I've also tried Google Slides.

I don't think Impress does syntax highlighting out of the box, but there's
a plugin that claims to.

Also, Google Slides purportedly supports highlighting just by
cut-and-pasting from a GUI editor/IDE with syntax highlighting.

HTH.

On Fri, Nov 15, 2019 at 9:38 AM Abdur-Rahmaan Janhangeer <
arj.pyt...@gmail.com> wrote:

> Greetings all,
>
> For slides i use https://yhatt.github.io/marp/, but sometimes i want a
> more
> stylish tool.
>
> What do you use for slides? (besides powerpoint + syntax highlighting
> included)
>
> Thanks!
>
> Abdur-Rahmaan Janhangeer
> http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ
> Mauritius
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to delay until a next increment of time occurs ?

2019-11-15 Thread Dietmar Schwertberger

On 14.11.2019 21:00, R.Wieser wrote:

There is a small 433 MHz rf transmitter connected to the pin, and when I
send the right pattern a wireless wall-wart will respond and switch a lamp
on or off. Its just ment as an example of a real-world application of
Python, nothing serious.


I would assume that this is not an application that needs to output a 
100% correct pulse train every time. (Based on the assumption that the 
telegrams for on and off are different enough.)

You may just repeat the pattern ten times to be safe enough.
Combine it with a light sensor for feedback ;-)

Btw. you may want to increase the priority of your task. I'm using this 
code on my Raspi to reduce the interference of other processes with my 
media player using Python with gstreamer:


os.system( "sudo renice -15 -p %d"%os.getpid() )


Anyway, Micropython on a microcontroller would probably be the best 
solution.


Regards,

Dietmar


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


Re: nonlocal fails ?

2019-11-15 Thread Gregory Ewing

On 16/11/19 8:22 am, Chris Angelico wrote:

That's the typical sort of description you get from someone who mostly
understands Python's semantics, but is hung up on the idea that
everything is either call-by-value or call-by-reference, and is trying
to figure out which box Python fits into.


Or they may have read the definition of "call by value" in the
Algol60 report, which says that "The actual parameter expression
is evaluated and the result is assigned to the formal parameter."
Which is exactly what Python does...

(Notably, that definition doesn't contain the word "value" at all.
So people who argue about the meaning of "call by value" based
on the meaning of "value" are barking in the wrong direction.)

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


Re: nonlocal fails ?

2019-11-15 Thread Chris Angelico
On Sat, Nov 16, 2019 at 5:41 PM Gregory Ewing
 wrote:
>
> On 16/11/19 8:22 am, Chris Angelico wrote:
> > That's the typical sort of description you get from someone who mostly
> > understands Python's semantics, but is hung up on the idea that
> > everything is either call-by-value or call-by-reference, and is trying
> > to figure out which box Python fits into.
>
> Or they may have read the definition of "call by value" in the
> Algol60 report, which says that "The actual parameter expression
> is evaluated and the result is assigned to the formal parameter."
> Which is exactly what Python does...
>

This is 100% true, but actually just punts on the question of
"call-by-X". All the subtleties are bound up in this little bit:

> the result is **assigned** to the formal parameter

Which is actually a really REALLY good way to start peeling things
back. In Python - and in many many other languages - the semantics of
function calls can be summarized as assignment. You evaluate an
expression in the caller's context, and assign the result to a local
name in the callee's context. So far, C and Python both have the exact
same semantics.

So the real question is: What is assignment? And that's where
everything about name binding comes in. In C, that assignment operates
on a bit-copying level, cloning some value (which might be a pointer).
In Python, that same assignment operates as a name binding, giving the
target a reference to some particular object.

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


Re: How to delay until a next increment of time occurs ?

2019-11-15 Thread R.Wieser
Dietmar,

> I would assume that this is not an application that needs to output a 100% 
> correct pulse train every time.

Correct.   Thats in the design of the pulses themselves  (25% duticycle for 
one state, 75% for the other. Lots of leeway, and self synchronising)

> You may just repeat the pattern ten times to be safe enough.

:-) I was already doing exactly that.

> Combine it with a light sensor for feedback ;-)

Well ... I see a few problems with that.  Some when I would keep the light 
sensor next to the Pi, and others when I place it next to the lamp. :-p

> Btw. you may want to increase the priority of your task.
...
> os.system( "sudo renice -15 -p %d"%os.getpid() )

Thanks.  That should help the reduce the jitter.

> Anyway, Micropython on a microcontroller would probably be the best 
> solution.

My language of choice would probably be Assembly, but yes.  An (atmel) 
attiny16 (8 pin, 5 free to use) should be enough for it.

But  first experiment the heck outof the Pi to see how well it can do on 
its own. :-)

Regards,
Rudy Wieser


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