@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.
@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! 🎉
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/….
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
> 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
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.
@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
@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?
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
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?
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.
@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
@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.
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.
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
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?
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
@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.
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
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.
@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.
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--СлаваУкраїні 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.
@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.
@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.
@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.
@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 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--СлаваУкраїні 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 :-)
@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
@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))
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}