« first day (4508 days earlier)      last day (662 days later) » 

09:24
Hi everyone
I want to make an algorithm for python code
10:11
Hello. Do you have a specific question? You can just ask.
10:23
Spent 2 hours rewriting my code only to get AssertionError: pass_fds not supported on Windows. :/
maybe show an example of what you're trying to do with subprocess that either use mkfifo or os.pipe and I'll play around with that
I have a hunch that win32pipe might work in this case, but need an MRE I can compare to
@Aran-Fey Does Windows have a separate way of doing this, perhaps? Since you are touching OS specific stuff, you will likely need a (thin) compatibility layer anyway.
@NordineLotfi This but without stdin
Preferably async, but if not I'll just to_thread it
Why is it so hard to send data from one process to another? Software is stupid
@Aran-Fey just to confirm, when you say "without stdin", do you mean by using named pipe (like on Linux) using os.pipe/mkfifo?
Yeah
10:36
got you
@MisterMiyagi I'm not aware of any alternatives for pipes that Windows provides. But fortunately, googling this led me to realize that I was wrong about sockets yesterday; ffmpeg can take input through sockets! 🎉
11:04
That's reassuring because I thought ffmpeg could do anything
/ffmpeg make me a coffee
sips coffee
 
1 hour later…
12:10
stackoverflow.com/questions/75493170 what should we be doing with these sorts of questions?
it seems to me like there's a common form that gets repeated a lot
maybe this is a canonical opportunity. Maybe something like "Why do I get library version conflicts with pip? How can I resolve them?"
Anyone remember Trigger's broom?
It turns out that property objects are a lot like that broom; if you replace all the parts, is it still the same property object? See stackoverflow.com/questions/75487566/….
I don't get the reference, but that sounds like the ship of theseus?
@KarlKnechtel: it is exactly like the ship of Theseus.
anyway, I have no idea what the question is supposed to be there; it definitely shouldn't be using that image to show the terminal; and several paragraphs of analogy there are definitely not making the answer seem either more clear or more accessible
12:28
@C.x.property is above my paygrade, will have to ponder this
@some_property.getter returns a copy of some_property but overrides the getter
That part I got. Accessing descriptor.property is what took me by surprise.
Oh, I didn't notice that. Looks like a mistake?
Huh, is this also why one should use the same name for all accessors, to ensure that you accumulate the methods? Assuming that's what happens.
@AndrasDeak--СлаваУкраїні Yup
AttributeError: 'property' object has no attribute 'property' definitely a mistake
12:34
@MartijnPieters huh ^
But then how do you keep the original? Use C.x.setter first and then the new name?
Keep the original what? Property? Getter? Setter?
Reference C.x once, then chain the additional attributes on the new, local reference.
> If you do need to keep some part of the property you constructed for C (e.g. because you have a deleter or a docstring to preserve), then you only need to reference C.x once
But then I get it
12:37
Without a base class, when you use a @property decorator on a getter, this produces a new property instance which you then reference by it's name to attach a setter.
This is no different, but you start with @C.x instead of @property. But it's pointless if all you do is replace all the hooks.
@AndrasDeak--СлаваУкраїні I missed this part to start with, that should've been C.x.getter.
That's what I eventually figured, thanks
I can't get DALL-E to produce images of a push broom. It sticks to classic witches brooms. :-/
13:42
@MartijnPieters can confirm. I'm guessing whoever labeled the data for broom didn't bother tagging the push broom as push broom. Or maybe they did, but just as "broom" or similar. If it's the latter, you might still be able to get one with some testing or with enough repeated execution
14:37
Hi. I want to give lambdify in sympy a list for input.
@MehdiMiri that's unclear. Do you want a single scalar-valued multivariate function? Multiple scalar-valued univariate functions? A single array-valued univariate function? Something else?
In docs.sympy.org/latest/modules/utilities/… both relevant arguments can be lists
14:53
for example:
L = [1,2,3,...]
func = sympy.lambdify([x,y,z,...], x*y*z*...)
func(L)
func(*L)
This is not sympy, this is python.
(But I'm on mobile, can't actually test anything)
I'm not familiar with sympy, but I doubt it can operate on lists. As far as I can tell, there are no loops that would let you iterate over the elements of a list
 
