[ANN] New version 2.1.0 of L.Pointal's Python 3 Cheat Sheet

2025-05-14 Thread Laurent Pointal via Python-list
Hello, In the context of a move for hosting of my one recto-verso pdf cheat sheet, I updated it to add Python's news stuff and make a new 2.1.0 version (latest version, 2.0.6, was from 2017). DOWNLOAD English version is at https://py3cheatsheet.lisn.fr/ (its a short URL fore real host

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

2023-10-24 Thread Chris Angelico via Python-list
On Wed, 25 Oct 2023 at 13:02, Mike H via Python-list wrote: > Is it possible to use lambda expression instead of defining a `Key` class? > Something like `sorted(my_list, key = lambda x, y: x+y > y+x)`? Look up functools.cmp_to_key. ChrisA -- https://mail.python.org/mailman/listinfo/python-lis

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

2023-10-24 Thread Mike H via Python-list
gt; > '953433230' > > > > nums.sort(cmp=lambda a,b: cmp(a+b, b+a), reverse=True) > > > > But how to do this in python 3? > > > > Thank you > While cmp_to_key is neat doing it by hand should also be instructive. > Essentially you move the comp

Re: How to decode ISO8859-1 in Python 3?

2021-11-28 Thread Chris Green
Stefan Ram wrote: > Chris Green writes: > >I have some text files which are ISO8859-1 encoded and I want to output > >them to screen using Python. > > Well, the first attempt would be: > > import pathlib > name = r"C:\example.txt" > encoding = r"iso8859-1" > path = pathlib.Path( name ) > with

How to decode ISO8859-1 in Python 3?

2021-11-28 Thread Chris Green
This sounds as if it should be trivial but searching only seems to produce ways ofd doing it in Python 2. I have some text files which are ISO8859-1 encoded and I want to output them to screen using Python. -- Chris Green · -- https://mail.python.org/mailman/listinfo/python-list

Re: How to iterate through maildir messages in python 3?

2021-06-27 Thread Chris Green
Dennis Lee Bieber wrote: > On Fri, 25 Jun 2021 09:19:49 +0100, Chris Green declaimed the > following: > > > > >Here's the full program where I'm encountering the error (yes, I > >should have posted this first time around) :- > > > >#!/usr/bin/python3 > > > >import mailbox > >import s

Re: How to iterate through maildir messages in python 3?

2021-06-26 Thread Chris Green
gt; >print msg # or whatever you want to do with the message > > > > > > > > > > > > However in python 3 this produces "TypeError: string argument > > > > expected, got 'bytes'". > > > > > > >

Re: How to iterate through maildir messages in python 3?

2021-06-25 Thread Chris Angelico
do with the message > > > > > > > > > However in python 3 this produces "TypeError: string argument > > > expected, got 'bytes'". > > > > > > How should one iterate over a maildir in python3? > > > > You're alre

Re: How to iterate through maildir messages in python 3?

2021-06-25 Thread Chris Green
Gilmeh Serda wrote: > On Fri, 25 Jun 2021 09:19:49 +0100, Chris Green wrote: > > > TypeError: string argument expected, got 'bytes' > > couple things comes to mind: > > 1. find py2 as archive, put it somewhere and run it from that > Hmm! :-) > 2. convert the bytes to str (find and replace) >

Re: How to iterate through maildir messages in python 3?

2021-06-25 Thread Chris Green
Greg Ewing wrote: > On 25/06/21 7:06 am, Chris Green wrote: > > In python 2 one can do:- > > > > for msg in maildir: > >print msg # or whatever you want to do with the message > > > > > > However in python 3 this produces

How to iterate through maildir messages in python 3?

2021-06-24 Thread Chris Green
In python 2 one can do:- for msg in maildir: print msg # or whatever you want to do with the message However in python 3 this produces "TypeError: string argument expected, got 'bytes'". How should one iterate over a maildir in python3? (I've

Re: How to iterate through maildir messages in python 3?

2021-06-24 Thread Greg Ewing
On 25/06/21 7:06 am, Chris Green wrote: In python 2 one can do:- for msg in maildir: print msg # or whatever you want to do with the message However in python 3 this produces "TypeError: string argument expected, got 'bytes'". How should one itera

