Tkinter and astral characters (was: Decoding bytes to text strings in Python 2)

2024-06-24 Thread Peter J. Holzer via Python-list
On 2024-06-24 01:14:22 +0100, MRAB via Python-list wrote: > Tkinter in recent versions of Python can handle astral characters, at least > back to Python 3.8, the oldest I have on my Windows PC. I just tried modifying https://docs.python.org/3/library/tkinter.html#a-hello-world-program to display "

Re: Decoding bytes to text strings in Python 2

2024-06-23 Thread Chris Angelico via Python-list
On Mon, 24 Jun 2024 at 10:18, MRAB via Python-list wrote: > Tkinter in recent versions of Python can handle astral characters, at > least back to Python 3.8, the oldest I have on my Windows PC. Good to know, thanks! I was hoping that would be the case, but I don't have a Windows system to check o

Re: Decoding bytes to text strings in Python 2

2024-06-23 Thread MRAB via Python-list
On 2024-06-24 00:30, Chris Angelico via Python-list wrote: On Mon, 24 Jun 2024 at 08:20, Rayner Lucas via Python-list wrote: In article , ros...@gmail.com says... > > If you switch to a Linux system, it should work correctly, and you'll > be able to migrate the rest of the way onto Python 3. O

Re: Decoding bytes to text strings in Python 2

2024-06-23 Thread Chris Angelico via Python-list
On Mon, 24 Jun 2024 at 08:20, Rayner Lucas via Python-list wrote: > > In article , > ros...@gmail.com says... > > > > If you switch to a Linux system, it should work correctly, and you'll > > be able to migrate the rest of the way onto Python 3. Once you achieve > > that, you'll be able to operate

Re: Decoding bytes to text strings in Python 2

2024-06-23 Thread Rayner Lucas via Python-list
In article , r...@zedat.fu- berlin.de says... > > I didn't really do a super thorough deep dive on this, > but I'm just giving the initial impression without > actually being familiar with Tkinter under Python 2, > so I might be wrong! > > The Text widget typically expects text in Tcl

Re: Decoding bytes to text strings in Python 2

2024-06-23 Thread Rayner Lucas via Python-list
In article , ros...@gmail.com says... > > If you switch to a Linux system, it should work correctly, and you'll > be able to migrate the rest of the way onto Python 3. Once you achieve > that, you'll be able to operate on Windows or Linux equivalently, > since Python 3 solved this problem. At lea

Re: Decoding bytes to text strings in Python 2

2024-06-21 Thread Chris Angelico via Python-list
On Sat, 22 Jun 2024 at 03:28, Rayner Lucas via Python-list wrote: > I'm curious about something I've encountered while updating a very old > Tk app (originally written in Python 1, but I've ported it to Python 2 > as a first step towards getting it running on modern systems). > > I am using Python

Decoding bytes to text strings in Python 2

2024-06-21 Thread Rayner Lucas via Python-list
I'm curious about something I've encountered while updating a very old Tk app (originally written in Python 1, but I've ported it to Python 2 as a first step towards getting it running on modern systems). The app downloads emails from a POP server and displays them. At the moment, the code is

Re: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in Python )

2024-06-01 Thread Peter J. Holzer via Python-list
687)] > > ((the 36225) (and 17551) (of 16759) (i 16696) (a 15816) (to 15722) (that > 11252) (in 10743) (it 10687)) > > > i think the latter is easier-to-read, so i use this code >(by Peter Norvig) This doesn't

Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in Python )

