« first day (3857 days earlier)      last day (1074 days later) » 

12:57 AM
I am trying to remove the following dates which are represented in a generated code i.e. "05/07/21 05/07/21". Is there a way of specifying the digits i.e. XX/XX/XX to be deleted from my code?
 
1:43 AM
I have this so far :

fin = open("/home/pi/media.txt")
fout = open("/home/pi/media2.txt", "w+")
delete_list = ['Live: ', ':', 'View More Detailed Calendar HERE', ' / / to / / ']
for line in fin:
for word in delete_list:
line = line.replace(word, "")
fout.write(line)
fin.close()
fout.close()

everything gets deleted except for the dates which are random and need to get rid of them.
 
2:37 AM
regex?
 
@Aran-Fey Very fun exercise, thanks for sharing. My analysis: gist.github.com/kms70847/d09f991dc9394f2feb3aa3910f935447. (Spoiler warning times a million)
 
@Aran-Fey That code made absolutely no sense to me
 
Not pictured: the half a dozen janky diagnostic functions and classes I had to write to figure out half of the things that I explain in half a line
 
I didn't know you could put called functions in a class's inheritance area...
 
"metaclasses are easy", I write. "metaclasses were not easy", I think.
@12944qwerty Likewise. My analysis explains why it is permitted in this case.
 
2:42 AM
Did Aran overwrite some basic functions though-
The names probably were the main cause of my confusion
 
print gets overwritten by the class print declaration. If you want to experiment with printing stuff after that, you should do something like show = print at the top of the code, so you can still access the original function.
 
@12944qwerty can you give an example?
 
I know... I didn't realize that print might've been a class...
Though it kind of makes sense
@Ahmed.B \d\d/\d\d/\d\d This will check for the XX/XX/XX
I accidentally pressed enter early :(
It's not the best way, but I'm also not the best at regex
 
I tried using partition and works perfectly but when writing to the text file it writes everything on 1 line
 
The best way is whatever always runs without crashing and produces the correct output ;-)
 
2:55 AM
@Ahmed.B Have you tried debugging what you're writing before you write it?
Also, I suggest opening a question. It gets kinda hard to read code in chatrooms
oh mah god.... I just realized dict.get is a thing....
I've always used indexing
 
@12944qwerty well yeah I have but I am on a raspberry pi at the moment so it's a little difficult.
 
Why don't you try debugging before producing?
 
@12944qwerty so you are suggesting I should use this \d\d/\d\d/\d\d with regex ?
 
It should work... I suggest using regex101 just for testing the regex
 
I tried \d\d/\d\d/\d\d with my code above and it didn't get rid of the dates
 
3:00 AM
What exactly did you do?
Also please make a question and provide everything you can on it... It'll be so much easier
 
MCVEs are very good and important.
 
@12944qwerty it worked :) thanks
 
Agreed... I never feel like reading through lengthy questions unless they're readable
And readable is mcve (for me at least)
 
 
4 hours later…
gig
6:41 AM
https://www.kaggle.com/punitchoudhary/tpu-offline-handwriting-recognition-cnn HI here I dont understand why the forms.parsing.txt is can anyone explain me if worked on this?

I am trying for word recognizer using cnn
 
7:14 AM
@Kevin Wow, good job!
I'm glad you enjoyed it, because, I, uh, I happen to not have a bajillion quatloos on me right now. I'll let you know if I ever win the lottery though
 
 
4 hours later…
10:46 AM
As the chairman of the national quatloo mint, I can just have the lads down on the floor print me up a ceremonial bajillion quatloo note. I'll only spend it if I can find a store that can break it into 20s.
 
 
1 hour later…
12:08 PM
Can anyone help in reopening this question ~ How to pass a class with Toplevel widget in Tkinter [duplicate]
 
 
1 hour later…
1:27 PM
Hey, I feel like there is an easier method than using 9 if statements here. Any ideas> Temperature converter that converts temp into Celsius, Fahrenheit and Kelvin using Tkinter
 
1:49 PM
It's not just the ifs. But also opt[lhs.get()] etc a dozen times
 