2 hours later…
16:57
whee. canonicalizing a bunch of duplicates, discovering that the question scores have basically no correlation with how well they were asked
Don't know if this is sarcasm, but I thought you already noticed that before? At least I know I did a couple of months ago for one of my answer
Yesterday, when browsing around, I also found something related to that on stackapps: stackapps.com/questions/3105/…
Glad some people openly admit it at least, even if it's not on purpose for some, but just out of habit
18:01
@AndrasDeak--СлаваУкраїні What can't you test on mobile?
What is the best practice when you want your __str__ and __repr__ methods to return the same thing? Call one from the other, repeat your code, something else?
@MattDMo Are you worried that a superclass changes the default behavior?
No, this particular class doesn't inherit from anything (other than object, of course). I'm just wondering if it's common practice to call dunder methods from other dunder methods. I don't see why not, but there may be gotchas I haven't thought about.
@matt Then I'd just implement __repr__.
Right, I am, but should I repeat the code I have in __str__, or just have it be return self.__str__()?
18:17
I'd implement __repr__ instead of __str__.
Oh, I understand.
Unless you have a reason to not trust __str__'s default behavior of calling __repr__...
What might happen to cause that?
Cause what? That default behavior, or a deviation from it?
@MattDMo str falls back on repr
@KellyBundy anything needing a python interpreter
18:33
@KellyBundy a deviation
@AndrasDeak--СлаваУкраїні But there online ones. I use them all the time.
@AndrasDeak--СлаваУкраїні yeah, I remember now. I knew there was something better than repeating code or calling the other method...
@KellyBundy It's not just the lack of interpreter, it's also the lack of decent keyboard and lack of investment when I'm not the one asking the question
@MattDMo when in doubt look at the data model docs.python.org/3/reference/datamodel.html
@AndrasDeak--СлаваУкраїні So it's not like you "can't", you're just not masochistic enough :-)
(I've been almost exclusively on mobile for over half a year... One of these days I'll get around to fixing my PC situation...)
19:24
@KellyBundy what do you use as online interpreter? I know PM2Ring use sagemath but wondering if there is anything else that I never heard of
19:44
There's repl.it, colab, tio.run and ato.pxeger.com to name a few of various complexity and use cases and data stealing
20:04
@AndrasDeak--СлаваУкраїні I mostly use TIO, as it has the most minimalistic interface, works best on the phone. ATO if I need a newer Python version. The Replit app (not the website) if I need packages that TIO/ATO don't have. Colab sometimes. myCompiler.io if I want a short link to share.
@NordineLotfi Oops, above was meant for you.
@AndrasDeak--СлаваУкраїні Data stealing?
Well colab is google colab, 'nuff said. And I don't know anything about repl.it but anything that's beyond a single guy running a server is questionable to me.
Hmm, not 'nuff to tell me anything useful. Google is fine in that regard, in my experience (both as user and as employee).
But I'm not interested in debating it, let's not waste time :-)
20:43
Hi guys, Why the strings in python are immutable? I know that it's a design choice by developers of python but what was the rationale behind it?
Well, you definitely need immutable strings so that they can be used as dictionary keys. So then you have to ask yourself, what do you gain by also adding mutable strings? Is it worth the effort? Probably not
70
Q: Why are Python strings immutable? Best practices for using them

Sergey What are the design reasons of making Python strings immutable? How does it make programming easier? I'm used to mutable strings, like the ones in C. How am I supposed to program without mutable strings? Are there any best practices?

There is a mutable string type, it is called bytearrayJanne Karila Dec 30, 2011 at 18:01
another reason that I'm not sure will be mentioned there, is that it helps enable Python's flexible-width string representation. If you tried to add '前' to a string that currently only contained ASCII characters, you'd need to reallocate everything anyway
Pythoff, get back in your grave!
20:56
2011, to be fair.
@Aran-Fey Anyways you can modify strings by using someString='x'+someString[1:] so I am not sure if your dictionary keys argument make a lot of sense to me. About the benefits part don't you think it will be convenient if we need to modify the strings for certain tasks. To support my argument I would like to add that strings are immutable in C/C++, Java for sure.
Why the focus on strings? Python integers are also immutable.
@Rishi please read and understand nedbatchelder.com/text/names.html before we continue this discussion further
@Rishi You can "modify" strings in the sense that you can create new strings, sure.
21:09
And I don't even know where to start with the dict key thing...
@KarlKnechtel Thanks @KarlKnechtel the class argument somewhat makes sense probably.
Technically python has mutable strings in the form of collections.UserString
class MutableString(str):
    def mute(self):
        return ''