Re: Retrieving non-/etc/passwd users with Python 3?

2021-03-31 Thread Loris Bennett
tall the PyPi package >>>> >>>> getent >>>> >>>> I get the error >>>> >>>> File "/tmp/pip-build-vu4lziex/getent/setup.py", line 9, in >>>> long_description = file('README.rst').read(), >>&

Re: Retrieving non-/etc/passwd users with Python 3?

2021-03-31 Thread Christian Heimes
t the error >>> >>> File "/tmp/pip-build-vu4lziex/getent/setup.py", line 9, in >>> long_description = file('README.rst').read(), >>> NameError: name 'file' is not defined >>> >>> I duckduckwent a bit and the probl

Re: Retrieving non-/etc/passwd users with Python 3?

2021-03-31 Thread Loris Bennett
long_description = file('README.rst').read(), >> NameError: name 'file' is not defined >> >> I duckduckwent a bit and the problem seems to be that 'file' from Python >> 2 has been replaced by 'open' in Python 3. >> >> S

Re: Retrieving non-/etc/passwd users with Python 3?

2021-03-31 Thread Chris Angelico
27; is not defined > > I duckduckwent a bit and the problem seems to be that 'file' from Python > 2 has been replaced by 'open' in Python 3. > > So what's the standard way of getting a list of users in this case? > I don't have LDAP experience so I don

Retrieving non-/etc/passwd users with Python 3?

2021-03-31 Thread Loris Bennett
File "/tmp/pip-build-vu4lziex/getent/setup.py", line 9, in long_description = file('README.rst').read(), NameError: name 'file' is not defined I duckduckwent a bit and the problem seems to be that 'file' from Python 2 has been replaced by

Re: SSL/TLS certificate verification suddenly broken, Python 3 on Windows 10

2021-02-16 Thread Michał Jaworski
I’ve had similar issue today on macOS when trying to download something from PyPI with Python 3.9.1 but I didn’t try to debug it and just moved on to different things. Maybe we both have outdated ca bundles? Michał Jaworski > Wiadomość napisana przez Carlos Andrews w dniu > 16.02.2021, o godz

SSL/TLS certificate verification suddenly broken, Python 3 on Windows 10

2021-02-16 Thread Carlos Andrews
Hi All, I ran into an error I, so far, cannot explain regarding Python's general ability to communicate via SSL/TLS. I'm using Python a lot to communicate with web servers and APIs, which worked just fine until yesterday (or somewhen late last week). I first noticed yesterday, when a requests-ba

Re: Python 2 to Python 3 .so library incompatibility - need help

2020-12-17 Thread Michał Jaworski
r, I wouldn't even try to port that to Python 3. First, it would be clearly against the licence agreement. Second, that would probably result in total mess and take more time that it takes to earn for a new printer. If you really want to keep the printer (I wouldn't) I would do the follo

Re: Python 2 to Python 3 .so library incompatibility - need help