When you have N different units of measurement that are all convertible between one another, writing (n-1)^2 formulas for all possible conversions is more work than necessary. Instead, choose one unit to be your "standard unit". write n-1 formulas to convert any other unit to that unit, and write n-1 formulas to convert that unit to any other unit.
As a concrete example. Choose Kelvin as the standard unit, because that's the SI unit for temperature. Implement c_to_k and f_to_k and k_to_c and k_to_f. If the user wants to convert C to F, call k_to_f(c_to_k(x)).
You could even write a "polymorphic" function with arguments like convert(x, from_="C", to="F"). Then OP's nine conditional block simplifies down to zero or one conditionals.
 
2:09 PM
class Temperature:
    def __init__(self, value, base):
        self.value = getattr(self, f'from_{base}')(value)

    def from_C(self, value):
        return value + 273.15

    def to_C(self):
        return self.value - 273.15
or something like that maybe?
just an oop'd version of your suggestion
mind you - my brain's in a stubborn mood in terms of operating this afternoon... so could well be a completely insane idea
 
@Kevin Hmmm that is a very interesting solution
@Kevin This would follow the same concept as mentioned before right
 
Yeah
 
Let me try to implement something like that
 
Not tested yet, as you can tell from the syntax error I just noticed
 
Ill write an expanded form and then try to simplify it then
 
2:18 PM
def convert(temp, from_, to):
    if from_ == to: return temp
    to_kelvin_formulas   = {"C": lambda t: t + 273.15, "F": lambda t: (t + 459.67) * 5 / 9, "K": lambda t: t}
    from_kelvin_formulas = {"C": lambda t: t - 273.15, "F": lambda t: t * 9 / 5 - 495.67,   "K": lambda t: t}
    return from_kelvin_formulas[to](to_kelvin_formulas[from_](temp))

t = 42
for a in "KFC":
    for b in "KFC":
        print(f"convert({t}, {repr(a)}, {repr(b)}) == {convert(t, a, b)}")
Ok, now it's tested.
Away with thee, ver 0.1...
Exercise: suppose you are very lazy and don't want to write the formula for f-to-k and the formula for k-to-f. Can you make the computer derive one from the other? What if the formula is more complicated than unit_a = x*unit_b + y?
(The formula that you do write by hand does not necessarily need to be a lambda, or even a syntactically valid python expression)
 
Educational question or real one?
 
Educational, mostly.
 
I mean, are you looking for an answer, or are you trying to teach Cool Cloud? :D
 
are you thinking of a certain library when asking this, or more so for a more hands-on approach
 
Trying to teach Cool Cloud and/or any interested readers. I may self-nerd-snipe and end up writing an implementation myself
@ParitoshSingh I suspect you can do it without libraries for unit_a = x*unit_b + y style formulae. More complicated ones may benefit from beefier math modules than what Python provides.
 
2:26 PM
not really
 
Yeah, in that case im going to refrain from name dropping any of them for this exercise then
 
In particular, view spoiler
 
oh yeah, spoiler tags. but yep, thats exactly what i was thinking of
 
in the most general case that won't help you
and in many not-so-general cases either
 
ooh. do you have an example in mind?
 
2:29 PM
most abstract view of the problem: view spoiler
 
My newly proposed temperature unit, Kevins (abbrv Kv), uses the formula Kv = K * (23 if P ≠ NP else 42). Solve that, beefy math libraries
 
@ParitoshSingh no, but view spoiler
 
@Kevin umm... instead of {repr(a)} you can use {a!r}...
 
Ah! I really should memorize the format option syntax one of these days.
Anything more complicated than "pad with this many characters" just sieves right out of my long term memory
 
I have to check now and again... I still (surprisingly to me) see a lot of f'something={some_date.strftime("%Y%m%d")}' instead of just f'something={some_date:%Y%m%d}')
 
2:43 PM
i didnt even know that was a thing
 
Thinking about it more, I guess if you only wish to convert between units with the same dimensionality*, then unit_a = x*unit_b + y is always sufficient. It only becomes more complicated if you expand your definition of "convert" to allow, for example, conversion from miles per hour to hours per mile; or from "velocity observed while riding a very fast accelerating space ship" to "velocity observed by a bystander on earth"
 