Now we just need a MutatableString
21:14
It's generally simpler & safer to make objects immutable. Always use immutable objects unless you specifically need mutability. If everything's mutable, you have to pay close attention to where & when stuff gets mutated.
@AndrasDeak--СлаваУкраїні Yeah I already had an Idea about the same. I understand that for string assignment to other variable refers to original variable, i.e. changes will be reflected in both but I am not sure if it does add a value to my question about string immutability. Correct me if I am wrong!
@Rishi I can't really tell if you're wrong because I don't understand what you just said, but your earlier message that I replied to suggests that you're wrong
@Aran-Fey Thanks for pointing out.
1. you said "you can modify strings by using someString='x'+someString[1:]" in a mutability context which suggests you don't actually understand mutability, and
2. you finished this sentence with "so I am not sure if your dictionary keys argument make a lot of sense to me" which I can only interpret in context as saying "you can already change strings even though they can be dict keys" which is funny because this would be equivalent to saying "strings are already mutable" (when we're talking about them being immutable), but I have no better interpretation of your logical reasoning here.
so, again, I can't tell for sure that you're wrong but it sure looks like it when I squint
Note that I'm only focusing on your mental model because I want to end up in a state that we both have the same understanding when we debate about mutability.
@AndrasDeak--СлаваУкраїні I see. Sorry if I am not clear enough, anyways let's talk in code.
a="rishi"
dict={a:1}
print(dict[a])
print(a)
a='n'+a[1:]
print(dict[a])
print(a)
what do you think will be the output of the above program?
21:21
you can try editing that block of code and clicking the "fixed font" button that appears, for code formatting
@Rishi For future reference, we have a code formatting guide to chat here. It's not you, it's the chat engine that's weird.
Here's another article about how Python names work. It's a bit shorter than Ned's article, but it has cute diagrams.
@Rishi that doesn't really have anything to do with mutability beyond "strings can be used as dict keys"
In contrast, Aran's point is that if strings were mutable in Python, you wouldn't be able to do {a: 1} or dct[a] with a string-valued a in the first place.
@AndrasDeak--СлаваУкраїні sure!
it's not a question of "oh no how do I change this variable to use a different key in my dict". It's "oh no this type is not hashasble so trying to use it as a dict key causes a TypeError!".
@AndrasDeak--СлаваУкраїні I knew about all of those except for ato :o Thank you
21:27
@AndrasDeak--СлаваУкраїні Well it's possible in C++, right? We can create maps with strings as keys and strings are mutable in C++. So technically that could have been implemented in python.
@KellyBundy didn't know about myCompiler.io, Nice. I never tried the Replit app, just the website.
@Rishi Well if we start from "why are strings immutable" and we reach "we could change the fundamental assumption that only immutable objects are hashable" then we're really going down the "why isn't Python something else?" rather than a fruitful discussion.
I didn't know there's a repl.it app. The usual website is virtually unusable on a phone.
@AndrasDeak--СлаваУкраїні I agree. See I know it's a kind of design choice made by C++/Python developers, and they had different opinions. I was just curious about the rationale for the same.
Python wants hashes to be fixed during the lifetime of an object. Otherwise you could run into issues with a and b being two different objects, then you have, say, a set s = {a} which makes use of a's hash when it was added, then we mutate a that changes its hash (otherwise "a == b implies hash(a) == hash(b)" would be shaky), then you have a different object b == a equal to the new state, and suddenly b not in s which is weird.
@Rishi OK, we can discuss that. I think the motivation was that Guido was writing a language and C++ was already designed, so he designed something else :P
Note that you could have trivial mutability changing state that doesn't affect equality and hashes, but then are you really mutating anything? Yes, but also meh.
Actually, you don't even need b. I thought identity check came first
>>> class HashableList(list):
...     # don't try this at home!
...     def __hash__(self):
...         return hash(tuple(self))
...
... a = HashableList([1])
... s = {a}
... a[0] = 42
... assert a not in s
... assert s.pop() is a
(I originally had next(iter(s)) instead of s.pop() to preserve the set but that might be more obscure for some readers)
I thought set.__contains__() used RichCompareBool or whatever that's essentially a is b or a == b
Hmm... I can't quite explain why the above example works the way it does and yet NaN is correctly identified in sets
Ah, it checks the hash, and only does the comparison if the hashes are the same.
21:45
@AndrasDeak--СлаваУкраїні :):)
@Rishi In C++, can you modify strings that are keys in a map?
if I wrote a hashmap implementation I'd pass keys by value to make sure the map owns all its data, but I'm not very creative
@AndrasDeak--СлаваУкраїні Well, the example below is a bit over my head but I am trying to understand it. Also, what do you mean by identity check?
@Rishi the example takes the usual builtin list and subclasses it and makes that subclass "hashable". Now you can use the "hash" in a set. But if you mutate the object, which changes its hash (which is my premise, as I mentioned), a in s is no longer true, even though if you remove one item from the set (the only item that's in there) you get a itself, i.e. it was in the set. Nonsensical result from set.__contains__() which governs what a in s evaluates to.
@KellyBundy Yup by default strings are mutable there. Also, it copies the string value to create a map.
21:53
by identity check I specifically mean a is b
@PM2Ring Yeah, if I remember correctly, the replit website editor jumped the cursor around randomly, ate what I typed, etc. Or maybe I confuse it with LeetCode. Both are horrible on the phone. But the replit app is alright. But I still prefer TIO's editor.
A few years ago I looked at python interpreter apps, I found only one significant-looking free app, and it asked for such ridiculous permissions that I gave up.
@Rishi I know C++ strings are mutable, but my question is can you mutate them when they're in the map as keys.
phones are useless for coding anyway
@AndrasDeak--СлаваУкраїні gotchas, thanks for it clearing it up. Can you please explain why the last line assert s.pop() is a not throwing error?
21:58
@KellyBundy "it copies the string value to create a map" addresses that part of your question though
@AndrasDeak--СлаваУкраїні Depends on what you're coding.
Kelly, are you aware there's a "directed reply" feature in chat? It helps follow parallel discussions.
@AndrasDeak--СлаваУкраїні Not really, as it doesn't say whether we can modify those copies.
@AndrasDeak--СлаваУкраїні Now I am aware.
Did I do that correctly?
yup, thanks
@KellyBundy why would you have access to the keys stored internally by the map?
@KellyBundy Do you mean modifying the key itself? If yes then have a look at this, stackoverflow.com/questions/5743545/…
22:03
@Rishi bah, I posted a long reply but my internet went down at it was lost. s still contains a, since s = {a} and a itself is still the same object, it's just the state of a that changed. Hence mutability. So the real question is why a not in s is True. And that's because we made a mutable object hashable which was a bad idea.
@Rishi weird
I wonder how that affects the performance of the container
@AndrasDeak--СлаваУкраїні Ah :(. Anyways, I got it now, thanks!!
@Rishi please edit that word
Thanks. We try to stay compatible with primetime US TV or similar.
@AndrasDeak--СлаваУкраїні I suspect you don't have access to them. And that's my point. That in C++ you can have string mutability and use strings in maps because they're copied and they thereby become immutable (if I suspect right... And I don't really want to read a lengthy q&a about it, I don't like C++ anyway :-)
@AndrasDeak--СлаваУкраїні Sorry, new here so I wasn't aware of that. Will take care of this in future.
@Rishi sure, no worries
@KellyBundy the linked post suggests that you can actually access the keys and mutate them. But even if you couldn't, the argument would be technically valid that mutable objects are used as keys :P
22:09
@AndrasDeak--СлаваУкраїні As maps are internally implemented as balanced trees. If I am thinking correctly then renaming can be implemented using a deleting of the old key and insertion of a new one which will require O(log(sizeOfMap))
2011 answer says keys should be immutable... stackoverflow.com/a/5743701/5067311
@Rishi but what you're saying suggests that the key is not being mutated, instead it's being replaced
Ah, yes, I misread the top answer. nodeHandler.key() = 2; doesn't mutate the key, it mutates the mapping item. It replaces the key.
I guess we're back to "understand what mutability is first"
Speaking of silly dict key tricks,
Apr 11, 2017 at 19:21, by PM 2Ring
class NotStr(str):
    def __hash__(self): return id(self)

print({NotStr('spam'): i for i in range(4)})
#output
{'spam': 0, 'spam': 1, 'spam': 2, 'spam': 3}
oh yeah, the Roll Safe version of "make your class hashable again"
@AndrasDeak--СлаваУкраїні Yeah, exactly.

« first day (4508 days earlier)      last day (662 days later) »