Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread Thomas Passin
On 3/10/2023 11:15 PM, aapost wrote: On 3/10/23 22:16, Thomas Passin wrote: [...] The additional note in the above is, when taking the def route above, the thing you would have to consider is what scope is the dictionary pids? Do you need to submit it to the lambda and subsequently the functi

Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread aapost
On 3/10/23 22:16, Thomas Passin wrote: On 3/10/2023 7:07 PM, aapost wrote: which does start to break down readability due to line length, as there isn't really an indention rule set for something uncommonly used. but some renaming makes the pattern clearer pids.update({"messages" :subprocess.

Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread Thomas Passin
t;1", "-f", f"/var/log/{target}"] pids.update({target: subprocess.Popen(cmd)}) if not \ pids[target] else None I might be missing something, but how is that more understandable and less error prone than any of the following: The main point is that there can be an ea

Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread 2QdxY4RzWzUUiLuE
On 2023-03-10 at 22:16:05 -0500, Thomas Passin wrote: > I'd make the pattern in this example even more understandable and less > error-prone: > > def update_pids(target): > cmd = ["tail", "-n", "1", "-f", f"/var/log/{target}"] > pids.update({target: subprocess.Popen(cmd)}) if not \ >

Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread Thomas Passin
On 3/10/2023 7:07 PM, aapost wrote: which does start to break down readability due to line length, as there isn't really an indention rule set for something uncommonly used. but some renaming makes the pattern clearer pids.update({"messages" :subprocess.Popen(["cmd1"])}) if not pids["messages

Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread aapost
should be killed, and how do you kill the right one?  With the function, you can get those details under control, but I hate to think what might happen to the lambda expression. Yes, of course, there can be times when the lambda expression is somewhat easy to understand and the side effects

Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread aapost
On 3/10/23 18:46, aapost wrote:     main.pids.update({"messages" :subprocess.Popen(["tail", "-n", "1", "-f", "/var/log/messages"])}),     main.pids.update({"syslog" :subprocess.Popen(["tail", "-n", "1", "-f", "/var/log/syslog"])}),     main.pids.update({"kern" :subprocess.Popen([

Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread Cameron Simpson
On 09Mar2023 17:55, aapost wrote: On 3/9/23 16:37, Cameron Simpson wrote: Just a note that some code formatters use a trailing comma on the last element to make the commas fold points. Both yapf (my preference) and black let you write a line like (and, indeed, flatten if short enough):    

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread aapost
On 3/9/23 16:37, Cameron Simpson wrote: On 09Mar2023 09:06, Alan Gauld wrote: Just a note that some code formatters use a trailing comma on the last element to make the commas fold points. Both yapf (my preference) and black let you write a line like (and, indeed, flatten if short enough):

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread aapost
On 3/9/23 04:06, Alan Gauld wrote: Thank you for the feedback, I appreciate the comments. To add a little extra, there is actually a reason I lean toward overuse of .config() for a lot of things even though they could be sent to the constructor (other than that w["attribute"]= doesn't work

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread Chris Angelico
ived {x}') or x*x I'm not sure why lambda functions shouldn't have side effects. They can be used for anything, as long as it's a single expression (which can, of course, be composed of other expressions). > The Python Reference on readthedocs.io also has a tk example

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread Cameron Simpson
On 09Mar2023 09:06, Alan Gauld wrote: Also layout is all important here. It could get very messy to read if indentation isn't clear. You only have to look at some Javascript code with function definitions as arguments to functions to see how clunky that can be. Just a note that some code forma

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread Cameron Simpson
;), ...maybe more..., expr)[-1] to embed some debug tracing in a lambda defined expression. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread Thomas Passin
killed, and how do you kill the right one? With the function, you can get those details under control, but I hate to think what might happen to the lambda expression. Yes, of course, there can be times when the lambda expression is somewhat easy to understand and the side effects are harmless.

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread aapost
On 3/9/23 00:13, Thomas Passin wrote: lol.. 'us'.. So.. to give an example from your own code: but_play = Tk.Button(_frame, text='Play', width = BUTTONWIDTH + 1, pady = PADY, command=lambda x=plotmgr:play_macro(x), bg = BUTTON_BG, font = NEWFONT) Can be written as: b = Tk.Button(master=

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread Weatherby,Gerard
t;,command=e) or b = tk.Button(master=main, text="Enable",command=lambda: [e.config(state="normal") for e in (e1, e2, e3)]) From: Python-list on behalf of aapost Date: Wednesday, March 8, 2023 at 5:15 PM To: python-list@python.org Subject: Lambda returning tuple question,

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread Alan Gauld
On 08/03/2023 21:56, aapost wrote: > When making a UI there are a lot of binding/trace operations that need > to occur that lead to a lot of annoying 1 use function definitions. I > don't really see lambda use like below. Lambdas are very common in GUI callbacks but I admit I've never seen tuple

Re: Lambda returning tuple question, multi-expression

2023-03-08 Thread Thomas Passin
on config_b_and_entries() that I suggested is not meant to be the target of a lambda expression that is the argument of b.config(). It is meant to be called *instead* of b.config(command = lambda.). I can't see any benefit of trying to force this coordination of states by using an obs

Re: Lambda returning tuple question, multi-expression

2023-03-08 Thread aapost
On 3/8/23 16:56, aapost wrote: Thomas > Cameron def set_entries_enabled_state(enabled = True): state = 'normal' if enabled else 'disabled' for e in (e1, e2, e3): e.config(state=state) def config_b_and_entries(enabled = True): state = 'normal' if enabled else 'disabled'

Re: Lambda returning tuple question, multi-expression

2023-03-08 Thread Cameron Simpson
On 08Mar2023 16:56, aapost wrote: When making a UI there are a lot of binding/trace operations that need to occur that lead to a lot of annoying 1 use function definitions. I don't really see lambda use like below. Giving 2 working lambda examples using a returned tuple to accomplish multipl

Re: Lambda returning tuple question, multi-expression

2023-03-08 Thread Thomas Passin
On 3/8/2023 4:56 PM, aapost wrote: b = tk.Button(master=main, text="Enable") b.config(     command=lambda: (     e1.config(state="normal"),     e2.config(state="normal"),     e3.config(state="normal")     ) ) It's hard to understand what you are trying to do here. I don't rem

Lambda returning tuple question, multi-expression

2023-03-08 Thread aapost
When making a UI there are a lot of binding/trace operations that need to occur that lead to a lot of annoying 1 use function definitions. I don't really see lambda use like below. Giving 2 working lambda examples using a returned tuple to accomplish multiple expressions - what sort of gotchas

Re: Regular Expression bug?

2023-03-02 Thread jose isaias cabrera
On Thu, Mar 2, 2023 at 9:56 PM Alan Bawden wrote: > > jose isaias cabrera writes: > >On Thu, Mar 2, 2023 at 2:38 PM Mats Wichmann wrote: > >This re is a bit different than the one I am used. So, I am trying to match >everything after 'pn=': > >import re >s = "pm=jose pn=2017"

Re: Regular Expression bug?

2023-03-02 Thread jose isaias cabrera
ject manager. pn=project name. I needed search() rather than match(). > > >>> s = "pn=jose pn=2017" > ... > >>> s0 = r0.match(s) > >>> s0 > > > > > -Original Message- > From: Python-list On > Behalf Of jose isaias cab

Re: Regular Expression bug?

2023-03-02 Thread jose isaias cabrera
On Thu, Mar 2, 2023 at 8:30 PM Cameron Simpson wrote: > > On 02Mar2023 20:06, jose isaias cabrera wrote: > >This re is a bit different than the one I am used. So, I am trying to > >match > >everything after 'pn=': > > > >import re > >s = "pm=jose pn=2017" > >m0 = r"pn=(.+)" > >r0 = re.compile(m0)

Re: Regular Expression bug?

2023-03-02 Thread Alan Bawden
jose isaias cabrera writes: On Thu, Mar 2, 2023 at 2:38 PM Mats Wichmann wrote: This re is a bit different than the one I am used. So, I am trying to match everything after 'pn=': import re s = "pm=jose pn=2017" m0 = r"pn=(.+)" r0 = re.compile(m0) s0 = r0.match(s) >>

Re: Regular Expression bug?

2023-03-02 Thread Cameron Simpson
On 02Mar2023 20:06, jose isaias cabrera wrote: This re is a bit different than the one I am used. So, I am trying to match everything after 'pn=': import re s = "pm=jose pn=2017" m0 = r"pn=(.+)" r0 = re.compile(m0) s0 = r0.match(s) `match()` matches at the start of the string. You want r0.se

RE: Regular Expression bug?

2023-03-02 Thread avi.e.gross
;> s0 -Original Message- From: Python-list On Behalf Of jose isaias cabrera Sent: Thursday, March 2, 2023 8:07 PM To: Mats Wichmann Cc: python-list@python.org Subject: Re: Regular Expression bug? On Thu, Mar 2, 2023 at 2:38 PM Mats Wichmann wrote: > > On 3/2/23 12:28

Re: Regular Expression bug?

2023-03-02 Thread jose isaias cabrera
On Thu, Mar 2, 2023 at 2:38 PM Mats Wichmann wrote: > > On 3/2/23 12:28, Chris Angelico wrote: > > On Fri, 3 Mar 2023 at 06:24, jose isaias cabrera wrote: > >> > >> Greetings. > >> > >> For the RegExp Gurus, consider the following python3 code: > >> > >> import re > >> s = "pn=align upgrade sd=2

RE: Regular Expression bug?

2023-03-02 Thread avi.e.gross
On Behalf Of jose isaias cabrera Sent: Thursday, March 2, 2023 2:23 PM To: python-list@python.org Subject: Regular Expression bug? Greetings. For the RegExp Gurus, consider the following python3 code: import re s = "pn=align upgrade sd=2023-02-" ro = re.compile(r"pn=(.+) &

Re: Regular Expression bug?

2023-03-02 Thread jose isaias cabrera
n upgrade sd=2023-02-" > > ro = re.compile(r"pn=(.+) ") > > r0=ro.match(s) > > >>> print(r0.group(1)) > > align upgrade > > > > > > This is wrong. It should be 'align' because the group only goes up-to > > the space. Thought

Re: Regular Expression bug?

2023-03-02 Thread Mats Wichmann
On 3/2/23 12:28, Chris Angelico wrote: On Fri, 3 Mar 2023 at 06:24, jose isaias cabrera wrote: Greetings. For the RegExp Gurus, consider the following python3 code: import re s = "pn=align upgrade sd=2023-02-" ro = re.compile(r"pn=(.+) ") r0=ro.match(s) print(r0.group(1)) align upgrade T

Re: Regular Expression bug?

2023-03-02 Thread 2QdxY4RzWzUUiLuE
) > align upgrade > > > This is wrong. It should be 'align' because the group only goes up-to > the space. Thoughts? Thanks. The bug is in your regular expression; the plus modifier is greedy. If you want to match up to the first space, then you'll need somethin

Re: Regular Expression bug?

2023-03-02 Thread Chris Angelico
On Fri, 3 Mar 2023 at 06:24, jose isaias cabrera wrote: > > Greetings. > > For the RegExp Gurus, consider the following python3 code: > > import re > s = "pn=align upgrade sd=2023-02-" > ro = re.compile(r"pn=(.+) ") > r0=ro.match(s) > >>> print(r0.group(1)) > align upgrade > > > This is wrong. I

Regular Expression bug?

2023-03-02 Thread jose isaias cabrera
Greetings. For the RegExp Gurus, consider the following python3 code: import re s = "pn=align upgrade sd=2023-02-" ro = re.compile(r"pn=(.+) ") r0=ro.match(s) >>> print(r0.group(1)) align upgrade This is wrong. It should be 'align' because the group only goes up-to the space. Thoughts? Thanks.

Re: Creating lambdas inside generator expression

2022-06-30 Thread Peter Otten
e, but by its reference. All checks therefore refence only the last variable. Yep, that is the nature of closures. (Side point: This isn't actually a generator expression, it's a list comprehension; current versions of Python treat them broadly the same way, but there was previously a diffe

Re: Creating lambdas inside generator expression

2022-06-29 Thread Chris Angelico
he lambda > not by its value, but by its reference. All checks therefore refence > only the last variable. > Yep, that is the nature of closures. (Side point: This isn't actually a generator expression, it's a list comprehension; current versions of Python treat them broadly the

Re: Creating lambdas inside generator expression

2022-06-29 Thread Antoon Pardon
it outputs: Check for bar False Check for bar False I.e., the iteration variable "z" somehow gets bound inside the lambda not by its value, but by its reference. All checks therefore refence only the last variable. This totally blew my mind. I can understand why it's happening, but is

Creating lambdas inside generator expression

2022-06-29 Thread Johannes Bauer
e only the last variable. This totally blew my mind. I can understand why it's happening, but is this the behavior we would expect? And how can I create lambdas inside a generator expression and tell the expression to use the *value* and not pass the "z" variable by reference? Cheers, Joe -- https://mail.python.org/mailman/listinfo/python-list

Re: Creating lambdas inside generator expression

2022-06-29 Thread Johannes Bauer
> Check for bar > False > Check for bar > False > > I.e., the iteration variable "z" somehow gets bound inside the lambda > not by its value, but by its reference. All checks therefore refence > only the last variable. > > This totally blew my mind. I ca

on a statement followed by an expression

2022-06-04 Thread Meredith Montgomery
(*) Question How can I, in a single line, write a statement followed by an expression? For example, if /d/ is a dicionary, how can I write d["key"] = value # and somehow making this line end up with d (*) Where does the question come from? >From the following experi

Re: on a statement followed by an expression

2022-06-04 Thread Alan Bawden
Meredith Montgomery writes: How can I execute a statement followed by a value in a single line? def roberry_via_reduce(rs): return my_reduce(rs, lambda d, r: ``increment and return d'', {}) The grammar or Python is deliberately designed so that the body of a lambda express

Re: Getting value of a variable without changing the expression in Python

2020-05-21 Thread Peter Otten
ansari.aafaq1...@gmail.com wrote: > Lets say i have a expression: > flowrate=(veloctiy*area) > i can find the flowrate with this expression > but if i dont wanna change the expression and want to find the velocity by > giving it value of area and flowrate ,how do i do this in p

Re: Getting value of a variable without changing the expression in Python

2020-05-21 Thread Richard Damon
On 5/21/20 5:56 AM, ansari.aafaq1...@gmail.com wrote: > Lets say i have a expression: > flowrate=(veloctiy*area) > i can find the flowrate with this expression > but if i dont wanna change the expression and want to find the velocity by > giving it value of area and flowrate ,how

Getting value of a variable without changing the expression in Python

2020-05-21 Thread ansari . aafaq1994
Lets say i have a expression: flowrate=(veloctiy*area) i can find the flowrate with this expression but if i dont wanna change the expression and want to find the velocity by giving it value of area and flowrate ,how do i do this in python? is there any library or package or module for this

Re: Why is a generator expression called a expression?

2020-04-21 Thread Chris Angelico
On Wed, Apr 22, 2020 at 6:12 AM Barry Scott wrote: > > > > > On 20 Apr 2020, at 10:29, Veek M wrote: > > > > On Mon, 20 Apr 2020 19:19:31 +1000, Chris Angelico wrote: > > > >> In the case of a genexp, the expression has a value which is a generator &g

Re: Why is a generator expression called a expression?

2020-04-21 Thread Barry Scott
> On 20 Apr 2020, at 10:29, Veek M wrote: > > On Mon, 20 Apr 2020 19:19:31 +1000, Chris Angelico wrote: > >> In the case of a genexp, the expression has a value which is a generator >> object. When you pass that to all(), it takes it and then iterates over > >

Re: Why is a generator expression called a expression?

2020-04-21 Thread Pieter van Oostrum
Veek M writes: > The docs state that a expression is some combination of value, operator, > variable and function. Also you cannot add or combine a generator > expression with a value as you would do with 2 + 3 + 4. For example, > someone on IRC suggested this > all(a == 

Re: Why is a generator expression called a expression?

2020-04-20 Thread Chris Angelico
On Mon, Apr 20, 2020 at 8:26 PM Veek M wrote: > > but one can do the following > (x for x in 'apple').next() * 2 > > def foo(): >(yield 2) > foo().next() * 3 > > (lambda x: 2)()*4 > > generator expr, yield expr, lambda expression > all requ

Re: Why is a generator expression called a expression?

2020-04-20 Thread Veek M
but one can do the following (x for x in 'apple').next() * 2 def foo(): (yield 2) foo().next() * 3 (lambda x: 2)()*4 generator expr, yield expr, lambda expression all require some modification (insertion of a .next or explicit () so it's quite confusing.. expressio

Re: Why is a generator expression called a expression?

2020-04-20 Thread DL Neil via Python-list
On 20/04/20 9:19 PM, Chris Angelico wrote: On Mon, Apr 20, 2020 at 6:51 PM Veek M wrote: The docs state that a expression is some combination of value, operator, variable and function. Also you cannot add or combine a generator expression with a value as you would do with 2 + 3 + 4. For

Re: Why is a generator expression called a expression?

2020-04-20 Thread Veek M
Also you will note, one can do: ( 2 if 3 > 2 else 4 ) + 4 so the () is just for precedence but otherwise a Conditional Expression works as expected by returning a value to be added to + 4. -- https://mail.python.org/mailman/listinfo/python-list

Re: Why is a generator expression called a expression?

2020-04-20 Thread Veek M
On Mon, 20 Apr 2020 19:19:31 +1000, Chris Angelico wrote: > In the case of a genexp, the expression has a value which is a generator > object. When you pass that to all(), it takes it and then iterates over but an object is NOT THE SAME as it's value! '2' is an object whi

Re: Why is a generator expression called a expression?

2020-04-20 Thread Chris Angelico
On Mon, Apr 20, 2020 at 6:51 PM Veek M wrote: > > The docs state that a expression is some combination of value, operator, > variable and function. Also you cannot add or combine a generator > expression with a value as you would do with 2 + 3 + 4. For example, > someone on IRC

Why is a generator expression called a expression?

2020-04-20 Thread Veek M
The docs state that a expression is some combination of value, operator, variable and function. Also you cannot add or combine a generator expression with a value as you would do with 2 + 3 + 4. For example, someone on IRC suggested this all(a == 'a' for a in 'apple') but

Re: python3, regular expression and bytes text

2019-10-14 Thread Eko palypse
Am Montag, 14. Oktober 2019 13:56:09 UTC+2 schrieb Chris Angelico: > > (My apologies for saying this in reply to an unrelated post, but I > also don't see those posts, so it's not easy to reply to them.) > > ChrisA Nothing to apologize and thank you for clarification, I was already checking my s

Re: python3, regular expression and bytes text

2019-10-14 Thread Chris Angelico
On Mon, Oct 14, 2019 at 10:41 PM Eko palypse wrote: > > Am Sonntag, 13. Oktober 2019 21:20:26 UTC+2 schrieb moi: > > [Do not know why I spent hours with this...] > > > > To answer you question. > > Yes, I confirm. > > It seems that as soon as one works with bytes and when > > a char is encoded in

Re: python3, regular expression and bytes text

2019-10-14 Thread Eko palypse
Am Sonntag, 13. Oktober 2019 21:20:26 UTC+2 schrieb moi: > [Do not know why I spent hours with this...] > > To answer you question. > Yes, I confirm. > It seems that as soon as one works with bytes and when > a char is encoded in more than 1 byte, "re" goes into > troubles. > First, sorry for a

Re: python3, regular expression and bytes text

2019-10-12 Thread Eko palypse
the current buffer to me. The problem is that the buffer can have all possible encodings. cp1251, cp1252, utf8, ucs-2 ... but scintilla informs me about which encoding is currently used. I wanted to realize a regular expression tester with Python3, and mark the text that has been matched by regular

Re: python3, regular expression and bytes text

2019-10-12 Thread MRAB
re.LOCALE are slow. It may be more efficient to decode text and use Unicode regular expression. Thank you, I guess I'm convinced to always decode everything (re pattern and text) to utf8 internally and then do the re search but then I would need to figure out the correct position, hmm -

Re: python3, regular expression and bytes text

2019-10-12 Thread Chris Angelico
On Sun, Oct 13, 2019 at 7:16 AM Richard Damon wrote: > > On 10/12/19 3:46 PM, Eko palypse wrote: > > Thank you very much for your answer. > > > >> You have to be able to match bytes, not strings. > > May I ask you to elaborate on this, sorry non-native English speaker. > > The buffer I receive is

Re: python3, regular expression and bytes text

2019-10-12 Thread MRAB
charsets. So even if you set the utf-8 locale, it would not help. Regular expressions with re.LOCALE are slow. It may be more efficient to decode text and use Unicode regular expression. +1 It's best to treat re.LOCALE as being for old legacy encodings that use/used 8 bits per character. Whe

Re: python3, regular expression and bytes text

2019-10-12 Thread Richard Damon
On 10/12/19 3:46 PM, Eko palypse wrote: > Thank you very much for your answer. > >> You have to be able to match bytes, not strings. > May I ask you to elaborate on this, sorry non-native English speaker. > The buffer I receive is a byte-like buffer. > >> I don't think you'll be able to 100% reliab

Re: python3, regular expression and bytes text

2019-10-12 Thread Chris Angelico
hen you're matching text (the normal way you use a regular expression), every element in the RE matches a character (or emptiness). For instance, the regular expression "^[bc]at$" has these elements: "^" matches emptiness at the start "[bc]" matches either "

Re: python3, regular expression and bytes text

2019-10-12 Thread Eko palypse
ow. It may be more efficient to > decode text and use Unicode regular expression. Thank you, I guess I'm convinced to always decode everything (re pattern and text) to utf8 internally and then do the re search but then I would need to figure out the correct position, hmm - some ongoi

Re: python3, regular expression and bytes text

2019-10-12 Thread Eko palypse
Thank you very much for your answer. > You have to be able to match bytes, not strings. May I ask you to elaborate on this, sorry non-native English speaker. The buffer I receive is a byte-like buffer. > I don't think you'll be able to 100% reliably match bytes in this way. > You're asking it to

Re: python3, regular expression and bytes text

2019-10-12 Thread Serhiy Storchaka
would not help. Regular expressions with re.LOCALE are slow. It may be more efficient to decode text and use Unicode regular expression. -- https://mail.python.org/mailman/listinfo/python-list

Re: python3, regular expression and bytes text

2019-10-12 Thread Chris Angelico
On Sun, Oct 13, 2019 at 5:11 AM Eko palypse wrote: > > What needs to be set in order to be able to use a re search within > utf8 encoded bytes? You have to be able to match bytes, not strings. > So how can I make it work with utf8 encoded text? > Note, decoding it to a string isn't preferred as

python3, regular expression and bytes text

2019-10-12 Thread Eko palypse
What needs to be set in order to be able to use a re search within utf8 encoded bytes? My test, being on a windows PC with cp1252 setup, looks like this import re import locale cp1252 = 'Ärger im Paradies'.encode('cp1252') utf8 = 'Ärger im Paradies'.encode('utf-8') print('cp1252:', cp1252) pr

"Regular Expression Objects" scanner method

2019-10-01 Thread ast
.7/library/re.html#regular-expression-objects nor with help import re lex = re.compile("foo") help(lex.scanner) Help on built-in function scanner: scanner(string, pos=0, endpos=2147483647) method of _sre.SRE_Pattern instance Does anybody know where to find a doc ? -- https://mail.python.

Re: repr = expression representation?

2019-05-17 Thread Ben Bacarisse
do) thing and I think he'd be happy. > You'll have to accept that not all Python objects can be represented > as literals. I don't think SR minds if the result is not a literal. I think the hope was simply that eval(repr(E)) === E for any expression E. You could, in a ve

Re: repr = expression representation?

2019-05-17 Thread Christian Gollwitzer
Am 17.05.19 um 06:13 schrieb Stefan Ram: However, look at this |>>> print( str( print )) | |>>> print( repr( print )) | . While it is nice that »str( print )« gives some useful information, I would expect »repr( print )« to give »print« - This is impossible. Python does not use "

Conversion between basic regular expression and extended regular expression

2018-11-17 Thread Peng Yu
Hi, I'd like to use a program to convert between basic regular expression (BRE) and extended regular expression (ERE). (see man grep for the definition of BRE and ERE). Does python has a module for this purpose? Thanks. -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-list

Re: regular expression problem

2018-10-29 Thread Karsten Hilbert
On Mon, Oct 29, 2018 at 05:16:11PM +, MRAB wrote: > > Logically it should not because > > > > >s'::15>>$ > > > > does not match > > > > ::\d*>>$ > > > > but I am not sure how to tell it that :-) > > > For something like that, I'd use parsing by recursive descent. > > It might be

Re: regular expression problem

2018-10-29 Thread MRAB
be either a length or a "from-until" > > - a length will be a positive integer (no bounds checking) > > - "from-until" is: a positive integer, a '-', and a positive integer (no sanity checking) > > - options needs to be able to contain nearly anythi

Re: regular expression problem

2018-10-29 Thread Karsten Hilbert
On Sun, Oct 28, 2018 at 11:57:48PM +0100, Brian Oney wrote: > On Sun, 2018-10-28 at 22:04 +0100, Karsten Hilbert wrote: > > [^<:] > > Would a simple regex work? This brought about the solution. However, not this way: > >>> import re > >>> t = '$$' > >>> re.findall('[^<>:$]+', t) > ['name', 'op

Re: regular expression problem

2018-10-29 Thread Karsten Hilbert
> Right, I am not trying to do that. I was, however, worried > that I need to make the expression not "trip over" fragments > of what might seem to constitute part of another placeholder. > > $<$::15>>$ > > Pass 1 might fill in to: > > $

Re: regular expression problem

2018-10-29 Thread Karsten Hilbert
On Mon, Oct 29, 2018 at 12:10:04AM +0100, Thomas Jollans wrote: > On 28/10/2018 22:04, Karsten Hilbert wrote: > > - options needs to be able to contain nearly anything, except '::' > > Including > and $ ? Unfortunately, it might. Even if I assume that earlier passes are "inside", and thusly "fil

Re: regular expression problem

2018-10-29 Thread Karsten Hilbert
ain '$' '<' '>' ':' > > > > - range can be either a length or a "from-until" > > > > - a length will be a positive integer (no bounds checking) > > > > - "from-until" is: a positive integer, a '

Re: regular expression problem

2018-10-28 Thread Thomas Jollans
On 28/10/2018 22:04, Karsten Hilbert wrote: > - options needs to be able to contain nearly anything, except '::' Including > and $ ? -- https://mail.python.org/mailman/listinfo/python-list

Re: regular expression problem

2018-10-28 Thread Thomas Jollans
On 28/10/2018 22:04, Karsten Hilbert wrote: > - options needs to be able to contain nearly anything, except '::' > > Is that sufficiently defined and helpful to design the regular expression ? so options isn't '.*', but more like '(:?[^:]+)*' (F

Re: regular expression problem

2018-10-28 Thread MRAB
On 2018-10-28 21:04, Karsten Hilbert wrote: On Sun, Oct 28, 2018 at 09:43:27PM +0100, Karsten Hilbert wrote: Let my try to explain the expression I am actually after (assuming .compile with re.VERBOSE): rx_works = ' \$< # start of match is

Re: regular expression problem

2018-10-28 Thread Brian Oney via Python-list
On Sun, 2018-10-28 at 22:04 +0100, Karsten Hilbert wrote: > [^<:] Would a simple regex work? I mean: ~$ python Python 2.7.13 (default, Sep 26 2018, 18:42:22)  [GCC 6.3.0 20170516] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> t = '$$' >>> re.f

Re: regular expression problem

2018-10-28 Thread Karsten Hilbert
On Sun, Oct 28, 2018 at 10:04:39PM +0100, Karsten Hilbert wrote: > - options needs to be able to contain nearly anything, except '::' This seems to contradict the "nesting" requirement, but the nesting restriction "earlier parsing passes go inside" makes it possible. Karsten -- GPG 40BE 5B0E C

Re: regular expression problem

2018-10-28 Thread Karsten Hilbert
On Sun, Oct 28, 2018 at 09:43:27PM +0100, Karsten Hilbert wrote: > Let my try to explain the expression I am actually after > (assuming .compile with re.VERBOSE): > > rx_works = ' > \$< # start of match is literal '$

Re: regular expression problem

2018-10-28 Thread Karsten Hilbert
Now that MRAB has shown me the follies of my ways I would like to learn how to properly write the regular expression I need. This part: > rx_works = '\$<[^<:]+?::.*?::\d*?>\$|\$<[^<:]+?::.*?::\d+-\d+>\$' > # it fails if switched around: >

Re: regular expression problem

2018-10-28 Thread MRAB
On 2018-10-28 18:51, Karsten Hilbert wrote: Dear list members, I cannot figure out why my regular expression does not work as I expect it to: #--- #!/usr/bin/python from __future__ import print_function import re as regex rx_works = '\$<[^<:]

regular expression problem

2018-10-28 Thread Karsten Hilbert
Dear list members, I cannot figure out why my regular expression does not work as I expect it to: #--- #!/usr/bin/python from __future__ import print_function import re as regex rx_works = '\$<[^<:]+?::.*?::\d*?>\$|\$<[^<:]+?::.*?::\d+-\d+>\$&

Re: Which class method is being called when we declare below expression?

2018-09-28 Thread Ben Finney
Ben Finney writes: > Ajay Patel writes: > > > L = [1,2,3] > > That's not an expression; it is an assignment statement. > > The right-hand side is an expression. […] in this case, [the object] a new > instance of 'list' […] is the result of evaluating t

Re: Which class method is being called when we declare below expression?

2018-09-27 Thread Ben Finney
Ajay Patel writes: > L = [1,2,3] That's not an expression; it is an assignment statement. The right-hand side is an expression. It will (at the top level) create a list. To create a new instance of the 'list' type, Python will call the type's '__new__' metho

Re: Which class method is being called when we declare below expression?

2018-09-27 Thread Chris Angelico
On Fri, Sep 28, 2018 at 8:52 AM Ajay Patel wrote: > > Hello gauys, > > Which list class method will call for below codes? > > L = [1,2,3] > And > L =[] None. Simple assignment does not call any methods. It just takes the value on the right hand side and says, hey, "L", you now mean that thing, k?

Which class method is being called when we declare below expression?

2018-09-27 Thread Ajay Patel
Hello gauys, Which list class method will call for below codes? L = [1,2,3] And L =[] Thanks, Ajay -- https://mail.python.org/mailman/listinfo/python-list

Re: pattern block expression matching

2018-07-22 Thread aldi . kraja
Thank you all for thoughtful excellent updates! Aldi -- https://mail.python.org/mailman/listinfo/python-list

Re: pattern block expression matching

2018-07-21 Thread Dan Sommers
On Sat, 21 Jul 2018 17:37:00 +0100, MRAB wrote: > On 2018-07-21 15:20, aldi.kr...@gmail.com wrote: >> Hi, >> I have a long text, which tells me which files from a database were >> downloaded and which ones failed. The pattern is as follows (at the end of >> this post). Wrote a tiny program, but

Re: pattern block expression matching

2018-07-21 Thread Peter Otten
MRAB wrote: > On 2018-07-21 15:20, aldi.kr...@gmail.com wrote: >> Hi, >> I have a long text, which tells me which files from a database were >> downloaded and which ones failed. The pattern is as follows (at the end >> of this post). Wrote a tiny program, but still is raw. I want to find >> term "

Re: pattern block expression matching

2018-07-21 Thread MRAB
On 2018-07-21 15:20, aldi.kr...@gmail.com wrote: Hi, I have a long text, which tells me which files from a database were downloaded and which ones failed. The pattern is as follows (at the end of this post). Wrote a tiny program, but still is raw. I want to find term "ERROR" and go 5 lines abov

pattern block expression matching

2018-07-21 Thread aldi . kraja
Hi, I have a long text, which tells me which files from a database were downloaded and which ones failed. The pattern is as follows (at the end of this post). Wrote a tiny program, but still is raw. I want to find term "ERROR" and go 5 lines above and get the name with suffix XPT, in this first

Re: Regular expression

2017-07-26 Thread Jussi Piitulainen
Kunal Jamdade writes: > There is a filename say:- 'first-324-True-rms-kjhg-Meterc639.html' . > > I want to extract the last 4 characters. I tried different regex. but > i am not getting it right. > > Can anyone suggest me how should i proceed.? os.path.splitext(name) # most likely; also: os.path

Re: Regular expression

2017-07-26 Thread Andre Müller
fname = 'first-324-True-rms-kjhg-Meterc639.html' # with string manipulation stem, suffix = fname.rsplit('.', 1) print(stem[-4:]) # oo-style with str manipulation import pathlib path = pathlib.Path(fname) print(path.stem[-4:]) -- https://mail.python.org/mailman/listinfo/python-list

Re: Regular expression

2017-07-26 Thread Peter Otten
Kunal Jamdade wrote: > There is a filename say:- 'first-324-True-rms-kjhg-Meterc639.html' . > > I want to extract the last 4 characters. I tried different regex. but i am > not getting it right. > > Can anyone suggest me how should i proceed.? You don't need

  1   2   3   4   5   6   7   8   9   10   >