@ParitoshSingh that objects can specify custom formatters?
 
(*not sure if this is the right word. To define what I mean by example: square feet and square inches don't have the same units, but they have the same dimensionality)
 
@JonClements Well, that datetime objects could be formatted to strings that way...but with that sentence you've made me question reality once again
so how does format work then? i guess there's a format dunder?
 
Very cool, TIL
I suppose if we wanted to go overkill, we could define our temperature class from earlier with these format specifiers
 
you wouldn't really want to as the format specifiers have to return a string... which isn't useful in this case
 
not to solve the specific problem for the OP, more so just like a "nice to have" thing for a temperature class
To be honest i didn't even see what the original problem was, just the conversation that followed
 
Oops, just noticed my code uses 459.67 in one place and 495.67 in another. All the more reason to be lazy an only write one formula!
 
3:08 PM
Which of these do you guys like better:
def func_1():
    [a,b],[c,d] = f() #f returns a 2x2 tuple, e.g. ((1,2),(3,4))
    return ((a * x + b) - d) / c

def func_2():
    return (((L:=(M:=f())[0])[0] * x + L[1]) - (R:=M[1])[1]) / R[0]
 
The 2nd one instills the urge to go clubbing in my inner canadian
 
But it's so concise :^)
>>> cvt=lambda x,f,t:(((c:={"C":(1,273.15),"F":(5/9,459.67*5/9),"K":(1,0)})[f][0]*x+c[f][1])-c[t][1])/c[t][0];t=42;print("\n".join(f"cvt({t},{a!r},{b!r})=={cvt(t,a,b):7.2f}"for a in"KFC"for b in"KFC"))
cvt(42,'K','K')==  42.00
cvt(42,'K','F')==-384.07
cvt(42,'K','C')==-231.15
cvt(42,'F','K')== 278.71
cvt(42,'F','F')==  42.00
cvt(42,'F','C')==   5.56
cvt(42,'C','K')== 315.15
cvt(42,'C','F')== 107.60
cvt(42,'C','C')==  42.00
Ok, now it's Pythonic
 
In the sense that it's very long, like a snake? Yes :P
 
3:23 PM
goes to show what lengths Americans are willing to go to avoid the metric system
 
:-)
I have no real loyalty to the imperial system. I just use whatever is immediately on hand. not my fault that all the bathroom scales default to pounds and not kg.
No, I will not spend 30 seconds changing the scale to metric mode. You have already seen how much work I put into not doing things
 
I'd think that ovens are more of an issue
and microwaves displaying the power setting in square bald eagle pulls per fluid feet
 
Hold that thought, I need to pop down to the shops to get a 3.785411784-litre of milk
 
 
1 hour later…
4:56 PM
Lord Kelvin enters from stage right and says "hold my beer: how about a temperature system where you can't go below zero, and 'twice as warm' has actual objective meaning"
 
I don't think absolute zero was known at the time that the Celsius scale was created? At least Fahrenheit had water available at the time the... unusual... scale was crated
Ah, nope, Kelvin approached the thermodynamics like a century later
 
Reading en.wikipedia.org/wiki/Fahrenheit#History, I can see why Farenheit used a water/salt/ammonia mixture instead of water for his scale. Apparently it "forms a eutectic system which stabilizes its temperature automatically [at 0F]". Presumably it's harder to keep regular ice at exactly 0C if you only have 1700s tech available.
That said, it does sound like he picked the zero point first and then devised a solution that would stabilize at that temperature. So there's still an element of arbitrariness there.
 
A mixture of ice and water is pretty damn close. IIRC it's like 0.15C in it
 
The video above pokes fun at him for using 32 and 96 as important set points instead of nice round numbers, but 96 minus 32 is a nice round number in base 2, and this was a driving motivation. Arguably less arbitrary than striving for roundness in base two times five.
 
Computing is in a relative infancy. Perhaps the Fahrenheit scale is due a resurgence once this is known
 
