Re: Binary Sort on Python List __xor__

2020-05-31 Thread Peter Otten
[email protected] wrote:

> I frequently use binary as bool placeholders and find myself filtering
> lists based on those bools, this seems to have a similar semantic meaning
> as the bit wise ^ or __xor__ operator and could add syntactic sugar to the
> base list class.
> 
> Use Case:
> 
> Controlling a stepper at half-step has the following cycle steps:
> 
> CYCLE = [
>   [1,0,0,0],
>   [1,1,0,0],
>   [0,1,0,0],
>   [0,1,1,0],
>   [0,0,1,0],
>   [0,0,1,1],
>   [0,0,0,1],
>   [1,0,0,1],
> ]
> 
> which can be represented as follows:
> 
> CYCLE = [
> 1<<3,
> 1<<3|1<<2,

[...]

> on a raspberrypi, using (for illustration's sake) GPIO pins 1,2,3,4 I'd
> like to use the __xor__ method (currently not implemented) to perform the
> bit-wise filter as follows:

Python isn't C;)

A matrix of booleans  *can* be expressed using bit twiddling, but I don't 
see the point.

Just the other day I read that raspis now come with up to 8 GB memory.

Here's an alternative:

>>> import numpy
>>> CYCLE = [
...   [1,0,0,0],
...   [1,1,0,0],
...   [0,1,0,0],
...   [0,1,1,0],
...   [0,0,1,0],
...   [0,0,1,1],
...   [0,0,0,1],
...   [1,0,0,1],
... ]
>>> cycle = numpy.array(CYCLE, dtype=bool)
>>> cycle
array([[ True, False, False, False],
   [ True,  True, False, False],
   [False,  True, False, False],
   [False,  True,  True, False],
   [False, False,  True, False],
   [False, False,  True,  True],
   [False, False, False,  True],
   [ True, False, False,  True]], dtype=bool)
>>> numpy.where(cycle[1])
(array([0, 1]),)

That's zero-based indexing, as it should be; you can convert with

>>> numpy.where(cycle[1])[0] + 1
array([1, 2])

or (similar to your list subclass) you can pick arbitrary values:

>>> labels = np.array(["first", "second", "third", "fourth"])
>>> labels[cycle[0]]
array(['first'], 
  dtype='>> labels[cycle[1]]
array(['first', 'second'], 
  dtype='https://mail.python.org/mailman/listinfo/python-list


Re: I cannot download python files from external source.

2020-05-31 Thread MRAB

On 2020-05-31 15:36, Michio Suginoo wrote:

Thanks MRAB,

I try to download the external file in .ipynb.
And I get the message attached herewith.

And this is not the first time, it has been like this. And I have 
never been able to download any python file.

I just wonder if it has anything to do with the setting of my computer.

As I've already said, that's just the installer. It isn't used to 
download files.


Where is the file? Is it on a website? If yes, download it using a browser.

Here's an example:

https://www.usna.edu/Users/math/uhan/sa421/2014f/ipynb-download.html


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


Re: Binary Sort on Python List __xor__

2020-05-31 Thread Evan Schalton
Peter,

This isn't a ram consideration as much it's a logical consideration. There are 
a lot of ways to handle this, I REALLY don't want to use a package here. Bit 
masking is incredibly useful for permutations/combinatoric algorithms. I can 
create my own class wrapper or functions, and optimize, but think that the 
__and__ operator would be a really useful syntactic tool. It would streamline 
these types of operations and *hopefully* help people write more efficient code.

I'm less strictly interested in the & operator explicitly working with a bit 
int, but think it'd be great if the was a built-in filter something like:

[1,2,3,4] & [0,0,1,1] => [3,4] OR
[1,2,3,4] & [False, False, True, True] = [3,4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I cannot download python files from external source.

2020-05-31 Thread Evan Schalton
Michio,

Are you trying to open the ipynb file with python? You need Jupyter Notebook to 
run ipynb files. Try installing jupyter notebook (cmd: pip install jupyter) 
then launching the jupyter notebook py server (cmd: jupyter notebook). You 
should be able to use the file browser in the notebook window to open the file.

I'm not sure about your familiarity with Jupyter/python, sorry if this is off 
base.

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


Re: Binary Sort on Python List __xor__

2020-05-31 Thread Peter Otten
Evan Schalton wrote:

> Peter,
> 
> This isn't a ram consideration as much it's a logical consideration. There
> are a lot of ways to handle this, I REALLY don't want to use a package
> here. Bit masking is incredibly useful for permutations/combinatoric
> algorithms. I can create my own class wrapper or functions, and optimize,
> but think that the __and__ operator would be a really useful syntactic
> tool. It would streamline these types of operations and *hopefully* help
> people write more efficient code.
> 
> I'm less strictly interested in the & operator explicitly working with a
> bit int, but think it'd be great if the was a built-in filter something
> like:
> 
> [1,2,3,4] & [0,0,1,1] => [3,4] OR
> [1,2,3,4] & [False, False, True, True] = [3,4]

But, but, but...
for numpy arrays this is done regularly, and the established way to spell it 
is

>>> a = np.array([1,2,3,4])
>>> b = np.array([False, False, True, True])
>>> a[b]
array([3, 4])

rather than a & b

whereas for lists IMO it's a fringe application.
I may be influenced by numpy's example, but I'd expect

[1, 2, 3, 4] & [0, 0, 1, 1] --> [0, 0, 1, 0]

i. e. bitwise per-element and.

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


Re: Binary Sort on Python List __xor__

2020-05-31 Thread Evan Schalton
I think you're arguing both sides of the argument -- numpy arrays do have a lot 
of similar, related operations (because numpy uses them internally -- since 
they're more efficient) which means they're not fringe.

I'm advocating that the built-in list class add the efficient, convenience 
methods -- especially since it wouldn't be overriding other methods, it would 
be leveraging standard methods that are currently unimplemented 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [RELEASE] Python 3.9.0b1 is now available for testing

2020-05-31 Thread Robin Becker

I used https://github.com/python/pyperformance pyperformance to compare Arch 
linux latest

Python 3.8.3 (default, May 17 2020, 18:15:42) 
[GCC 10.1.0] on linux

Type "help", "copyright", "credits" or "license" for more information.




against a vanilla build (configure make makeinstall) of python 3.9b1

Python 3.9.0b1 (default, May 19 2020, 21:09:14) 
[GCC 10.1.0] on linux

Type "help", "copyright", "credits" or "license" for more information.




I find all the bench marks seem to be slower in python 3.9b1.


38.json
===

Performance version: 1.0.1
Report on Linux-5.6.14-arch1-1-x86_64-with-glibc2.2.5
Number of logical CPUs: 4
Start date: 2020-05-31 04:00:24.503704
End date: 2020-05-31 04:22:44.961331

39.json
===

Performance version: 1.0.1
Report on Linux-5.6.14-arch1-1-x86_64-with-glibc2.31
Number of logical CPUs: 4
Start date: 2020-05-31 04:23:21.247268
End date: 2020-05-31 04:49:09.891889

### 2to3 ###
Mean +- std dev: 437 ms +- 5 ms -> 548 ms +- 7 ms: 1.25x slower
Significant (t=-96.22)

### chameleon ###
Mean +- std dev: 12.5 ms +- 0.1 ms -> 16.2 ms +- 0.2 ms: 1.30x slower
Significant (t=-111.53)

> ...

Is this because I haven't built in the same way as Arch or are there real slowdowns in this beta? Or even dumber have I 
got the results the wrong way round?

--
Robin Becker

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


Re: I cannot download python files from external source.

2020-05-31 Thread Michio Suginoo
Hi Evan,

Thanks for your explaining the situation in a plain language.
Thanks to your description, I have a better understanding.

This is one step forward.
I will try to open it from Jupyter Notebook.

If I still have trouble, I might get back to this list. Then, if you can
further advise me from there, I would appreciate it.

Thanks for now.

Best regards
Michio

On Sun, May 31, 2020 at 1:43 PM Evan Schalton 
wrote:

> Michio,
>
> Are you trying to open the ipynb file with python? You need Jupyter
> Notebook to run ipynb files. Try installing jupyter notebook (cmd: pip
> install jupyter) then launching the jupyter notebook py server (cmd:
> jupyter notebook). You should be able to use the file browser in the
> notebook window to open the file.
>
> I'm not sure about your familiarity with Jupyter/python, sorry if this is
> off base.
>
> -E
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I cannot download python files from external source.

2020-05-31 Thread Michio Suginoo
Thanks MRAB

Sorry that I did not fully understand your previous message. I have been
learning Python within the system of an online course provider.
This is my new attempt to use Python outside of the system and everything
about the operating environment is very new to me.

Thanks

On Sun, May 31, 2020 at 12:48 PM MRAB  wrote:

> On 2020-05-31 15:36, Michio Suginoo wrote:
> > Thanks MRAB,
> >
> > I try to download the external file in .ipynb.
> > And I get the message attached herewith.
> >
> > And this is not the first time, it has been like this. And I have
> > never been able to download any python file.
> > I just wonder if it has anything to do with the setting of my computer.
> >
> As I've already said, that's just the installer. It isn't used to
> download files.
>
> Where is the file? Is it on a website? If yes, download it using a browser.
>
> Here's an example:
>
> https://www.usna.edu/Users/math/uhan/sa421/2014f/ipynb-download.html
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Spotify Playlist

2020-05-31 Thread giovanni . braschi2
Hi everyone,



first of all I must say I'm NOT a Python expert. In reality, I've never even 
used Python, but I know that it is a super powerful tool, useful in many 
contexts, also in Spotify.

2nd disclaimer: English is not my first language so I'll try to explain what I 
want to ask in the best way possible.

So, this is my problem:



I am a playlist curator on Spotify, with more than 50.000 followers over all 
through out all my playlist.

Lately, people started falsely reporting playlists on Spotify to gain a better 
rank in Spotify search algorithm. (if you search on the web, you will find that 
is becoming more and more common)

Each time a playlist is reported, the title, description and image disappear 
BEFORE the Spotify team check if the report is actually true or not. You will 
understand that this leads to a MASSIVE abuse of this tool, you just need to 
fill a form with name, telephone number and email and you can make this report. 
Obviously, people are filling this form with fake mails and identities.

This means that a fraudulent user can report your playlist 1000 times a 
day, and there is nothing you can do against it, because if Spotify bans his 
fake "mail" he will fill the form with another fake email. This also means that 
if the reporter flag my playlist 10.000 times, I have to rewrite title, caption 
and upload user 10.000 times, and it is absolutely absurd. I sent hundreds of 
mail to the spotify team, they told me they are working to fix it, but 
currently there is no way to stop this (THIS IS CRAZY!)



So my question is: is there a way to create a code with Python, that auto 
rewrite the title of a playlist each time Python sees the title has disappeared?



For example:

The reporter reports my playlist --> Title, Description and Image are gone 
(until I don't rewrite them again)

Python notices that the title is gone and automatically rewrite the title and 
caption



Do you think this is possible?



I am willing to pay for someone making this code for me, because these fake 
reports are becoming more and more frequent, and as a music blogger, Spotify 
Playlists are a part of my income. I can't stay 24/7 at home rewriting the 
titles of my falsely reported playlist (with no reason)



Hope this was clear enough, thank you!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Spotify Playlist

2020-05-31 Thread Chris Angelico
On Mon, Jun 1, 2020 at 8:34 AM  wrote:
> This means that a fraudulent user can report your playlist 1000 times a 
> day, and there is nothing you can do against it, because if Spotify bans his 
> fake "mail" he will fill the form with another fake email. This also means 
> that if the reporter flag my playlist 10.000 times, I have to rewrite title, 
> caption and upload user 10.000 times, and it is absolutely absurd. I sent 
> hundreds of mail to the spotify team, they told me they are working to fix 
> it, but currently there is no way to stop this (THIS IS CRAZY!)
>

Yes. That is crazy. Spotify needs to fix that. However, in the meantime...

> So my question is: is there a way to create a code with Python, that auto 
> rewrite the title of a playlist each time Python sees the title has 
> disappeared?
>
> For example:
> The reporter reports my playlist --> Title, Description and Image are gone 
> (until I don't rewrite them again)
>
> Python notices that the title is gone and automatically rewrite the title and 
> caption
>
> Do you think this is possible?
>

Hmm. Leaving aside the automation part, I think it's going to be
possible. You'd need to have a file somewhere with a list of your
playlists and their Spotify IDs, and the desired titles and captions,
and then a program that uses the Spotify API to reapply those details:
https://developer.spotify.com/documentation/web-api/reference/playlists/change-playlist-details/

And for the cover image:
https://developer.spotify.com/documentation/web-api/reference/playlists/upload-custom-playlist-cover/

Automation would be a bit harder, as you'd have to periodically query
the API for each playlist's description, and then update them.
https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlist/

The reason this would be harder is that you'd risk running up against
the rate limits:
https://developer.spotify.com/documentation/web-api/#rate-limiting

But that's a matter of striking a balance between how much you use the
API and how quickly you notice a problem. Initially, just having
something that you manually run would be fairly straight-forward, and
should still be of value.

> I am willing to pay for someone making this code for me, because these fake 
> reports are becoming more and more frequent, and as a music blogger, Spotify 
> Playlists are a part of my income. I can't stay 24/7 at home rewriting the 
> titles of my falsely reported playlist (with no reason)
>

Can't blame you!

I won't take on the job myself, but I fully support the notion :) To
whoever ends up picking this up, it'll be a pretty straight-forward
job of calling on an HTTP API.

All the best!

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


Re: why no camelCase in PEP 8?

2020-05-31 Thread Dennis Carachiola
>From PEP8--
"The guidelines provided here are intended to improve the readability of code 
and make it consistent across the wide spectrum of Python code. As PEP 20 says, 
"Readability counts".
A style guide is about consistency. Consistency with this style guide is 
important. Consistency within a project is more important. Consistency within 
one module or function is the most important.
However, know when to be inconsistent -- sometimes style guide recommendations 
just aren't applicable. When in doubt, use your best judgment. Look at other 
examples and decide what looks best. And don't hesitate to ask!
In particular: do not break backwards compatibility just to comply with this 
PEP!"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Binary Sort on Python List __xor__

2020-05-31 Thread Terry Reedy

On 5/31/2020 12:24 PM, Evan Schalton wrote:


I'm less strictly interested in the & operator explicitly working with a bit 
int, but think it'd be great if the was a built-in filter something like:



[1,2,3,4] & [0,0,1,1] => [3,4] OR
[1,2,3,4] & [False, False, True, True] = [3,4]


Leaving numpy aside, Python already has very flexible map and filter 
functions, and comprehensions encompassing both, that easily do both 
what *you* want:


>>> list(map(lambda x: x[0], filter(lambda x: x[1], zip([1,2,3,4], 
[0,0,1,1]

[3, 4]
>>> [x[0] for x in zip([1,2,3,4], [0,0,1,1]) if x[1]]
[3, 4]
# This illustrates why comprehensions were added.

and an infinity of related operations, that *others* may want or can 
imagine, such as:


>>> ''.join(c[1] for c in enumerate('every third char') if not c[0] % 3)
'ertrcr'

Python 3, even more than Python 2, is designed to work with generic 
sequences and streams rather than just lists.
We would only add a specific list function if the function is specific 
to lists, and filtering a sequence of items according to a sequence of 
values treated as boolean values is definitely not.  Please drop the idea.


--
Terry Jan Reedy

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


Re: Spotify Playlist

2020-05-31 Thread Terry Reedy

On 5/31/2020 7:10 PM, Chris Angelico wrote:

On Mon, Jun 1, 2020 at 8:34 AM  wrote:

This means that a fraudulent user can report your playlist 1000 times a day, and 
there is nothing you can do against it, because if Spotify bans his fake "mail" 
he will fill the form with another fake email. This also means that if the reporter flag 
my playlist 10.000 times, I have to rewrite title, caption and upload user 10.000 times, 
and it is absolutely absurd. I sent hundreds of mail to the spotify team, they told me 
they are working to fix it, but currently there is no way to stop this (THIS IS CRAZY!)



Yes. That is crazy. Spotify needs to fix that. However, in the meantime...


So my question is: is there a way to create a code with Python, that auto 
rewrite the title of a playlist each time Python sees the title has disappeared?

For example:
The reporter reports my playlist --> Title, Description and Image are gone 
(until I don't rewrite them again)

Python notices that the title is gone and automatically rewrite the title and 
caption

Do you think this is possible?


Python has tools to both make html requests and extract and decode json 
responses.  (And to parse standard timestamps.)



Hmm. Leaving aside the automation part, I think it's going to be
possible. You'd need to have a file somewhere with a list of your
playlists and their Spotify IDs, and the desired titles and captions,
and then a program that uses the Spotify API to reapply those details:
https://developer.spotify.com/documentation/web-api/reference/playlists/change-playlist-details/

And for the cover image:
https://developer.spotify.com/documentation/web-api/reference/playlists/upload-custom-playlist-cover/

Automation would be a bit harder, as you'd have to periodically query
the API for each playlist's description, and then update them.
https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlist/

The reason this would be harder is that you'd risk running up against
the rate limits:
https://developer.spotify.com/documentation/web-api/#rate-limiting


Their recommendation is to query infomation about multiple items at 
once, as their API allows.  I suspect that one can also add or update 
multiple items at once.


There is also a mechanism to ask whether locally cached information has 
changed by sending a cache tag, but I could not tell if that would apply 
to your situation.



But that's a matter of striking a balance between how much you use the
API and how quickly you notice a problem. Initially, just having
something that you manually run would be fairly straight-forward, and
should still be of value.


I am willing to pay for someone making this code for me, because these fake 
reports are becoming more and more frequent, and as a music blogger, Spotify 
Playlists are a part of my income. I can't stay 24/7 at home rewriting the 
titles of my falsely reported playlist (with no reason)



Can't blame you!

I won't take on the job myself, but I fully support the notion :) To
whoever ends up picking this up, it'll be a pretty straight-forward
job of calling on an HTTP API.


Let us hope that you can find a Python Web (REST) programmer who uses 
Spotify, and perhaps angered by the current abuse.


--
Terry Jan Reedy

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


Re: OT: ALGOL 60 at 60

2020-05-31 Thread Dennis Carachiola
Ah, but I have used it.  Admittedly it was during a programming languages 
survey course at RPI in 1971-3.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Spotify Playlist

2020-05-31 Thread Chris Angelico
On Mon, Jun 1, 2020 at 2:55 PM Terry Reedy  wrote:
>
> On 5/31/2020 7:10 PM, Chris Angelico wrote:
> > Automation would be a bit harder, as you'd have to periodically query
> > the API for each playlist's description, and then update them.
> > https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlist/
> >
> > The reason this would be harder is that you'd risk running up against
> > the rate limits:
> > https://developer.spotify.com/documentation/web-api/#rate-limiting
>
> Their recommendation is to query infomation about multiple items at
> once, as their API allows.  I suspect that one can also add or update
> multiple items at once.

I'm not sure, but that doesn't even matter. The question is more about
how frequently you can query to see if it's been wiped. But that might
be irrelevant, depending on exactly how high the rate limits are - I
didn't check. (If you're allowed, say, 1500 calls per day, then you
could poll every minute and still be fine.)

But I only did a very cursory examination. A feasibility test, the
results of which are that I'd be confident putting this project in the
hands of a competent novice programmer.

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