2020-12-17 Thread Chris Green
system. > Aside from whinging about systemd it installed ok. How do I reproduce > your problems? (I've got no printer of course, but...) > Try running scantool.py, that should pop up a little GUI. It uses GTK which of course in itself makes migration tricky because one has to m

Re: Python 2 to Python 3 .so library incompatibility - need help

2020-12-16 Thread Cameron Simpson
;as I don't have the source, I can't build for Python 3. >> >> ChrisA I think suggested keeping a Python 2.7 install around for this. >> >Not possible really as there are other python conflicts that start >appearing if one tries to retain the libraries needed. Ru

Re: Python 2 to Python 3 .so library incompatibility - need help

2020-12-16 Thread Chris Angelico
me from a PPA to support Python GTK, these conflict with > ongoing updates to Python. The PPA works OK in Ubuntu 20.04 but > prevents some updates in 20.10. I expect it will get worse as time > goes on. > Try getting JUST the printer info in Python 2, and then outputting that to stdou

Re: Python 2 to Python 3 .so library incompatibility - need help

2020-12-16 Thread Chris Green
Cameron Simpson wrote: > On 16Dec2020 18:51, Chris Green wrote: > >The specific problem that finally prevented me from managing to get it > >to work was a (Linux) .so file that had been built for Python 2 and, > >as I don't have the source, I can't build fo

Re: Python 2 to Python 3 .so library incompatibility - need help

2020-12-16 Thread Chris Angelico
the source, I can't build for Python 3. > > ChrisA I think suggested keeping a Python 2.7 install around for this. (MRAB did, but I agree with it.) ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Python 2 to Python 3 .so library incompatibility - need help

2020-12-16 Thread Cameron Simpson
On 16Dec2020 18:51, Chris Green wrote: >The specific problem that finally prevented me from managing to get it >to work was a (Linux) .so file that had been built for Python 2 and, >as I don't have the source, I can't build for Python 3. ChrisA I think suggested keeping a

Re: Python 2 to Python 3 .so library incompatibility - need help

2020-12-16 Thread Chris Angelico
On Thu, Dec 17, 2020 at 7:27 AM MRAB wrote: > > On 2020-12-16 19:16, Chris Angelico wrote: > > On Thu, Dec 17, 2020 at 6:06 AM Chris Green wrote: > >> > >> Some time ago (in July) I asked some questions here > >> about problems migrating some code f

Re: Python 2 to Python 3 .so library incompatibility - need help

2020-12-16 Thread MRAB
On 2020-12-16 19:16, Chris Angelico wrote: On Thu, Dec 17, 2020 at 6:06 AM Chris Green wrote: Some time ago (in July) I asked some questions here about problems migrating some code from Python 2 to Python 3. The specific problem that finally prevented me from managing to get it to work was a

Re: Python 2 to Python 3 .so library incompatibility - need help

2020-12-16 Thread Chris Angelico
On Thu, Dec 17, 2020 at 6:06 AM Chris Green wrote: > > Some time ago (in July) I asked some questions here > about problems migrating some code from Python 2 to Python 3. > > The specific problem that finally prevented me from managing to get it > to work was a (Linux) .so

Python 2 to Python 3 .so library incompatibility - need help

2020-12-16 Thread Chris Green
Some time ago (in July) I asked some questions here about problems migrating some code from Python 2 to Python 3. The specific problem that finally prevented me from managing to get it to work was a (Linux) .so file that had been built for Python 2 and, as I don't have the source, I can&#x

Re: Python 3

2020-11-07 Thread Hernán De Angelis
Hi, Wikipedia has an article on the duodecimal system, that includes an explanation of how to convert from decimal and the other way around. https://en.wikipedia.org/wiki/Duodecimal?wprov=sfla1 Peerrhaps it can be easily implemented as a function. Good luck. H. Den lör 7 nov. 2020 07:55Nick

Re: Python 3

2020-11-07 Thread Barry Scott
> On 7 Nov 2020, at 06:51, Nick Li wrote: > > Does anyone know how to turn a decimal number into duodecimal or if there is > a function built-in for it? I see lots of interesting answer in here: https://stackoverflow.com/questions/2267362/how-to-convert-an-integer-to-a-string-in-any-base

Python 3

2020-11-06 Thread Nick Li
Does anyone know how to turn a decimal number into duodecimal or if there is a function built-in for it? -- https://mail.python.org/mailman/listinfo/python-list

RE: Python 3..9.0

2020-10-09 Thread Schachner, Joseph
dle, it's there in your Python installation. Or download PyScripter, or Jetbrains' PyCharm, or Wing (see recent new version announcement). --- Joseph S. -Original Message- From: jjall...@aol.com Sent: Thursday, October 8, 2020 12:59 PM To: python-list@python.org Subject

Re: Fwd: Python 3..9.0

2020-10-09 Thread Sibylle Koczian
Am 08.10.2020 um 18:58 schrieb Joe via Python-list: Hi, I just downloaded the above for Windows but am unable to get it to run.  I have gone to the directory and double-clicked the "python.exe" file but that just brings me to the command prompt. Any suggestions as to what I am doing wrong? Tha

Fwd: Python 3..9.0

2020-10-09 Thread Joe via Python-list
Hi, I just downloaded the above for Windows but am unable to get it to run.  I have gone to the directory and double-clicked the "python.exe" file but that just brings me to the command prompt. Any suggestions as to what I am doing wrong? Thank you. Joe -- https://mail.python.org/mailman/listin

wxpython-OGL fails to render objects with Python-3

2020-09-17 Thread Frank Miles
h Py3, Py2 works properly). I have cut the code to a pretty minimum set and will attempt to paste it to the bottom of this message in the hope that it will encourage one of you to see what the problem might be. Alternatively if anyone knows of an example that works with Python-3 I'd be de

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-30 Thread Chris Green
Cameron Simpson wrote: > On 29Aug2020 16:50, Chris Green wrote: > >However the problem appears to be that internally in Python 3 mailbox > >class there is an assumption that it's being given 'ascii'. Here's > >the error (and I'm doing no processing

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-30 Thread Chris Green
Karsten Hilbert wrote: > > However the problem appears to be that internally in Python 3 mailbox > > class there is an assumption that it's being given 'ascii'. > > Do you really _need_ the mailbox class ? From what you've > written so far my understandin

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-29 Thread Cameron Simpson
On 29Aug2020 16:50, Chris Green wrote: >However the problem appears to be that internally in Python 3 mailbox >class there is an assumption that it's being given 'ascii'. Here's >the error (and I'm doing no processing of the message at all):- > >Traceb

Aw: Re: Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-29 Thread Karsten Hilbert
> Just appending a message as a raw file to a mailbox, doesn't properly > add it as a new message. You need to add a From: line to the front, and > then go through the message and alter any line that begins as "From:" > (and possibly any line that begins with something like ">From:" or > ">>From:"

Re: Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-29 Thread Richard Damon
On 8/29/20 3:31 PM, Karsten Hilbert wrote: >> However the problem appears to be that internally in Python 3 mailbox >> class there is an assumption that it's being given 'ascii'. > Do you really _need_ the mailbox class ? From what you've > written so far my u

Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-29 Thread Karsten Hilbert
> However the problem appears to be that internally in Python 3 mailbox > class there is an assumption that it's being given 'ascii'. Do you really _need_ the mailbox class ? From what you've written so far my understanding was that you receive data (bytes) and wan

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-29 Thread Richard Damon
", and using the >>> methods of the bytes data type. >>> >> Now I'm beginning to realise that *this* may well be what I need to >> do, after going round in several convoluted circles! :-) >> > However the problem appears to be that internall

Finally fixed my Python 2 to Python 3 e-mail problem

2020-08-29 Thread Chris Green
I've started a new thread because this relates to two or three threads I started here over the past few days. First, thank you everyone for all the help and suggestions. I've finally fixed the problem, it was due to sys.stdin.read() returning a string object in Python 3 as opposed t

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-29 Thread Chris Green
gt; any encoding. > > > > So, for Python3, the SAME processing requires NOT USING "string" > > (which > > is now Unicode) and ensuring that all literals are b"stuff", and using the > > methods of the bytes data type. > > > Now I&#x

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-29 Thread Chris Green
Dennis Lee Bieber wrote: > On Fri, 28 Aug 2020 12:26:07 +0100, Chris Green declaimed the > following: > > > > >Maybe I shouldn't but Python 2 has been managing to do so for several > >years without any issues. I know I *could* put the exceptions in a > >bucket somewhere and deal with them sep

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-29 Thread Grant Edwards
On 2020-08-28, Chris Green wrote: > Maybe I shouldn't but Python 2 has been managing to do so for several > years without any issues. I know I *could* put the exceptions in a > bucket somewhere and deal with them separately but I'd really rather > not. Then just leave it as bytes and do whateve

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-29 Thread Grant Edwards
On 2020-08-27, Chris Green wrote: > bbb = [b'aaa', b'bbb', b'ccc'] > sss = [] > for i in range(0, 2): > sss.append(str(bbb[i]) > > but that does seem a bit clumsy. Is there a better way? sss = [str(s) for s in bbb] -- Grant -- https://mail.python.org/mailman/listinfo/pyth

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-29 Thread Grant Edwards
On 2020-08-27, Marco Sulla wrote: > Are you sure you want `str()`? > str(b'aaa') > "b'aaa'" > > Probably you want: > > map(lambda x: x.decode(), bbb) If you're an old Scheme or Lisp programmer. :) This is probably the more usual way to spell it: sss = [x.decode() for x in bbb] -- ht

Re: Didn't understand the output of the following Python 3 code with reduce function?

2020-08-29 Thread Shivlal Sharma
On Saturday, 29 August 2020 at 02:47:56 UTC+5:30, Ben Bacarisse wrote: Thanks you all, I was really confused in this code. > Shivlal Sharma writes: > > > I have seen this code on one of competative programming site but I > > didn't get it, Why output is 9? > > > > from functools import * > >

Re: Didn't understand the output of the following Python 3 code with reduce function?

2020-08-28 Thread Ben Bacarisse
Shivlal Sharma writes: > I have seen this code on one of competative programming site but I > didn't get it, Why output is 9? > > from functools import * > > def ADDS(a,b): > return a+1 > nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] > add = reduce(ADDS, nums) > print(add) > > output: 9 Hint: reduce(f

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Cameron Simpson
Python 2 code still installed) it all 'just works' >and the absolute worst corruption I ever see in an E-Mail is things >like accented characters missing altogether or £ signs coming out as a >funny looking string. Either of these don't really make the message >unintelli

Re: Didn't understand the output of the following Python 3 code with reduce function?

2020-08-28 Thread Peter Otten
Shivlal Sharma wrote: > I have seen this code on one of competative programming site but I didn't > get it, Why output is 9? > > from functools import * > > def ADDS(a,b): > return a+1 > nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] > add = reduce(ADDS, nums) > print(add) > > output: 9 Rewrite the AD

RE: Didn't understand the output of the following Python 3 code with reduce function?

2020-08-28 Thread David Raymond
All the numbers in the nums list don't matter and aren't used. Only the first number, and how many there are. https://docs.python.org/3.8/library/functools.html#functools.reduce Basically it's doing ADDS(1, 2) which returns 2 that 2 gets fed back into ADDS(2, 3) which returns 3 that 3 gets fed ba

Didn't understand the output of the following Python 3 code with reduce function?

2020-08-28 Thread Shivlal Sharma
I have seen this code on one of competative programming site but I didn't get it, Why output is 9? from functools import * def ADDS(a,b): return a+1 nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] add = reduce(ADDS, nums) print(add) output: 9 -- https://mail.python.org/mailman/listinfo/python-list

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Richard Damon
ake a difference between "scoring" and "transport": >> >> To transfer a message into an mbox it can be transferred as it is. >> Just the bytes from the POP3 server. Let mutt deal with them. >> > That's what I do at present in Python 2, the problem is

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Chris Angelico
On Fri, Aug 28, 2020 at 11:24 PM Chris Green wrote: > > Chris Angelico wrote: > > > > Also, if you're parsing an email message, you can and should be doing > > so with respect to the encoding(s) stipulated in the headers, after > > which you will have valid Unicode text. > > > But not all E-Mail

Re: Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread D'Arcy Cain
On 2020-08-28 08:30, Richard Damon wrote: > This might be one of the cases where Python 2's lack handling of string > vs bytes was an advantage. For English speaking Americans. > Python2 handled that sort of case quite easily. Python 3 on the other > hand, will have issue co

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Chris Green
Chris Angelico wrote: > > Also, if you're parsing an email message, you can and should be doing > so with respect to the encoding(s) stipulated in the headers, after > which you will have valid Unicode text. > But not all E-Mail messages are 'well behaved', the above works fine if the headers sp

Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Karsten Hilbert
> I want to transport the message into my mbox and Python 3 won't do it > without knowing how it's encoded whereas Python 2 just stuffed it in > there 'as is'. > > I want Python 3's mailbox class to juyst put what I tell it (even if > mis-formatted or mis

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Richard Damon
ere were no issues because everything worked just right under >>> py2 but rather because py2 cared less than py3 does now. >>> >>>> Are we saying that Python 3 really can't be made to handle things >>>> 'tolerantly' like Python 2 used to? >

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Chris Angelico
On Fri, Aug 28, 2020 at 10:51 PM Chris Green wrote: > > > One possible solution in Python3 is to decode the byte string using an > > encoding that allows all 256 byte values, so it won't raise any encoding > > errors, just give your possibly non-sense characters for non-ASCII text. > > > But this

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Chris Green
> To transfer a message into an mbox it can be transferred as it is. > Just the bytes from the POP3 server. Let mutt deal with them. > That's what I do at present in Python 2, the problem is that Python 3 complains when I use the standard library to put the message into the mbox. I

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Chris Green
;> Maybe I shouldn't but Python 2 has been managing to do so for several > >> years without any issues. > > I am inclined to congratulate you on that sheer amount of luck. I don't > > believe there were no issues because everything worked just right under > &

Re: Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Chris Angelico
ite is unlikely to have been causing > problems. > > Python2 handled that sort of case quite easily. Python 3 on the other > hand, will have issue converting the byte message to a string, since > there isn't a single encoding that you could use for all of it all the > time

Re: Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Richard Damon
managing to do so for several >> years without any issues. > I am inclined to congratulate you on that sheer amount of luck. I don't > believe there were no issues because everything worked just right under > py2 but rather because py2 cared less than py3 does now. >

Re: Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Richard Damon
managing to do so for several >> years without any issues. > I am inclined to congratulate you on that sheer amount of luck. I don't > believe there were no issues because everything worked just right under > py2 but rather because py2 cared less than py3 does now. >

Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Karsten Hilbert
I am inclined to congratulate you on that sheer amount of luck. I don't believe there were no issues because everything worked just right under py2 but rather because py2 cared less than py3 does now. > Are we saying that Python 3 really can't be made to handle things > &#x

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Chris Green
> Maybe I shouldn't but Python 2 has been managing to do so for several years without any issues. I know I *could* put the exceptions in a bucket somewhere and deal with them separately but I'd really rather not. At prsent (with the Python 2 code still installed) it all 'just works' and the absolute worst corruption I ever see in an E-Mail is things like accented characters missing altogether or £ signs coming out as a funny looking string. Either of these don't really make the message unintelligible. Are we saying that Python 3 really can't be made to handle things 'tolerantly' like Python 2 used to? -- Chris Green · -- https://mail.python.org/mailman/listinfo/python-list

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Cameron Simpson
On 28Aug2020 08:56, Chris Green wrote: >Stefan Ram wrote: >> Chris Angelico writes: >> >But this is a really good job for a list comprehension: >> >sss = [str(word) for word in bbb] >> >> Are you all sure that "str" is really what you all want? >> >Not absolutely, you no doubt have been follow

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Chris Green
Cameron Simpson wrote: > On 27Aug2020 23:54, Marco Sulla wrote: > >Are you sure you want `str()`? > > > str(b'aaa') > >"b'aaa'" > > > >Probably you want: > > > >map(lambda x: x.decode(), bbb) > > _And_ you need to know the encoding of the text in the bytes. The above > _assumes_ UTF-8 beca

Re: How do I do this in Python 3 (string.join())?

2020-08-28 Thread Chris Green
hing that might be a typo for one of our names or anything else that might be of interest. I have an associated configuration file that specifies the patterns to look for so I can change things on the fly as it were. One of the scripts that I'm having trouble converting to Python 3 is the one that d

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Chris Green
Chris Angelico wrote: > On Fri, Aug 28, 2020 at 6:36 AM Chris Green wrote: > > > > This sounds quite an easy thing to do but I can't find how to do it > > elegantly. > > > > I have a list of bytes class objects (i.e. a list containing sequences > > of bytes, which are basically text) and I want t

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Chris Green
Stefan Ram wrote: > Chris Angelico writes: > >But this is a really good job for a list comprehension: > >sss = [str(word) for word in bbb] > > Are you all sure that "str" is really what you all want? > Not absolutely, you no doubt have been following other threads related to this one. :-)

Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Karsten Hilbert
> >Are you sure you want `str()`? > > > str(b'aaa') > >"b'aaa'" > > > >Probably you want: > > > >map(lambda x: x.decode(), bbb) > > _And_ you need to know the encoding of the text in the bytes. The above > _assumes_ UTF-8 because that is the default for bytes.decode, and if > that is _not_ wha

Re: How do I do this in Python 3 (string.join())?

2020-08-27 Thread Cameron Simpson
ing a new filing rule. >> >E.g. in this case the only (well the only ready made) way to get a >> >POP3 message is using poplib and this just gives you a list of lines >> >made up of "bytes as text" :- >> > >> >popmsg = pop3.retr(i+1) >&g

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-27 Thread Cameron Simpson
On 27Aug2020 23:54, Marco Sulla wrote: >Are you sure you want `str()`? > str(b'aaa') >"b'aaa'" > >Probably you want: > >map(lambda x: x.decode(), bbb) _And_ you need to know the encoding of the text in the bytes. The above _assumes_ UTF-8 because that is the default for bytes.decode, and if

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-27 Thread Marco Sulla
Are you sure you want `str()`? >>> str(b'aaa') "b'aaa'" Probably you want: map(lambda x: x.decode(), bbb) -- https://mail.python.org/mailman/listinfo/python-list

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-27 Thread Chris Angelico
On Fri, Aug 28, 2020 at 6:36 AM Chris Green wrote: > > This sounds quite an easy thing to do but I can't find how to do it > elegantly. > > I have a list of bytes class objects (i.e. a list containing sequences > of bytes, which are basically text) and I want to convert it to a list > of string ob

Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-27 Thread Chris Green
This sounds quite an easy thing to do but I can't find how to do it elegantly. I have a list of bytes class objects (i.e. a list containing sequences of bytes, which are basically text) and I want to convert it to a list of string objects. One of the difficulties of finding out how to do this is

Re: How do I do this in Python 3 (string.join())?

2020-08-27 Thread Chris Green
empties the POP3 catchall mailbox, checks for anything that *might* be for me or other family members then just deletes the rest. > >E.g. in this case the only (well the only ready made) way to get a > >POP3 message is using poplib and this just gives you a list of lines > >m

Re: How do I do this in Python 3 (string.join())?

2020-08-27 Thread Cameron Simpson
On 27Aug2020 09:16, Chris Green wrote: >Cameron Simpson wrote: >> But note: joining bytes like strings is uncommon, and may indicate >> that >> you should be working in strings to start with. Eg you may want to >> convert popmsg from bytes to str and do a str.join anyway. It depends on >> exactl

Re: How do I do this in Python 3 (string.join())?

2020-08-27 Thread Chris Green
Cameron Simpson wrote: > On 26Aug2020 15:09, Chris Green wrote: > >2qdxy4rzwzuui...@potatochowder.com wrote: > >> Join bytes objects with a byte object: > >> > >> b"\n".join(popmsg[1]) > > > >Aaahhh! Thank you (and the other reply). > > But note: joining bytes like strings is uncommon, and

Re: How do I do this in Python 3 (string.join())?

2020-08-26 Thread Cameron Simpson
On 26Aug2020 15:09, Chris Green wrote: >2qdxy4rzwzuui...@potatochowder.com wrote: >> Join bytes objects with a byte object: >> >> b"\n".join(popmsg[1]) > >Aaahhh! Thank you (and the other reply). But note: joining bytes like strings is uncommon, and may indicate that you should be working i

Re: How do I do this in Python 3 (string.join())?

2020-08-26 Thread Chris Green
2qdxy4rzwzuui...@potatochowder.com wrote: > On 2020-08-26 at 14:22:10 +0100, > Chris Green wrote: > > > I have the following line in Python 2:- > > > > msgstr = string.join(popmsg[1], "\n") # popmsg[1] is a list containing > the lines of the message > > > > ... so I changed it to:- > > > >

Re: How do I do this in Python 3 (string.join())?

2020-08-26 Thread MRAB
e list in popmsg[1] but surely there must be a way that's as neat and elegant as the Python 2 way was? In Python 3, bytestring literals require the 'b' prefix: msgstr = b"\n".join(popmsg[1]) -- https://mail.python.org/mailman/listinfo/python-list

Re: How do I do this in Python 3 (string.join())?

2020-08-26 Thread D'Arcy Cain
On 2020-08-26 09:22, Chris Green wrote: > I have the following line in Python 2:- > > msgstr = string.join(popmsg[1], "\n") # popmsg[1] is a list > containing the lines of the message > > ... so I changed it to:- > > s = "\n" > msgstr = s.join(popmsg[1]) # popmsg[1] is a l

Re: How do I do this in Python 3 (string.join())?

2020-08-26 Thread 2QdxY4RzWzUUiLuE
On 2020-08-26 at 14:22:10 +0100, Chris Green wrote: > I have the following line in Python 2:- > > msgstr = string.join(popmsg[1], "\n") # popmsg[1] is a list > containing the lines of the message > > ... so I changed it to:- > > s = "\n" > msgstr = s.join(popmsg[1]) # po

How do I do this in Python 3 (string.join())?

2020-08-26 Thread Chris Green
I have the following line in Python 2:- msgstr = string.join(popmsg[1], "\n") # popmsg[1] is a list containing the lines of the message ... so I changed it to:- s = "\n" msgstr = s.join(popmsg[1]) # popmsg[1] is a list containing the lines of the message However this sti

Re: "dictionary changed size during iteration" error in Python 3 but not in Python 2

2020-08-23 Thread Peter Otten
Chris Green wrote: >> >1 - Why doesn't it error in Python 2? >> >> The dict internal implementation has changed. I don't know the >> specifics, but it is now faster and maybe smaller and also now preserves >> insert order. >> > Ah, that probably explains it then. But if you try to modify a dict

Re: "dictionary changed size during iteration" error in Python 3 but not in Python 2

2020-08-23 Thread Chris Green
Cameron Simpson wrote: > On 23Aug2020 10:00, Chris Green wrote: > >I have a (fairly) simple little program that removes old mail messages > >from my junk folder. I have just tried to upgrade it from Python 2 to > >Python 3 and now, when it finds any message[s] to delete it

Re: "dictionary changed size during iteration" error in Python 3 but not in Python 2

2020-08-23 Thread Cameron Simpson
On 23Aug2020 10:00, Chris Green wrote: >I have a (fairly) simple little program that removes old mail messages >from my junk folder. I have just tried to upgrade it from Python 2 to >Python 3 and now, when it finds any message[s] to delete it produces >the error:- > >Runtim

"dictionary changed size during iteration" error in Python 3 but not in Python 2

2020-08-23 Thread Chris Green
I have a (fairly) simple little program that removes old mail messages from my junk folder. I have just tried to upgrade it from Python 2 to Python 3 and now, when it finds any message[s] to delete it produces the error:- RuntimeError: dictionary changed size during iteration I can sort of

Re: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3

2020-08-20 Thread Chris Angelico
why the 20.04 release insists > >on 2.7. > > I would guess they didn't have the resources to regression test the > shift in time for 20.04. Moving to Python 3, _particularly_ with > something like Mercurial which has a bunch of internal things which are > in fact byte string

Re: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3

2020-08-20 Thread Cameron Simpson
rces to regression test the shift in time for 20.04. Moving to Python 3, _particularly_ with something like Mercurial which has a bunch of internal things which are in fact byte strings, risks subtle breakage. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3

2020-08-20 Thread Cameron Simpson
On 20Aug2020 18:13, Chris Green wrote: >Cameron Simpson wrote: >> On 19Aug2020 08:53, Chris Green wrote: >> >Maybe I should bite the bullet and make Python 3 the default Python >> >and see what falls over as a consequence. >> >> Don't change the syst

Re: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3

2020-08-20 Thread Chris Green
lists. All the OS python > > code in Ubuntu 20.04 is now Python 3 but there are some other things > > which I have installed (such as Mercurial) which still depend on > > Python 2. One can see what is affected by doing:- > > > > $ sudo apt remove python2 --simulate &

Re: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3

2020-08-20 Thread Chris Angelico
On Fri, Aug 21, 2020 at 3:21 AM Chris Green wrote: > It's actually more subtle and complicated than the OS changing or not > changing the default Python version. There are quite a lot of > questions about exactly this on the Ubuntu lists. All the OS python > code in Ubuntu 20.0

Re: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3

2020-08-20 Thread Chris Green
n so I have to > >run pip3 explicitly to get Python 3 code. > > My approach to this is to have a personal venv based on a modern Python3 > and put its bin near the front of my $PATH. The pip and python come from > it. But I tend to type "pip3" anyway - still the pip from

  1   2   3   4   5   6   7   8   9   10   >