2024-05-31 Thread HenHanna via Python-list
;;; Pls tell me about little tricks you use in Python or Lisp. [('the', 36225), ('and', 17551), ('of', 16759), ('i', 16696), ('a', 15816), ('to', 15722), ('that', 11252), ('in', 10743), ('it', 10687)] ((the 36225) (and 17551) (of 16759) (i 16696) (a 15816) (to 15722) (that 11252)

Re: Match statement with literal strings

2023-06-07 Thread Jason Friedman via Python-list
> > The bytecode compiler doesn't know that you intend RANGE > to be a constant -- it thinks it's a variable to bind a > value to. > > To make this work you need to find a way to refer to the > value that isn't just a bare name. One way would be to > define your constants using an enum: > > class O

Re: Match statement with literal strings

2023-06-07 Thread Chris Angelico via Python-list
On Thu, 8 Jun 2023 at 08:19, Jason Friedman via Python-list wrote: > > This gives the expected results: > > with open(data_file, newline="") as reader: > csvreader = csv.DictReader(reader) > for row in csvreader: > #print(row) > match row[RULE_TYPE]: > case "RANGE": > print("range") > case "MANDAT

Re: Match statement with literal strings

2023-06-07 Thread Greg Ewing via Python-list
On 8/06/23 10:18 am, Jason Friedman wrote: SyntaxError: name capture 'RANGE' makes remaining patterns unreachable The bytecode compiler doesn't know that you intend RANGE to be a constant -- it thinks it's a variable to bind a value to. To make this work you need to find a way to refer to the

Match statement with literal strings

2023-06-07 Thread Jason Friedman via Python-list
This gives the expected results: with open(data_file, newline="") as reader: csvreader = csv.DictReader(reader) for row in csvreader: #print(row) match row[RULE_TYPE]: case "RANGE": print("range") case "MANDATORY": print("mandatory") case _: print("nothing to do") This: RANGE = "RANGE" MANDATORY

Re: How to escape strings for re.finditer?

2023-03-02 Thread Grant Edwards
On 2023-03-02, Peter J. Holzer wrote: > [1] Personally I'd say you shouldn't use Outlook if you are reading > mails where line breaks (or other formatting) is important, but ... I'd shorten that to "You shouldn't use Outlook if mail is important." -- https://mail.python.org/mailman/listin

RE: How to escape strings for re.finditer?

2023-03-02 Thread avi.e.gross
. -Original Message- From: Python-list On Behalf Of Peter J. Holzer Sent: Thursday, March 2, 2023 3:09 PM To: python-list@python.org Subject: Re: How to escape strings for re.finditer? On 2023-03-01 01:01:42 +0100, Peter J. Holzer wrote: > On 2023-02-28 15:25:05 -0500, avi.e

Re: How to escape strings for re.finditer?

2023-03-02 Thread Peter J. Holzer
On 2023-03-01 01:01:42 +0100, Peter J. Holzer wrote: > On 2023-02-28 15:25:05 -0500, avi.e.gr...@gmail.com wrote: > > I had no doubt the code you ran was indented properly or it would not work. > > > > I am merely letting you know that somewhere in the process of copying > > the code or the transi

Re: How to escape strings for re.finditer?

2023-03-01 Thread Thomas Passin
On 3/1/2023 12:04 PM, Grant Edwards wrote: On 2023-02-28, Cameron Simpson wrote: Regexps are: - cryptic and error prone (you can make them more readable, but the notation is deliberately both terse and powerful, which means that small changes can have large effects in behaviour); the "

Re: How to escape strings for re.finditer?

2023-03-01 Thread Grant Edwards
On 2023-02-28, Cameron Simpson wrote: > Regexps are: > - cryptic and error prone (you can make them more readable, but the >notation is deliberately both terse and powerful, which means that >small changes can have large effects in behaviour); the "error prone" >part does not mean

RE: How to escape strings for re.finditer?

2023-02-28 Thread avi.e.gross
Of Peter J. Holzer Sent: Tuesday, February 28, 2023 7:26 PM To: python-list@python.org Subject: Re: How to escape strings for re.finditer? On 2023-03-01 01:01:42 +0100, Peter J. Holzer wrote: > On 2023-02-28 15:25:05 -0500, avi.e.gr...@gmail.com wrote: > > It happens to be easy for me to

Re: How to escape strings for re.finditer?

2023-02-28 Thread Weatherby,Gerard
@python.org Subject: Re: How to escape strings for re.finditer? *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Using str.startswith is a cool idea in this case. But is it better than regex for performance or reliability? Regex

Re: How to escape strings for re.finditer?

2023-02-28 Thread Peter J. Holzer
On 2023-03-01 01:01:42 +0100, Peter J. Holzer wrote: > On 2023-02-28 15:25:05 -0500, avi.e.gr...@gmail.com wrote: > > It happens to be easy for me to fix but I sometimes see garbled code I > > then simply ignore. > > Truth to be told, that's one reason why I rarely read your mails to the > end. Th

Re: How to escape strings for re.finditer?

2023-02-28 Thread Peter J. Holzer
On 2023-02-28 15:25:05 -0500, avi.e.gr...@gmail.com wrote: > Jen, > > > > I had no doubt the code you ran was indented properly or it would not work. > > > > I am merely letting you know that somewhere in the process of copying > the code or the transition between mailers, my version is mes

Re: How to escape strings for re.finditer?

2023-02-28 Thread Cameron Simpson
On 28Feb2023 18:57, Jen Kris wrote: One question:  several people have made suggestions other than regex (not your terser example with regex you shown below).  Is there a reason why regex is not preferred to, for example, a list comp?  These are different things; I'm not sure a comparison is

Re: How to escape strings for re.finditer?

2023-02-28 Thread Thomas Passin
On 2/28/2023 2:40 PM, David Raymond wrote: With a slight tweak to the simple loop code using .find() it becomes a third faster than the RE version though. def using_simple_loop2(key, text): matches = [] keyLen = len(key) start = 0 while (foundSpot := text.find(key, start))

RE: How to escape strings for re.finditer?

2023-02-28 Thread avi.e.gross
function that hides the loops inside a faster environment than the interpreter. -Original Message- From: Python-list On Behalf Of David Raymond Sent: Tuesday, February 28, 2023 2:40 PM To: python-list@python.org Subject: RE: How to escape strings for re.finditer? > I wrote my previ

RE: How to escape strings for re.finditer?

2023-02-28 Thread avi.e.gross
To: python-list@python.org Subject: Re: How to escape strings for re.finditer? On 2/28/2023 1:07 PM, Jen Kris wrote: > > Using str.startswith is a cool idea in this case. But is it better > than regex for performance or reliability? Regex syntax is not a > model of simplicity, but in

RE: How to escape strings for re.finditer?

2023-02-28 Thread avi.e.gross
, February 28, 2023 12:58 PM To: avi.e.gr...@gmail.com Cc: 'Python List' Subject: RE: How to escape strings for re.finditer? The code I sent is correct, and it runs here. Maybe you received it with a carriage return removed, but on my copy after posting, it is correct: example = '

RE: How to escape strings for re.finditer?

2023-02-28 Thread David Raymond
> I wrote my previous message before reading this.  Thank you for the test you > ran -- it answers the question of performance.  You show that re.finditer is > 30x faster, so that certainly recommends that over a simple loop, which > introduces looping overhead.  >>     def using_simple_loop(

Re: How to escape strings for re.finditer?

2023-02-28 Thread Thomas Passin
On 2/28/2023 11:48 AM, Jon Ribbens via Python-list wrote: On 2023-02-28, Thomas Passin wrote: ... It is interesting, though, how pre-processing the search pattern can improve search times if you can afford the pre-processing. Here's a paper on rapidly finding matches when there may be up to

Re: How to escape strings for re.finditer?

2023-02-28 Thread Thomas Passin
list On Behalf Of Jen Kris via Python-list Sent: Monday, February 27, 2023 8:36 PM To: Cameron Simpson Cc: Python List Subject: Re: How to escape strings for re.finditer? I haven't tested it either but it looks like it would work. But for this case I prefer the relative simplicity o

RE: How to escape strings for re.finditer?

2023-02-28 Thread avi.e.gross
: python-list@python.org Subject: Re: How to escape strings for re.finditer? Op 28/02/2023 om 3:44 schreef Thomas Passin: > On 2/27/2023 9:16 PM, avi.e.gr...@gmail.com wrote: >> And, just for fun, since there is nothing wrong with your code, this >> minor change is terser: >&g

Re: How to escape strings for re.finditer?

2023-02-28 Thread Thomas Passin
nges and then regexes would almost certainly be the best approach. But the regular expression strings would become harder to read. -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list

Re: How to escape strings for re.finditer?

2023-02-28 Thread Jon Ribbens via Python-list
-prone. Using a well-tested >>>> existing function becomes quite attractive. >>> >>> Sure, it all depends on what the real task will be.  That's why I >>> wrote "Without knowing how general your expressions will be". For the >>> example s

Re: How to escape strings for re.finditer?

2023-02-28 Thread Jen Kris via Python-list
h(KEY): >>>     print(i, i + len(KEY)) >>> # prints: >>> 4 18 >>> 26 40 >>> >> I think it's often a good idea to use a standard library function instead of >> rolling your own. The issue becomes less clear-cut when the standard libra

Re: How to escape strings for re.finditer?

2023-02-28 Thread Jen Kris via Python-list
gt; 26 40 > > If you may have variable numbers of spaces around the symbols, OTOH, the > whole situation changes and then regexes would almost certainly be the best > approach. But the regular expression strings would become harder to read. > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list

RE: How to escape strings for re.finditer?

2023-02-28 Thread Jen Kris via Python-list
s but also show > the exact text that matched or even show some characters before and/or after > for context. > > > -Original Message- > From: Python-list On > Behalf Of Jen Kris via Python-list > Sent: Monday, February 27, 2023 8:36 PM > To: Cameron Simpson

Re: How to escape strings for re.finditer?

2023-02-28 Thread Thomas Passin
. For the example string, it's unlikely that speed will be a factor, but who knows what target strings and keys will turn up in the future? On hindsight I think it was overthinking things a bit. "It all depends on what the real task will be" you say, and indeed I think that shoul

Re: How to escape strings for re.finditer?

2023-02-28 Thread Roel Schroeven
at speed will be a factor, but who knows what target strings and keys will turn up in the future? On hindsight I think it was overthinking things a bit. "It all depends on what the real task will be" you say, and indeed I think that should be the main conclusion here. -- "Man ha

Re: How to escape strings for re.finditer?

2023-02-28 Thread Thomas Passin
nstead of rolling your own. The issue becomes less clear-cut when the standard library doesn't do exactly what you need (as here, where re.finditer() uses regular expressions while the use case only uses simple search strings). Ideally there would be a str.finditer() method we could use, b

Re: How to escape strings for re.finditer?

2023-02-28 Thread Roel Schroeven
mes less clear-cut when the standard library doesn't do exactly what you need (as here, where re.finditer() uses regular expressions while the use case only uses simple search strings). Ideally there would be a str.finditer() method we could use, but in the absence of that I think we stil

RE: How to escape strings for re.finditer?

2023-02-27 Thread avi.e.gross
rting from where you left off. -Original Message- From: Python-list On Behalf Of Thomas Passin Sent: Monday, February 27, 2023 9:44 PM To: python-list@python.org Subject: Re: How to escape strings for re.finditer? On 2/27/2023 9:16 PM, avi.e.gr...@gmail.com wrote: > And, just for fun

Re: How to escape strings for re.finditer?

2023-02-27 Thread Thomas Passin
abc_degree + 1' for i in range(len(example)): if example[i:].startswith(KEY): print(i, i + len(KEY)) # prints: 4 18 26 40 If you may have variable numbers of spaces around the symbols, OTOH, the whole situation changes and then regexes would almost certainly be the best approach.

RE: How to escape strings for re.finditer?

2023-02-27 Thread avi.e.gross
bookkeeper. In those cases, you may want even more than offsets but also show the exact text that matched or even show some characters before and/or after for context. -Original Message- From: Python-list On Behalf Of Jen Kris via Python-list Sent: Monday, February 27, 2023 8:36 PM To:

RE: How to escape strings for re.finditer?

2023-02-27 Thread avi.e.gross
tion and now you have a tool. Even better, you can make it return whatever you want. -Original Message- From: Python-list On Behalf Of Jen Kris via Python-list Sent: Monday, February 27, 2023 7:40 PM To: Bob van der Poel Cc: Python List Subject: Re: How to escape strings for re.findit

Re: How to escape strings for re.finditer?

2023-02-27 Thread Jen Kris via Python-list
found + len(substring) > ... do whatever with start and end ... > pos = end > > Many people go straight to the `re` module whenever they're looking for > strings. It is often cryptic error prone overkill. Just something to keep in > mind. > > Cheers, > Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list

Re: How to escape strings for re.finditer?

2023-02-27 Thread Cameron Simpson
On 28Feb2023 00:57, Jen Kris wrote: Yes, that's it.  I don't know how long it would have taken to find that detail with research through the voluminous re documentation.  Thanks very much.  You find things like this by printing out the strings you're actually working with. N

Re: How to escape strings for re.finditer?

2023-02-27 Thread Cameron Simpson
tring, pos) if found < 0: break start = found end = found + len(substring) ... do whatever with start and end ... pos = end Many people go straight to the `re` module whenever they're looking for strings. It is often cryptic error prone o

Re: How to escape strings for re.finditer?

2023-02-27 Thread Jen Kris via Python-list
ccurred only once then the str.find would be best.  >> >> I changed my re code after MRAB's comment, it now works.  >> >> Thanks much.  >> >> Jen >> >> >> Feb 27, 2023, 15:56 by >> c...@cskk.id.au>> : &g

RE: How to escape strings for re.finditer?

2023-02-27 Thread avi.e.gross
Just FYI, Jen, there are times a sledgehammer works but perhaps is not the only way. These days people worry less about efficiency and more about programmer time and education and that can be fine. But it you looked at methods available in strings or in some other modules, your situation is

Re: How to escape strings for re.finditer?

2023-02-27 Thread Jen Kris via Python-list
28Feb2023 00:11, Jen Kris wrote: > >> When matching a string against a longer string, where both strings have >> spaces in them, we need to escape the spaces.  >> >> This works (no spaces): >> >> import re >> example = 'abcdefabcdefabcdefg'

RE: How to escape strings for re.finditer?

2023-02-27 Thread avi.e.gross
the backslash breaks the match from going further. -Original Message- From: Python-list On Behalf Of MRAB Sent: Monday, February 27, 2023 6:46 PM To: python-list@python.org Subject: Re: How to escape strings for re.finditer? On 2023-02-27 23:11, Jen Kris via Python-list wrote: > When matching

Re: How to escape strings for re.finditer?

2023-02-27 Thread Jen Kris via Python-list
When matching a string against a longer string, where both strings have >> spaces in them, we need to escape the spaces. >> >> This works (no spaces): >> >> import re >> example = 'abcdefabcdefabcdefg' >> find_string = "abc" >> for match

Re: How to escape strings for re.finditer?

2023-02-27 Thread Cameron Simpson
On 28Feb2023 00:11, Jen Kris wrote: When matching a string against a longer string, where both strings have spaces in them, we need to escape the spaces.  This works (no spaces): import re example = 'abcdefabcdefabcdefg' find_string = "abc" for match in re.finditer(

Re: How to escape strings for re.finditer?

2023-02-27 Thread MRAB
On 2023-02-27 23:11, Jen Kris via Python-list wrote: When matching a string against a longer string, where both strings have spaces in them, we need to escape the spaces. This works (no spaces): import re example = 'abcdefabcdefabcdefg' find_string = "abc" for match in re.

How to escape strings for re.finditer?

2023-02-27 Thread Jen Kris via Python-list
When matching a string against a longer string, where both strings have spaces in them, we need to escape the spaces.  This works (no spaces): import re example = 'abcdefabcdefabcdefg' find_string = "abc" for match in re.finditer(find_string, example):     print(matc

Re: Ref-strings in logging messages (was: Performance issue with CPython 3.10 + Cython)

2022-10-24 Thread Barry Scott
t; > Date: Friday, October 7, 2022 at 1:30 PM > To: MRAB mailto:pyt...@mrabarnett.plus.com>> > Cc: python-list@python.org <mailto:python-list@python.org> > mailto:python-list@python.org>> > Subject: Re: Ref-strings in logging messages (was: Performance issue with

Re: Ref-strings in logging messages (was: Performance issue with CPython 3.10 + Cython)

2022-10-08 Thread Weatherby,Gerard
hello" logging.basicConfig() logging.debug(Defer(some_expensive_function)) From: Python-list on behalf of Barry Date: Friday, October 7, 2022 at 1:30 PM To: MRAB Cc: python-list@python.org Subject: Re: Ref-strings in logging messages (was: Performance issue with CPython 3.10 + Cython) *** Attentio

Re: Ref-strings in logging messages (was: Performance issue with CPython 3.10 + Cython)

2022-10-07 Thread Julian Smith
On Fri, 7 Oct 2022 18:28:06 +0100 Barry wrote: > > On 7 Oct 2022, at 18:16, MRAB wrote: > > > > On 2022-10-07 16:45, Skip Montanaro wrote: > >>> On Fri, Oct 7, 2022 at 9:42 AM Andreas Ames > >>> > >>> wrote: > >>> 1. The c

Re: Ref-strings in logging messages (was: Performance issue with CPython 3.10 + Cython)

2022-10-07 Thread Barry
ebug = logger_from(DEBUG) log_debug and log_debug(‘expensive %s’ % (complex(),)) Barry > > From: Python-list on > behalf of Barry > Date: Friday, October 7, 2022 at 1:30 PM > To: MRAB > Cc: python-list@python.org > Subject: Re: Ref-strings in logging messages (was: Pe

Re: Ref-strings in logging messages (was: Performance issue with CPython 3.10 + Cython)

2022-10-07 Thread Weatherby,Gerard
To: MRAB Cc: python-list@python.org Subject: Re: Ref-strings in logging messages (was: Performance issue with CPython 3.10 + Cython) *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** > On 7 Oct 2022, at 18:16, MRAB wrote: >

Re: Ref-strings in logging messages (was: Performance issue with CPython 3.10 + Cython)

2022-10-07 Thread Barry
> On 7 Oct 2022, at 18:16, MRAB wrote: > > On 2022-10-07 16:45, Skip Montanaro wrote: >>> On Fri, Oct 7, 2022 at 9:42 AM Andreas Ames >>> wrote: >>> 1. The culprit was me. As lazy as I am, I have used f-strings all over the >>> place in

Re: Ref-strings in logging messages (was: Performance issue with CPython 3.10 + Cython)

2022-10-07 Thread MRAB
On 2022-10-07 16:45, Skip Montanaro wrote: On Fri, Oct 7, 2022 at 9:42 AM Andreas Ames wrote: 1. The culprit was me. As lazy as I am, I have used f-strings all over the place in calls to `logging.logger.debug()` and friends, evaluating all arguments regardless of whether the logger was

Re: Ref-strings in logging messages (was: Performance issue with CPython 3.10 + Cython)

2022-10-07 Thread Barry
> On 7 Oct 2022, at 16:48, Skip Montanaro wrote: > > On Fri, Oct 7, 2022 at 9:42 AM Andreas Ames > wrote: > >> 1. The culprit was me. As lazy as I am, I have used f-strings all over the >> place in calls to `logging.logger.debug()` and friends, evaluating all

Re: Ref-strings in logging messages (was: Performance issue with CPython 3.10 + Cython)

2022-10-07 Thread Skip Montanaro
Dang autocorrect. Subject first word was supposed to be "f-strings" not "ref-strings." Sorry about that. S On Fri, Oct 7, 2022, 10:45 AM Skip Montanaro wrote: > > > On Fri, Oct 7, 2022 at 9:42 AM Andreas Ames > wrote: > >> 1. The culprit was me. As laz

Ref-strings in logging messages (was: Performance issue with CPython 3.10 + Cython)

2022-10-07 Thread Skip Montanaro
On Fri, Oct 7, 2022 at 9:42 AM Andreas Ames wrote: > 1. The culprit was me. As lazy as I am, I have used f-strings all over the > place in calls to `logging.logger.debug()` and friends, evaluating all > arguments regardless of whether the logger was enabled or not. > I thought th

Re: on str.format and f-strings

2022-09-06 Thread Meredith Montgomery
Chris Angelico writes: > On Wed, 7 Sept 2022 at 03:52, Meredith Montgomery > wrote: >> >> It seems to me that str.format is not completely made obsolete by the >> f-strings that appeared in Python 3.6. But I'm not thinking that this >> was the objective of

Re: on str.format and f-strings

2022-09-06 Thread Chris Angelico
On Wed, 7 Sept 2022 at 03:52, Meredith Montgomery wrote: > > It seems to me that str.format is not completely made obsolete by the > f-strings that appeared in Python 3.6. But I'm not thinking that this > was the objective of the introduction of f-strings: the P

Re: on str.format and f-strings

2022-09-06 Thread Meredith Montgomery
Julio Di Egidio writes: > On Tuesday, 6 September 2022 at 01:03:02 UTC+2, Meredith Montgomery wrote: >> Julio Di Egidio writes: >> > On Monday, 5 September 2022 at 22:18:58 UTC+2, Meredith Montgomery wrote: >> >> r...@zedat.fu-berlin.de (Stefan Ram) writes: >> > >> >> > , but with the spaces

Re: on str.format and f-strings

2022-09-06 Thread Meredith Montgomery
Julio Di Egidio writes: > On Monday, 5 September 2022 at 22:18:58 UTC+2, Meredith Montgomery wrote: >> r...@zedat.fu-berlin.de (Stefan Ram) writes: > >> > , but with the spaces removed, it's even one character >> > shorter than the format expression: >> > >> > eval('f"The name is {name} and t

Re: on str.format and f-strings

2022-09-06 Thread Meredith Montgomery
lt;---cut here---end--->8--- >>Is there a way to do this with f-strings? > > I cannot think of anything shorter now than: > > eval( 'f"The name is {name} and the email is {email}"', d ) > > , but with the spa

on str.format and f-strings

2022-09-06 Thread Meredith Montgomery
It seems to me that str.format is not completely made obsolete by the f-strings that appeared in Python 3.6. But I'm not thinking that this was the objective of the introduction of f-strings: the PEP at https://peps.python.org/pep-0498/#id11 says so explicitly. My question is whet

Re: Printing Unicode strings in a list

2022-04-30 Thread Chris Angelico
On Sun, 1 May 2022 at 00:03, Vlastimil Brom wrote: > (Even the redundant u prefix from your python2 sample is apparently > accepted, maybe for compatibility reasons.) Yes, for compatibility reasons. It wasn't accepted in Python 3.0, but 3.3 re-added it to make porting easier. It doesn't do anythi

Re: Printing Unicode strings in a list

2022-04-30 Thread Vlastimil Brom
have good reasons for doing so and > will be moving to Python 3.x in due course. > > I have the following questions arising from the log: > > 1. Why does the second print statement not produce [ ║] or ["║"] ? > > 2. Should the second print statement produce [ ║] or [

Re: Printing Unicode strings in a list

2022-04-28 Thread Rob Cliffe via Python-list
On 28/04/2022 14:27, Stephen Tucker wrote: To Cameron Simpson, Thanks for your in-depth and helpful reply. I have noted it and will be giving it close attention when I can. The main reason why I am still using Python 2.x is that my colleagues are still using a GIS system that has a Python pro

Re: Printing Unicode strings in a list

2022-04-28 Thread Jon Ribbens via Python-list
don't have their own str converter, so fall back to repr instead, which outputs '[', followed by the repr of each list item separated by ', ', followed by ']'. > 2. Should the second print statement produce [ ║] or ["║"] ? There's certainly n

Re: Printing Unicode strings in a list

2022-04-28 Thread Stephen Tucker
> > >2. Should the second print statement produce [ ║] or ["║"] ? > > Well, to me its behaviour is correct. Do you _want_ to get your Unicode > glyph? in quotes? That is up to you. But consider: what would be sane > output if the list contained the string "], [3

Re: Printing Unicode strings in a list

2022-04-28 Thread Cameron Simpson
yph? in quotes? That is up to you. But consider: what would be sane output if the list contained the string "], [3," ? >3. Given that I want to print a list of Unicode strings so that their >characters are displayed (instead of their Unicode codepoint definitions), >is there a m

Printing Unicode strings in a list

2022-04-28 Thread Stephen Tucker
oes the second print statement not produce [ ║] or ["║"] ? 2. Should the second print statement produce [ ║] or ["║"] ? 3. Given that I want to print a list of Unicode strings so that their characters are displayed (instead of their Unicode codepoint definitions), is there a more P

Re: Using astype(int) for strings with thousand separator

2021-11-15 Thread Mahmood Naderan via Python-list
> (see > https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html) Got it. Thanks. Regards, Mahmood -- https://mail.python.org/mailman/listinfo/python-list

Re: Using astype(int) for strings with thousand separator

2021-11-14 Thread Thomas Jollans
On 14.11.21 16:41, Mahmood Naderan via Python-list wrote: Hi While reading a csv file, some cells have values like '1,024' which I mean they contains thousand separator ','. Therefore, when I want to process them with   row = df.iloc[0].astype(int) If you are reading a CSV with pandas.read

Re: Using astype(int) for strings with thousand separator

2021-11-14 Thread Barry Scott
> On 14 Nov 2021, at 15:41, Mahmood Naderan via Python-list > wrote: > > Hi > > While reading a csv file, some cells have values like '1,024' which I mean > they contains thousand separator ','. Therefore, when I want to process them > with > > row = df.iloc[0].astype(int) remove the

Using astype(int) for strings with thousand separator

2021-11-14 Thread Mahmood Naderan via Python-list
Hi While reading a csv file, some cells have values like '1,024' which I mean they contains thousand separator ','. Therefore, when I want to process them with   row = df.iloc[0].astype(int) I get the following error   ValueError: invalid literal for int() with base 10: '1,024' How can I fi

Re: f-strings and internationalisation.

2021-05-24 Thread Barry Scott
> On 24 May 2021, at 19:30, Antoon Pardon wrote: > > I have now come across several occasion where an author advice the use > of f-strings above the %-formatting and the format method. However it > seems these authors were only thinking about rather straight forward > eng

f-strings and internationalisation.

2021-05-24 Thread Antoon Pardon
I have now come across several occasion where an author advice the use of f-strings above the %-formatting and the format method. However it seems these authors were only thinking about rather straight forward english communication. So what if you want your application to work with multiple

Re: Comparing text strings

2021-04-18 Thread dn via Python-list
s, you've identified why this is hard: package versioning takes many > forms.  As suggested elsewhere, for Linux distribution packages, the > only reliable approach is to lean on the distro's packaging > infrastructure in some way, because those version strings (plus package > meta

Re: Comparing text strings

2021-04-18 Thread Peter Pearson
On Sun, 18 Apr 2021 06:38:16 GMT, Gilmeh Serda wrote: > On Mon, 12 Apr 2021 16:11:21 -0700, Rich Shepard wrote: > >> All suggestions welcome. > > Assuming you want to know which is the oldest version and that the same > scheme is used all the time, could this work? > s1='atftp-0.7.2-x86_64-2_

Re: Comparing text strings

2021-04-13 Thread Rich Shepard
On Tue, 13 Apr 2021, jak wrote: If I understand your problem correctly, the problem would be dealing with numbers as such in file names. This is just a track but it might help you. This example splits filenames into strings and numbers into tuples, appends the tuple into a list, and then sorts

Re: Comparing text strings

2021-04-13 Thread jak
27;t work because while the file name is the same the version or build numbers differ. All suggestions welcome. Rich If I understand your problem correctly, the problem would be dealing with numbers as such in file names. This is just a track but it might help you. This example splits filenam

Re: Comparing text strings

2021-04-13 Thread Grant Edwards
On 2021-04-12, 2qdxy4rzwzuui...@potatochowder.com <2qdxy4rzwzuui...@potatochowder.com> wrote: > I don't know whether or how Slackware handles "compound" package names > (e.g., python-flask), but at some point, you're going to have to pull > apart (aka---gasp--parse), the package names to come up

Re: Comparing text strings

2021-04-13 Thread Mats Wichmann
infrastructure in some way, because those version strings (plus package metadata which may have "replaces" or "obsoletes" or some similar information) all have a defined meaning to *it* - it's the intended audience. Don't know if Slack exposes this information in some wa

Re: Comparing text strings

2021-04-13 Thread Rich Shepard
On Tue, 13 Apr 2021, Cameron Simpson wrote: The problem is not that simple. Sometimes the package maintainer upgrades the package for the same version number so there could be abc-1.0_1_SBo.tgz and abc-1.0_2_SBo.tgz. The more involved route will be taken. If that _1, _2 thing is like RedHat's

Re: Comparing text strings

2021-04-12 Thread Cameron Simpson
On 12Apr2021 19:11, Rich Shepard wrote: >On Tue, 13 Apr 2021, Cameron Simpson wrote: >>Alternatively, and now that I think about it, more simply: _if_ the >>package files can be sorted by version, then all you need to do is read a >>sorted listing and note that latest fil for a particular package.

Re: Comparing text strings

2021-04-12 Thread Rich Shepard
On Tue, 13 Apr 2021, Cameron Simpson wrote: I do not know if there are preexisting modules/tools for this, but I recommend looking at slackware's package management tool - they usually have some kind of 'clean" operation to purge "old" package install files. Sometimes that purges all the install

Re: Comparing text strings

2021-04-12 Thread Chris Angelico
On Tue, Apr 13, 2021 at 9:54 AM Cameron Simpson wrote: > Note that this depends on sorting by version. A lexical sort (eg > "ls|sort") will look good intil a package version crosses a boundary > like this: > > 1.9.1 > 1.10.0 > > A lexical sort will put those the other way around because "9

Re: Comparing text strings

2021-04-12 Thread Cameron Simpson
On 12Apr2021 16:11, Rich Shepard wrote: >I'm running Slackware64-14.2 and keep a list of installed packages. When a >package is upgraded I want to remove the earlier version, and I've not >before written a script like this. Could there be a module or tool that >already exists to do this? If not, w

Re: Comparing text strings

2021-04-12 Thread 2QdxY4RzWzUUiLuE
On 2021-04-12 at 16:11:21 -0700, Rich Shepard wrote: > I'm running Slackware64-14.2 and keep a list of installed packages. When a > package is upgraded I want to remove the earlier version, and I've not > before written a script like this. Could there be a module or tool that > already exists to

Comparing text strings

2021-04-12 Thread Rich Shepard
I'm running Slackware64-14.2 and keep a list of installed packages. When a package is upgraded I want to remove the earlier version, and I've not before written a script like this. Could there be a module or tool that already exists to do this? If not, which string function would be best suited to

Re: how to separate the strings in a string

2021-04-02 Thread Peter Otten
bl.split(',') ['"a', 'bc"', ' def'] The initial string looks like it's close enough to the CSV format. Unfortunately Python's csv module operates on files, not strings -- to use it you have to wrap the string into a stream: import csv

Re: how to separate the strings in a string

2021-04-02 Thread Peter Otten
ot;a', 'bc"', ' def'] The initial string looks like it's close enough to the CSV format. Unfortunately Python's csv module operates on files, not strings -- to use it you have to wrap the string into a stream: >>> import csv >>> import io >&g

  1   2   3   4   5   6   7   8   9   10   >