On Wed, 30 Mar 2022 at 15:11, Stephen J. Turnbull
wrote:
>
> Chris Angelico writes:
>
> > [fruit] = sscanf(sample, "%*sfruit:%s\n")
>
> I'm warming to this idea. It does hit the sweet spot of doing exactly
> what you want -- except when it can't do what you want at all. :-)
> It's concise and
On Tue, Mar 29, 2022 at 12:35:56AM -0700, Paul Bryan wrote:
> I wonder if applying regular expressions would sufficiently address
> your use case.
'Some people, when confronted with a problem, think "I know, I'll use
regular expressions." Now they have two problems.' -- Jamie Zawinski
Apart
On Tue, Mar 29, 2022 at 4:08 PM Steven D'Aprano wrote:
> I have no strong opinion on whether this simple function should be built
> into the string class,
I do -- this is not sufficiently general to be a string method.
> but I do have a strong opinion about re-writing
> it into a slower,
On Tue, Mar 29, 2022 at 11:00:41AM +0300, Serhiy Storchaka wrote:
> 28.03.22 15:13, StrikerOmega пише:
> >And I want to grab some kind of value from it.
>
> There is a powerful tool designed for solving such problems. Is is
> called regular expressions.
>
> >sample.grab(start="fruit:",
On 3/29/22 14:41, Christopher Barker wrote:
> Ethan Furman queried:
>> The `__dict__` is needed to store the field names -- did you add `__dict__`
to the
>> `__slots__`?
>
> Nope — though the error indicated that I couldn’t add anything to __slots__
when subclassing tuple. But I may have
>
On Wed, 30 Mar 2022 at 10:08, Steven D'Aprano wrote:
> Here's the version of grab I used:
>
> def grab(text, start, end):
> a = text.index(start)
> b = text.index(end, a+len(start))
> return text[a+len(start):b]
>
This is where Python would benefit from an sscanf-style parser.
> >> The `__dict__` is needed to store the field names -- did you add
> `__dict__` to the
> >> `__slots__`?
Nope — though the error indicated that I couldn’t add anything to __slots__
when subclassing tuple. But I may have misunderstood the error.
Also, frankly, I’m completely confused by
On Tue, Mar 29, 2022 at 09:12:36AM +0200, StrikerOmega wrote:
> The grab function would find the index of the first occurrence of the
> "start" string in the parent string and then the next occurrence of the
> "end" string starting from that index and return the substring between
> those.
That's
Chris Angelico writes:
> [fruit] = sscanf(sample, "%*sfruit:%s\n")
I'm warming to this idea. It does hit the sweet spot of doing exactly
what you want -- except when it can't do what you want at all. :-)
It's concise and quite powerful, applicable to many common use cases.
I do have one
@Michael: As the previous author I fully support this proposal! ;) Thank you
for the revival. For reference, since you linked one of the answer of the
original thread, this is my original proposal:
https://mail.python.org/pipermail/python-ideas/2016-April/039836.html
Both suggested
On Tue, Mar 29, 2022 at 06:23:06AM +1100, Chris Angelico wrote:
> If I'm reading this correctly, you're defining a "conflict" as finding
> two implementations of the same-named method in independent subtrees
> of inheritance - that is, when you say "class Pizza(Crust, Topping):",
> you're
On Tue, 29 Mar 2022 at 21:34, Steven D'Aprano wrote:
>
> On Tue, Mar 29, 2022 at 06:23:06AM +1100, Chris Angelico wrote:
>
> > If I'm reading this correctly, you're defining a "conflict" as finding
> > two implementations of the same-named method in independent subtrees
> > of inheritance - that
I think I'd often reach for an optimized version of something like this
over SimpleNamespace or even a Dataclass if it existed.
On Tue, Mar 29, 2022, 2:04 AM Christopher Barker
wrote:
> Finally got around to fleshing out my idea here.
>
> My thought was to make an anonymous names tuple not as a
On Fri, Mar 25, 2022 at 12:17 AM Brendan Barnwell
wrote:
> On 2022-03-24 10:43, Andrew Svetlov wrote:
> > The proposal doesn't work well with type hints: atuple(a=1, b=2) and
> > atuple(a="a", b="b") generates the same type.
>
> I'm neither here nor there on the original proposal, but I
malmiteria writes:
> class An:
> def method(self):
> print('An')
> class A[n-1](An): pass
> ...
> class A1(A2): pass
> class A0(A1):
> def method(self):
> self.__as_parent__(An).method()
>
> A0().method() prints 'An'
Of course it prints 'An', and so does
class A00(A1):
Thanks for teaching me about the __getitem__ method of the Match class. I
always do .group(1) before.
Abdulla
Sent from my iPhone
> On 29 Mar 2022, at 12:02 PM, Serhiy Storchaka wrote:
>
> re.search(r'fruit:(.*?)\n', sample)[1]
___
Python-ideas
Finally got around to fleshing out my idea here.
My thought was to make an anonymous names tuple not as a new anonymous
class, but simply as an instance with specific field names. So all of these
would the the same class, but they would also be lightweight, and all
subclasses of tuple -- from a
On Tue, Mar 29, 2022 at 6:37 AM Joseph Martinot-Lagarde <
contreba...@gmail.com> wrote:
> Both suggested implementations are very interesting. If I'm not wrong they
> have exactly the same behavior (except for __dict__).
>
pretty close, yes -- probably differences with pickling, and if you did
On 3/29/22 09:14, Christopher Barker wrote:
> [...] I tried to use __slots__ in TupleWithNames, but apparently you can't
use __slots__ in a
> tuple subclass ('cause tuple's already using it ??) -- but that could be done
in a builtin.
> then it wouldn't need a __dict__
The `__dict__` is needed
On 3/29/22 09:57, Ricky Teachey wrote:
> On Tue, Mar 29, 2022 at 12:49 PM Ethan Furman wrote:
>> The `__dict__` is needed to store the field names -- did you add `__dict__`
to the
>> `__slots__`? (Of course, if you've added `__dict__` then you lose the
limited size
>> of `__slots__`.)
>
>
On Tue, Mar 29, 2022 at 12:49 PM Ethan Furman wrote:
> On 3/29/22 09:14, Christopher Barker wrote:
>
> > [...] I tried to use __slots__ in TupleWithNames, but apparently you
> can't use __slots__ in a
> > tuple subclass ('cause tuple's already using it ??) -- but that could
> be done in a
Alright everyone.
First of all, thanks for all your answers, I really appreciate the discussion
we're having.
Turns out i won't have so much free time tonight, and probably tomorrow night
either, so i won't be able to answer the last few comments before some then.
I apologise if i'm missing
28.03.22 15:13, StrikerOmega пише:
And I want to grab some kind of value from it.
There is a powerful tool designed for solving such problems. Is is
called regular expressions.
sample.grab(start="fruit:", end="\n")
>> 'apple'
re.search(r'fruit:(.*?)\n', sample)[1]
On Sat, 26 Mar 2022 at 18:01, malmiteria wrote:
> Hi,
>
> Before anything, i made a github repository about this topic here :
> https://github.com/malmiteria/super-alternative-to-super
>
> The core of what i wanna discuss here is that i don't think mro and super
> (mainly because it relies on
On 29/03/2022 03:18, Michael Smith wrote:
On Mon, Mar 28, 2022 at 16:06 Patrick Reader
wrote:
I would like to be able to use a `yield from` expression in a
`return`
statement without parentheses, as a small quality of life tweak, i.e.:
return yield from gen
instead of
On Tue, 29 Mar 2022 at 18:13, StrikerOmega
wrote:
>
> The grab function would find the index of the first occurrence of the "start"
> string in the parent string and then the next occurrence of the "end" string
> starting from that index and return the substring between those.
>
This sounds
The grab function would find the index of the first occurrence of the
"start" string in the parent string and then the next occurrence of the
"end" string starting from that index and return the substring between
those.
So in the example:
sample = "sqrt(sin(x) + cos(y))"
The grab function would
I wonder if applying regular expressions would sufficiently address
your use case.
On Mon, 2022-03-28 at 14:13 +0200, StrikerOmega wrote:
> Hello everyone,
>
> When I am coding in Python I often encounter situations where I have
> a string like this one.
>
> sample="""
> fruit:apple
>
28 matches
Mail list logo