5:08 PM
None of this is to say "therefore, let us continue using F forever". Just... Let's not strawman his design process, that's all
We can continue to strawman feet and miles and pounds and stuff though
@roganjosh Hmm, true. en.wikipedia.org/wiki/… suggests that some initial theorizing was done starting in 1702, but I guess the foundation just wasn't there for meaningful discoveries until the field of thermodynamics got going
There had to have been at least some back room chatting at the academy like "isn't it weird that all our units of physical measurement only go down to zero, except for temperature specifically? Maybe we can do something about that"
 
5:31 PM
@Kevin that
"Coldest reproducible thing in my shed"
Now, about the horse...
Water+ice in equilibrium should also be 0 celsius (depending on pressure)
 
That's where my 0.15C comes in. I don't think it quite is, due to sublimation effects (but I'm dredging my mind from years ago in a different life)
The word is also evading me on when a reversible process follows a different route going forwards and backwards
It's a lagged difference. The word is on the tip of my fingers :/
Hysteresis!
I misremembered the discrepancy by an order of magnitude, but the triple point of water doesn't quite line up with the Kelvin scale... but they could be damn close
Wait, that's a nonsensical statement. They line up perfectly. But I don't think they would by experimental observation hundreds of years ago
 
6:15 PM
I'm a big fan of experiments that you can reproduce in your shed. If you could prove the Earth is round from your shed, we'd have one less conspiracy theory.
I wonder how much accuracy you could get out of a foucalt pendulum made from a bowling ball and eight feet of twine...
 
6:28 PM
I'm pretty sure that Foucault pendula would also rotate on a flat Earth, albeit differently.
and the kind of people mistrusting Big Round Earth would also believe that Big Foucault is in cahoots with Big Round Earth
@user14073111 since you asked 3 questions on main in the last 24 hours let me give you a heads-up regarding our rules: we ask that you don't ask for help here with fresh questions on the main site. If this is something different then go ahead.
 
yeah, sorry, thats why i deleted it
 
Ah, I see. No worries, and thanks :)
 
Yeah, I think if you math it out, then the precession of a very good Foucault pendulum will tell you the angle between yourself and the world's axis of rotation. On flat earth, it tells you that theta equals zero no matter where your shed is. On round earth, it only says zero on sheds at the north or south pole
 
yup
 
Oh, they actually tried it in a shed at the south pole. rotation period is... about 24 hours? Why even have a shed if it doesn't give you exact values
 
6:55 PM
I bet the committee was more interested in the albedo of the shed than the precision!
 
Fools!
 
@roganjosh Doesn't a thoroughly mixed ice/water combination would be at exactly 0ºC, but clearly you've looked deeper than me.
 
7:09 PM
@holdenweb It should be, in theory, but 7 years of chemical engineering education tells me that it's not quite so simple. As to why... well, those details are hazy. But you'll get a discrepancy
I think it is in sublimation and hysteresis so things get a little "off" but it's pretty negligible
Hysteresis is more fun in adsorption, rather than liquid --> solid and solid --> liquid equilibrium
 
7:41 PM
stackoverflow.com/questions/51918941/… both of the software mentioned in the answer are not maintained anymore. Does this create a vacuum or is this normal? Any insights? It looks like this is a crucial tool
 
@aeyalcinoglu the second answer mentions apache spark, and I know pyspark is a thing. Is that not relevant?
 
8:07 PM
@AndrasDeak I guess it's relevant, but I can't assess the ecosystem. Then why did faust exist?
 
cbg
 
 
2 hours later…
10:38 PM
@Kevin What is unit_a = x*unit_b + y? ? Is it something general?
 
Yes, it's a general linear mapping
 
Hmmm don't know. I don't think they have taught me this in school
 
11:45 PM
@CoolCloud if someone tells you "I have these two scales. 0 on the one scale corresponds to 32 on the other scale, and 100 on the one scale corresponds to 212 on the other scale". Then you can derive such a general linear relationship that transforms values from one scale onto the other scale.
 
@AndrasDeak Oh I see it now, thanks :D
 
The terminology using "linear" is a bit loose. Technically things we call linear relationships or linear functions are usually not linear.
 

« first day (3857 days earlier)      last day (1074 days later) »