« first day (4232 days earlier)      last day (699 days later) » 

2:29 AM
Is it possible to make
`line.startswith("|Frame:") or line.startswith("Frame:")`
shorter?
 
yes but it is not pythonic, explicit is better than implicit
import this
 
@XavierCombelle Sorry, could you please explain that in more detail. I can't see any relation wtih import this yet.
 
try in the REPL to type import this @John
 
Thank you for the rapid reply. But I have to achieve this goal by python. I can't use REPL.
Why
line_text_read.replace('\n', "").replace('\r', "")
dees not work?
"\n" could not be removed indeed.
The last question has been solved. Sorry for disturbing.
 
2:59 AM
>>> '1\n2'.replace('\n', '')
'12'
@John That totally worked
@John re.match('^\|?Frame:', line)
use the regex module (import re)
 
Thanks a lot.
How to remove substring which ends with "foo" or "foo_" in a specific string?
For example, replace all the string below to "OK":
"M_foo_OK"
"foo_OK"
"Mabc_foo_OK"
"M_abc_fooOK"
 
3:36 AM
@John I suggest looking at the regex module and search existing questions first, such as thread, thread, thread or thread.
 
4:22 AM
@Pherdindy the search facility in chat is not too bad if you know what you are looking for, but of course, if you get the search terms wrong, it can't guess
it supports searching by author and by tag (though that probably doesn't help much here)
@John the regex for that would be "foo_?" but of course, you could just split on foo and see if the result is longer than 1 and then trim off any leading underscore
>>> for test in ("M_foo_OK", "foo_OK", "Mabc_foo_OK", "M_abc_fooOK"):
...   parts = test.rsplit("foo", 2)
...   if len(parts) > 1:
...     print(parts[-1].strip("_"), test)
...   else:
...     raise ValueError("horror vacui")
...
OK M_foo_OK
OK foo_OK
OK Mabc_foo_OK
OK M_abc_fooOK
 
 
7 hours later…
11:31 AM
I have a problem. What I imagine as a solution goes like this: Inside a python code, I'm gonna use a cryptographic function to get a "signature" of a specific MySQL database's values and rows (I don't want the signature to include nothing meta).
This identifier would be stored, and later on let's say somebody changed a value in a table on the db... Then I would run the cryptographic function again, and it would return a different signature. If no values changed, the first and original signature would be provided,
proving it was not changed.Also this would not be terribly slow performance. Is it realistic? If so, what function would you use (don't care about security here), and how would you do the db "hashing" exactly? I'll appreciate any advice/insight.
 
I'd probably use the first sample code at docs.python.org/3/library/hashlib.html#hash-algorithms
 
11:46 AM
Hmm, does querying a database always return the data in the same order? That may be something you need to be careful about, it might change your hash
 
I don't think all dbs guarantee a particular order. Better include an order by clause to enforce deterministic behavior.
Oh, nice, MySQL has a built-in function for this. dev.mysql.com/doc/refman/5.7/en/checksum-table.html
 
Sounds like it's probably enough to send the DB content through adler32.
 
12:01 PM
It doesn't appear to mention cryptography, so I assume it's not incredibly secure against bad guys. If they can get the type signature of your table's columns, and its current checksum, perhaps they could generate an evil data set that has the same checksum.
In any case, no matter what algorithm you use, there's always a chance that two distinct data sets will have identical signatures. So strictly speaking, "I would run the cryptographic function again, and it would return a different signature" is impossible to guarantee
 
Actually I'm going with a different solution: checking binlogs. But thanks anyhow! :)
 
Sensible
 
Seems like there are other "immutable type" error changes in 3.10, at least in 3.9 I get TypeError: can't set attributes of built-in/extension type 'numpy.ndarray' whereas on 3.10 someone else gets TypeError: cannot set '__hash__' attribute of immutable type 'numpy.ndarray' when trying to do numpy.ndarray.__hash__ = ...
I don't want to bother with conda so I'll have to wait until my debian rolls out 3.10
hmm, even though 9.9 \approx 10
 
12:20 PM
Wait, you were wondering about 3.10...
tries on 3.10 my goodness, they really did it!
 
oddly enough I sort of find the "extension type" wording clearer
"Immutable how?? Oh, defined in C..."
Which also raises the question whether we can somehow trigger the same behaviour in pure python... probably not
# 3.15:
final class Foo: pass
ah no, it should be static final, probably :P
 
guys please don't delete my recent SO question/answer, assuming some of you are mods. I think it can really help beginners!
 
It's not mods who delete most of the posts, and your Q&A has no votes whatsoever so I'm not sure why you'd think this plea is necessary.
in any case the users watching the main site will decide based on their own individual assessments
 
@AndrasDeak--СлаваУкраїні class Foo(typing.Final):? :P
 
I've posted it 5 minutes ago Andras
 
12:32 PM
@AndrasDeak--СлаваУкраїні Eh. Weird that they only use it for the type. TypeError: cannot set '__hash__' attribute of immutable type 'tuple' but AttributeError: 'tuple' object attribute '__hash__' is read-only.
 
Alright I didn't know about mods. Let the people decide. I just hope experienced folks do not downvote it. I'm 100% confident it can help somebody else because it would have helped me. There was a similar answer but for a different db system, that I found while doing the research.
 
@MisterMiyagi do you think there could be edge cases where the former would not apply to the latter?
I guess exactly with an "immutable type" odds are good that the instance is also the same
 
 
2 hours later…
2:37 PM
Is there a Q&A that explains argument unpacking? (That is, foo(**kwargs) and not def foo(**kwargs):)
 
 
1 hour later…
Oh hey, reading pays off, apparently. Thanks :D
 
4:22 PM
@AndrasDeak--СлаваУкраїні A lot, actually: try dict.__hash__ = None.
"immutable type" feels somewhat misleading to me, since for me that imply that instances are immutable. When the type itself is immutable, that's just an "immutable object" to me.
 
4:43 PM
hey guys, i have installed the package 'python-certifi-win32' and since then pip has completely stopped working. Do you have suggestions as for what to do?
(a proper question i have opened - https://stackoverflow.com/questions/72280762/pip-broke-after-downlading-python-certifi-win32)
 
5:19 PM
@MisterMiyagi you probably mean on 3.10 but I don't have that :(
 
Is there a good way for having a "tagged union" that can be one of several cases which can be identified clearly?
I'm dealing with several situations of having "result or error" and passing around tuples of (result or None, error or None) gets cumbersome.
 
What's tagged about it? That you know if it's a result or an error or both?
 
Yeah.
There's no both, though.
 
So like a dict with keys 'result' and 'error'? :P
@MisterMiyagi ah
Also no neither, then. So exclusive either.
 
5:23 PM
Do you want to make the creation or the consumption leaner?
 
I blame Rust for giving me such ideas in the first place...
 
(result, 'res') if result else (error, 'err') might be worse on creation, but you can just look at the second item to check what it is...
 
@AndrasDeak--СлаваУкраїні Both, ideally. But consumption would be the most important. It's usually four lines at least.
 
or, you know, handle exceptions like a normal python person :P
 
There might be queues and such involved... 😓
 
5:34 PM
You could maybe try something a bit fancier like a Future-like object or a Maybe/Just/Nothing from haskell, but ultimately all of that is very low-level and should be abstracted away (i.e. turned into a real exception or return value) ASAP
 
 
2 hours later…
7:31 PM
stackoverflow.com/questions/72294937/… please tell me there's a canonical for this.
I see this issue all the time, I am intimately familiar with how it all works, and I have no idea what to put in the search box.
 
@KarlKnechtel wow, that was a lot of garbage to wade through looking for targets. The best thing I could find is stackoverflow.com/questions/62641895/… which is still pretty bad (in terms of a dupe target)
 
7:47 PM
sigh
 
 
2 hours later…
9:24 PM
https://stackoverflow.com/questions/339007/how-to-pad-zeroes-to-a-string

How are we intended to deal with old questions where the out-of-date answers are much higher voted (historically) than the currently most applicable ones?
 
What's out of date there? The top answer even has an f-string
Generally speaking, I see 3 options:
1) Add the new solution to the top answer(s)
2) Post a comment highlighting the newer solutions
3) Just let the votes speak for themselves
 
@KarlKnechtel use the new "trending sort"
 
the top answer supposes that all the modern approaches are "for numbers", which is not the case.
@AndrasDeak--СлаваУкраїні my goal is that when I dupe-hammer something, I can be reasonably confident that OP won't take bad advice from the dupe.
 
that's what comments are for
 
9:46 PM
How could you have not used the number 7 for your example?!? 😲 — Motti Aug 13, 2019 at 8:54
Really
 
I don't get it. Anyway, the number was probably chosen by fair dice roll.
 
 
2 hours later…

« first day (4232 days earlier)      last day (699 days later) »