« first day (3232 days earlier)      last day (1713 days later) » 
01:00 - 16:0016:00 - 22:00

1:57 AM
Does anyone have experience with the Google Drive API?
I'm trying to make sense of the documentation. The main documentation is here. I'm trying to fetch a file list. I'm having trouble figuring out what the http request url should look like.
 
2:56 AM
cabbage
 
3:29 AM
Can anyone tell me what is happening in this program? First time I saw this type of return statement and why there is a * before names[:3]?
def likes(names):
    n = len(names)
    return {
        0: 'no one likes this',
        1: '{} likes this',
        2: '{} and {} like this',
        3: '{}, {} and {} like this',
        4: '{}, {} and {others} others like this'
    }[min(4, n)].format(*names[:3], others=n-2)
Here is the problem statement - codewars.com/kata/who-likes-it/python
 
3:45 AM
* unpacks the object such as a list and [:3] says give me the first 3 items.
INPUT:
names = ["Max", "John", "Mark", 'Alex']
[*names][:3]

OUTPUT:
['Max', 'John', 'Mark']
 
Ok, thanks :) does it gives a list?
It seems like, format(*names[:3],others = n-2) is same as calling format("Max","John","Mark",others = n-2)
 
 
1 hour later…
user10984358
5:18 AM
Heya, hope y’all doing good. I’ve been asked to create wrappers around some file and directory operation tasks. Using shutil and Path from pathlib to do this. But my “boss” asks me to do so without exception handling. Meaning I have to manually check if’s for Path.exists() and Path.is_file() or is_dir(). Is there a strong reason I should do so or do you guys suggest the same??
 
cbg
 
user10984358
Backstory: he’s been working on python for like a year. So he says
 
user10984358
I’m using wayyyy to many if’s and I feel like try except could dramatically reduce this
 
5:34 AM
cbg Guys o/
 
@TheNamesAlc Try to see if you can have oops there instead.
 
I wonder how many Python users think that Python was named after snakes... 🤔
 
raises hand in fear
 
5:38 AM
@TheLittleNaruto haha you're kidding me right
 
@U10-Forward I am afraid I am not. :P
 
@TheLittleNaruto Ever heard of Monty Python?
 
@JennaSloan Nope! Is it another language ?
 
@TheLittleNaruto No, it's a British comedy group.
 
@JennaSloan Oh!
Talks about comedy, I like George Carlin and Fluffy Guy.
 
6:01 AM
cbg
 
\o , Arne
 
 
1 hour later…
7:11 AM
recbg
 
7:46 AM
Hi ... is it possible to pass a tkinter button as a function argument ?
for example this passes the text 'B1' to the function toggle_button:
B1 = Button(topframe, text ='Button 1', fg ='red', command = lambda B='B1': toggle_button(B))
but I want to bass actually the button not the text 'b1'
 
8:02 AM
cbg
 
@louigi600 it should probably work if you remove B='B1 from the lambda and put B1 in the global namespace or use some other way that toggle_button can access the button object
Perhaps you don't even need a global, I'm away from laptop
 
8:42 AM
Button ? We can make desktop application using Python ?
 
 sorry I'm a total newbi with python.
 this works but is not what I want:

    #!/usr/bin/python
    from tkinter import *
    from tkinter import messagebox

    text="was pressed"

    def toggle_button(B):
       messagebox.showinfo( B, text)
    #   print topframe.get()
       if B1.cget("fg") == "red":
          B1.config(fg ='green')
       elif B1.cget("fg") == "green":
          B1.config(fg ='red')


    top = Tk()
    topframe= Frame(top)
    topframe.pack()
    B1 = Button(topframe, text ='Button 1', fg ='red', command = lambda B='B1': toggle_button(B))
 
@louigi600 Can you make a gist instead ?
 
maybe I could but I don't know what it is ...
can you give me an example ?
 
Click on gist and copy your code there. And then click on "Create public gist" button. And share the generated link from address bar.
 
8:59 AM
@TheLittleNaruto you mean to use gist to share the code and make it more readable then in the chat window ?
 
Indeed. Gist or any other code paste service works
 
Hello
 
I am wondering about how to store the data in the computer for just one year interval and erase the other data in the computer from the previous year? Is there any hint to store the data for just one year?
???
 
@ParitoshSingh I'm trying to reset my github account password because I've forgotten it
 
9:03 AM
@senshinakamora maybe, but it will probably have little to do with python. this is the python room.
 
any hind?
hint
 
cbg
 
Here it is :
https://gist.github.com/louigi600/eb1d08b7f105aba59d614851d5999050#file-passing-button-as-function-argument-in-tk
 
@louigi600 fyi, if you call the file some_name.py gist will add python syntax highlighting.
 
9:12 AM
@Arne done
 
much better =)
(I can't help though, I know nothing about tk)
 
thanks
 
well I'll just sit here waiting for someone to help ....
I googled but could not find how to pass a tk button as function argument.
 
@louigi600 Well the function should accept a tk button instance as an argument, right ?
 
yes
I do not want to write a toggle function specific for each button ... just one toggle button function that takes the appropriate button as argument
 
9:26 AM
Looks like Frame can accept instance of TK button; You're getting any error ?
 
bash-5.0# ./tk_test3.py
Traceback (most recent call last):
File "./tk_test3.py", line 19, in <module>
B1 = Button(topframe, text ='Button 1', fg ='red', command = lambda B=B1: toggle_button(B))
NameError: name 'B1' is not defined
bash-5.0#
that's with the second code snippet in my gist
when I start trying to use B as a button and not as a variable containing text
 
 
1 hour later…
10:51 AM
@louigi600 Perhaps you might get an idea from functools.partial. This lets you "bake function arguments in," which you could use to parameterise button handlers that took no arguments. Would that work for you?
The "traditional" method would be to define a button (sub)class and have each button be an instance of that class, so each instance's on_click method would be set as the event handler for that instance.
Either way it's a matter of binding a specific argument to the handler method.
 
11:21 AM
@holdenweb unfortunately I'm totally inexperienced in python and in general in object oriented programming languages.
could you please turn that into a code snippet easier for me to understand ?
 
class MyButton(Button):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('command', self.default_command)
        super().__init__(*args, **kwargs)

    def default_command(self):
        toggle_button(self)
 
@Aran-Fey and how is that going to fit in while using tkinter buttons ?
 
11:36 AM
@TheLittleNaruto create private gist
 
11:59 AM
@louigi600 Not sure I understand the question. You do B1 = MyButton(topframe, text='Button 1', fg='red')?
 
@Aran-Fey i put the sipet on gist: gist.github.com/louigi600/…
I want to do something like this: B1 = Button(topframe, text ='Button 1', fg ='red', command = lambda B=B1: toggle_button(B))
 
And what's wrong with the code I wrote?
 
@AndrasDeak ^^
 
I don't know how to use that while still using tk button
to me that looks like I'me defining something that will probabbly conflict with tkinter's definition of Button
 
Try copy/pasting it and you might be surprised
 
12:14 PM
#!/usr/bin/python
from tkinter import *
from tkinter import messagebox

class MyButton(Button):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('command', self.default_command)
        super().__init__(*args, **kwargs)

def default_command(self):
        toggle_button(self)

text="was pressed"

def toggle_button(B):
   messagebox.showinfo( B, text)
#   print topframe.get()
   if B1.cget("fg") == "red":
      B1.config(fg ='green')
   elif B1.cget("fg") == "green":
      B1.config(fg ='red')
bash-5.0# ./tk_test3.py
Traceback (most recent call last):
  File "./tk_test3.py", line 27, in <module>
    B1 = Button(topframe, text ='Button 1', fg ='red', command = lambda B=B1: toggle_button(B))
NameError: name 'B1' is not defined
bash-5.0#
 
*sigh*
 
I can confirm that it is possible to inherit from Tkinter classes without causing a "conflict". I do it constantly whenever the existing interface comes up short. For example, when I need to get the text out of an Entry.
 
B1 = MyButton(topframe, text='Button 1', fg='red')
 
Apparently the designers didn't think it was a high priority to be able to directly read the contents of a text box
 
not sure if the toggle button function should actually be below
toggle_button(self)
 
12:18 PM
If you use the bind method instead of the command parameter, then the function you register will be called with an argument e that you can extract the widget object from.
That way you won't have to futz around with lambdas in order to make B1 visible to toggle_button
 
My lunch break is over, so I wish y'all good luck
 
@louigi600 I think I can summaries the above by saying if you take the time to understand Python's class inheritance you will end up with a much better idea of how to organise your program.
 
import tkinter
def toggle_button(e):
    button = e.widget
    print("Button with id", id(button), "was pressed")

root = tkinter.Tk()
B1 = tkinter.Button(root, text="Button 1")
B1.bind("<1>", toggle_button)
B1.pack()
root.mainloop()
 
cbg
 
A GUI is a pretty ambitious task for a first Python project, so don't get discouraged if it takes a while to get where you want to go.
@Andy cbg
 
12:23 PM
Of course, none of this is necessary at all if B1 is defined at the global scope, since then you can refer directly to it anywhere* without having to pass it as a parameter or access it via the event object or whatever
 
@Kevin and how is this going to work:
if B.cget("fg") == "red":
      B.config(fg ='green')
   elif B.cget("fg") == "green":
      B.config(fg ='red')
 
import tkinter
def toggle_button(e):
    B = e.widget
    print("Button with id", id(B), "was pressed")
    if B.cget("fg") == "red":
        B.config(fg ='green')
    elif B.cget("fg") == "green":
        B.config(fg ='red')

root = tkinter.Tk()
B1 = tkinter.Button(root, text="Button 1", fg="red")
B1.bind("<1>", toggle_button)
B1.pack()
root.mainloop()
 
morning cbg all
 
Hi everyone
Quick question. I can't seem to get a hang of sys.stdout and redirecting certain strings in my tkinter GUI to it
 
And the question is?
Hi there, by the way!
 
12:33 PM
The typical way of sending data to stdout is by using the print function. It's a pretty useful function, I recommend it
 
An explanation of "redirecting" is likely to be enlightening. To what are the messages currently being directed, and by what?
If you use Python3 then as @kevin says, the output goes to sys.stdout by default. We therefore conclude the problem may be a little more complex than "how do I print to standard out?"
 
@Kevin this worked:
#!/usr/bin/python
from tkinter import *
from tkinter import messagebox

text="was pressed"

def toggle_button(e):
   B = e.widget
   messagebox.showinfo( B.cget("text"), text)
   if B.cget("fg") == "red":
      B.config(fg ='green')
   elif B.cget("fg") == "green":
      B.config(fg ='red')


top = Tk()
topframe= Frame(top)
topframe.pack()
#B1 = Button(topframe, text ='Button 1', fg ='red', command = lambda B='B1': toggle_button(B))
#B2 = Button(topframe, text ='Button 2', fg ='red', command = lambda B='B2': toggle_button(B))
thankyou
can you explain what this is actually doing ?
B1.bind("<1>",toggle_button)
is it binding to stdout of the button or something like that ?
 
"When a left mouse click occurs on button B1, call the toggle_button function with the event as an argument"
The event has the button as its widget attribute.
 
As holdenweb says, "<1>" is indeed shorthand for "on a left mouse click". Consult effbot.org/tkinterbook/tkinter-events-and-bindings.htm for a listing of other event names.
 
so it's binding left mouse button <1> click to a function ?
I could so the same with center or right buttons ?
 
12:39 PM
Yes, you can also bind center and right buttons. Those are <2> and <3>, IIRC
 
@Kevin supposing that script is running can I force it to toggle a button from some other piece of code ?
ie some event happens (triggered by eudev) can I write some code that would force the python script already running to toggle_button
 
In principle, yes, but interprocess communication is not my area of expertise so I don't know precisely how one would do that
I especially don't know how you'd do it from eudev because I don't know what eudev is
 
I can get eudev (systemd stripped udev) to run a script upon the event I'm intrested in
 
There's one approach to interprocess communication that I see a lot of new users employ. Suppose process A wants to send a message to process B. You make process A write its message to a file. Process B periodically reads that same file to see if anything new has been added.
This isn't the best solution in the world, since simultaneous writes/reads to a file can cause race conditions and permission errors, and it scales badly.
But if you don't mind the occasional dropped message and lag in the ballpark of 100 ms, then maybe that's fine
 
12:57 PM
Ok I've maybe a simpler question:
#!/usr/bin/python
from tkinter import *
from tkinter import messagebox
import time

text="was pressed"

def toggle_button(e):
   B = e.widget
   Istatus = B.cget("fg")
#   messagebox.showinfo( B.cget("text"), text)
   B.config(fg ='yellow');
   time.sleep(5)
   if Istatus == "red":
      B.config(fg ='green')
   elif Istatus == "green":
      B.config(fg ='red')


top = Tk()
topframe= Frame(top)
topframe.pack()
B1 = Button(topframe, text ='Button 1', fg ='red')
that does not work ... the pressed button never show's yellow
it just goes black for the whole time the toggle_button function is running
and then goes green as an endresult
or red if it was green before
 
tkinter does not play well with time.sleep. Any function that does not return instantaneously will cause your interface to completely lock up until it does return.
The conventional way to make something happen X seconds in the future is to use Tk.after
def toggle_button(e):
   B = e.widget
   Istatus = B.cget("fg")
   B.config(fg ='yellow');
   future_color = "green" if Istatus == "red" else "red"
   top.after(5000, lambda: B.config(fg=future_color))
 
this will not play well in what I want to do ...
it would be better if I could have the button pressed color (while the toggle function is running) to be yellow. Can I do that ?
 
1:14 PM
I interpret your question as "but I really really need to sleep in this function. Can I at least make the button turn yellow before the interface becomes completely unresponsive for five seconds?". Possibly. The method update_idletasks causes widget style changes to get flushed out sooner than they usually would. This might make your button turn yellow right before the five second freeze.
def toggle_button(e):
   B = e.widget
   Istatus = B.cget("fg")
   B.config(fg ='yellow');
   top.update_idletasks()
   time.sleep(5)
   if Istatus == "red":
      B.config(fg ='green')
   elif Istatus == "green":
      B.config(fg ='red')
This works on my machine. I'm less confident about how it behaves in environments that aren't identical to mine. In particular, I don't know what it does on non-Windows boxes.
One way to make sleep play perfectly nicely with tkinter is to use threading. The main thread handles all UI-related tasks, and never sleeps. The child thread never handles UI-related tasks, and may sleep whenever it pleases. You use a queue to send messages from the child thread to the main thread.
This is kind of a pain in the butt to set up and you probably won't find a ready-made recipe for it online, so you should make sure you really really need sleep before you commit to this approach
 
m8_
Hey all, I have a dataframe with names, ages, grades and new grades. I want to groupby names and grades and then check to see if each new grade is in each group as new a column, True or False. What would be the best approach?
import pandas as pd

data = [['Alex',10,'A','A'],['Amanda',12,'A','B'],['Aaron',13,'A','B'],
`['Bob',10,'B','A'],['Bill',12,'B','A'],['Brett',13,'B','C'],
['Cory',10,'C','A'],['Cathy',12,'C','B'],['Clark',13,'C','A']]

df = pd.DataFrame(data,columns=['Name','Age','Grade','New Grade'])

grades = df.groupby(['Name','Grade'])
correction...had to adjust the names:
data = [['Alex',10,'A','A'],['Amanda',12,'A','B'],['Aaron',13,'A','B'],
['Alex',10,'B','A'],['Amanda',12,'B','A'],['Aaron',13,'B','C'],
['Alex',10,'C','A'],['Amanda',12,'C','B'],['Aaron',13,'C','A']]
 
Hmm, not sure what you mean by "see if each new grade is in each group as new a column"
 
Sorry guys for the delay in response.
It was just a bit confusing the stdout vs print.
As regards 'redirecting', I want certain print command outputs to always go to a scrolltext box rather than the default console output (if that makes sense)
 
Ah, so you want to redirect stdout to your application, and not the other way around.
 
@Kevin I don't need to sleep in the function ... the sleep would be replaced by the code that actually handle the appropriate action (start/stop a wifi interface or something like that)
but while it is being handled I want the button to be yellow
@Kevin so for me having it yellow instead of black as the the mouse button is pressed
I'm doing this on a raspberryPi3 running slackwareARM ... so it may behave slightly differently ...
 
1:29 PM
Yeah, I suspected that your sleep call was actually a stand-in for some long-running process. My advice still applies. Tkinter doesn't care why the function takes five seconds to return, it's going to throw a tantrum in any case
 
m8_
So if Alex has grades A, B and C and new grades A, A, A (as in my example) because the new grade A is in the existing group of grades, it should return True.
 
@Kevin correct
 
m8_
Although now I am seeing that because they way I grouped, it is creating separate groups for each grade. So I would guess I need this: grades = df.groupby('Name')['Grade']
 
@EJay What version of Python are you using? Redirecting stdout is slightly easier if you're on 3.4 or higher
 
3.7
 
1:37 PM
@EJay here's one possible approach: pastebin.com/4k66knmu. Basically, you create a file-like class TextIO, whose write method updates a text widget. Then you use redirect_stdout to redirect stdout to that file-like object.
 
this worked (activeforeground):
#!/usr/bin/python
from tkinter import *
from tkinter import messagebox
import time

text="was pressed"

def toggle_button(e):
   B = e.widget
   Istatus = B.cget("fg")
#   messagebox.showinfo( B.cget("text"), text)
   time.sleep(5)
   if B.cget("fg") == "red":
      B.config(fg ='green')
   elif B.cget("fg") == "green":
      B.config(fg ='red')


top = Tk()
topframe= Frame(top)
topframe.pack()
B1 = Button(topframe, text ='Button 1', fg ='red', activeforeground='yellow')
 
@EJay are these "certain print command outputs" determined by content or by code location? print can write to arbitrary streams using its file keyword, as in print('DANGER, WILL ROBINSON!', file=sys.stderr)
 
@kevin
@Kevin Thanks. Will try it out.
The plan was to create function that accepts certain variables in the program and prints to the scrolltext box (kind of synonymous to logging in a file).
However, the whole sys.stdout vs print was confusing to me
 
I have a feeling that redirecting stdout may be overkill here. If you only need a single function to send output to the Text, then there's no need to create a file-like object or anything. Just delete all your print() calls in that function and replace them with text.insert(tkinter.END, "message goes here")
 
@Kevin, yes that can work also. Thanks
 
1:47 PM
Redirecting stdout is a technique usually reserved for when you have no ability to edit the function that's doing the printing. Maybe it's in a third-party library, maybe it's in the part of the code under the comment #students: do not edit this part of the code, or you will receive a zero for the assignment
 
@Kevin LOL
 
m8_
I think I need to do something with groups.keys()
Getting close
 
@Kevin, update! All good and running as desired
Thank you!!
 
I'm solving a problem to move all zeros to the end. (0.0is treated as 0). But, the given list also contains False, so if I use a[j] == 0, False will be treated as 0 also, to resolve that issue I have used a[j] is 0. But now it does not treat 0.0 as 0.
Here is the code -
def move_zeros(a):
    if not a or len(a) == 1:
        return a
    i, j = 0, 0
    l = len(a)
    while j < l:
        if a[j] is 0:
            j += 1
            continue
        a[i] = a[j]
        i += 1
        j += 1
    if i == 0:
        return a
    while i < l:
        a[i] = 0
        i += 1
    return a
This fails for the input: [9,0.0,0,9,1,2]
The actual output need to be [9,9,1,2,0,0]
 
I propose if a[j] == 0 and a[j] is not False
 
2:06 PM
But, a[j] is 0 is same as a[j] is not False
As, when I use is we are checking the location in memory
Correct me if I'm wrong
 
I disagree. 0.0 is 0 evaluates to False, and 0.0 is not False evaluates to True.
0.0 and 0 have different locations in memory.
def move_zeroes(a):
    is_numeric_zero = lambda x: x == 0 and x is not False
    nonzeroes = [item for item in a if not is_numeric_zero(item)]
    a[:] = nonzeroes + [0]*(len(a)-len(nonzeroes))
    return a

print(move_zeroes([9,0.0,0,9,1,2]))
#result:
#[9, 9, 1, 2, 0, 0]
 
Ok, get it.. thanks :)
 
morning snakes
 
cbg
 
good morning
 
2:21 PM
'morning cabbage
 
\o what's new and exciting today
I'm still hateorading on Gitlab on my end. I'm hoping to get the latest version soon to make use of the enhancements to the pipeline configurations. It's going to improve so much
 
I have upended all conventional knowledge about the laws of physics, and perhaps even the basic tenets of mathematics. Or my code has a bug. Either or.
 
Your bug introduced a wormhole in to a world of backwards physics.
 
@Kevin it's probably your bug from next Monday which will be so bad it rippled back in time to break physics today
 
To warn you of impending doom.
But you're not listening. Clearly.
 
2:26 PM
@Kevin Is there any cause of using a[:] instead of a only?
 
@Quark a[:] = ... will cause the changes to be propagated to the original list. a = ... will not do the same.
In general I prefer not to mutate my function's arguments, but your original code was doing so, so I made mine do so also.
 
@Quark please read this to understand name binding and mutation in python
 
I would simply do return nonzeroes + [0]*(len(a)-len(nonzeroes)) and not bother assigning anything to a, if I had my druthers
 
cabbage
 
@Kevin So, using a = . . . will assign another variable a?
 
2:30 PM
@Quark please read what I linked and ask again if you still don't get it
 
Ok thanks
 
@Quark Try this b = move_zeroes(a); print(a, b) with and without the [:] to see what it does.
 
a = ... will cause the name a to be bound to a value that is (usually) completely unrelated to its old value. Mutating this new value won't change the old value, and vice versa.
Contrawise, a[:] = ... doesn't rebind the name a at all. It mutates the existing value of a. If any other names are bound to that same value, they will also see the mutation.
 
Ok, I will try to understand what you just said, after reading the link provided by Andras
 
Thanks, I promise it will be much easier.
 
2:37 PM
I'm not terribly fond of a[:] = ..., as it is a bit too "magical" for my tastes. For much the same reason that I dislike my_list += [whatever]
Both of them violate the basic mental model that newbies often adopt, which goes like "assignment doesn't propagate changes to other variables, and method calls do". This mental model is correct 85% of the time, with a[:] = ...and a += [...] falling into the 15% bucket
 
I'd argue that trying to align your coding around models of newbies is a suboptimal design principle
 
The thing is, nobody would expect a[0] = ... to rebind a, so nobody should expect a[:] = ... to do so either
 
Ideally newbies would skip over this mental model entirely and jump right to a perfect understanding of name binding, but I won't ask for a miracle
@AndrasDeak Yeah, typically. We have a little more incentive to avoid confusing techniques, since we hang out in the place where newbies go when they encounter a confusing technique.
Non SO-lurking devs are more insulated from the consequences of their design choices
 
That's true, but "mutate the input list into something new" can hardly be done without a[:] =, right?
well, a.clear(), a.extend(new_items) works too...
Perhaps that's actually clearer semantically. But meh.
 
I won't dispute that a[:] = ... is the most concise way to completely change the contents of a's value. I still don't like it much.
 
2:45 PM
cbg. Looks like I'm gonna have take my first class since forever later today. how exciting :P
 
Awesome @Dair, grad school?
 
Cbg. What kind of class?
 
Thought experiment: if a += b was equivalent to a = a + b, what effects would that have on the language?
 
@Dodge Yup!
 
morning cabbages, all!
 
2:46 PM
Biggest change I can think of is that list.extend would see more use
 
@AndrasDeak Ironically, I have these "deficit courses" (because I majored in math not cs) so I'm taking an intro to theoretical to CS course. I also have another course on knowledge representation and I'm working in a lab too.
 
@Aran-Fey no a[0] += [item] tuple-of-lists fun
@Dair sounds adorable :D
 
@AndrasDeak that's an improvement... I think? :P
 
The primary reason I might mutate a list is because making a complete copy of it would consume too much memory. But a[:] = whatever doesn't save me any memory compared to a = whatever, since whatever will consume the same amount of memory either way
 
@Dair Noice! I'm starting PhD next week as well, all distance through Texas A&M, however. Good luck!
 
2:48 PM
@Aran-Fey I guess it would force you to use .extend a lot more
 
@Dodge congratulations. Great uni
 
@Dodge Nice! Congratulations!
 
Thanks, I thought I was done with school (I totally was, and told everyone I was) but I applied for an NSF fellowship and actually won. So I had to eat my words and keep going.
 
@Dodge LOL. Never say never
 
Hmm, is there an easy way to determine how fast a satellite needs to travel in order to maintain a stable orbit of radius R from some body of known mass?
Or do I need, like, calculus.
 
2:53 PM
rip my simulation timed out on the cluster. Looks like I'm going to have to go back to the drawing board.
 
I remember there being such an equation
 
@Kevin yes, assuming a circular orbit
 
@Kevin Iirc, this is covered in AP Physic textbooks (well, at least an approximation)
 
gravitational force = centrifugal force
 
@EJay Absolutely!
 
2:54 PM
G*m*M/R^2 = m v^2/R
 
@Kevin This Wikipedia page seems to have what you're looking for
 
I also got a weird email saying my knowledge rep class was cancel thursday, but according to my schedule knowledge rep is only on tuesday
 
and if you don't know G and M and want to use Earth, G m M/R^2 = G m M/R_earth^2 (R_earth/R)^2 = mg (R_earth/R)^2. It's easier to memorize the radius of Earth than its mass, if you ask me.
@Dair just increase the time limit :P
or Use More Cores
 
@AndrasDeak Ok, cool. Solving for v gives me the "relative velocity" formula in inspectorG4dget's link*, so that checks out.
 
@AndrasDeak So I'm mostly using the cluster for a single computer with better GPUs than my intel idris.
 
2:58 PM
@Dair ah, too bad
Isn't there a longer queue?
 
(*give or take the definition of big M, but tiny m is very small for my purposes, so the difference is negligible)
 
@Kevin size of m should not matter as long as big M is spherically symmetric (well, and m is point-like compared to M)
 
I'm almost there ...
 
@AndrasDeak Nah, there is a hard cap of 3 days or so.
 
@Dair :/
 
3:00 PM
cbg room6
 
@piRSquared I've been doing review queues and all of my flags are simply ignored and expire so I'll never get there it seems
 
I'm simulating a teapot going around the sun, so they're sufficiently point-like and sphere-like respectively, I think
 
@Dodge what kind of flags? That shouldn't happen very often, and mostly with custom ones.
 
I'm going to discuss this with my advisors tho and come up with a game plan. Might do some MPI again, might change the simulation method... We'll see.
 
I've flagged so few things
 
3:01 PM
maybe I'll need to whip out the FORTRAN BOI!
 
@AndrasDeak Close as "Unclear what you're asking" is my go to
 
@Kevin yup. As long as M is spherical you can use Gauss' law to compute the gravitational force (-> Newton's gravitational law) at a given point outside the planet. And as long as m is point-like you can use a single value of said force.
@Dodge ah, close flags. Most flags are not like that, because at 3k rep you can't close flag anymore.
@Dair how's fortran with gpu?
@Kevin (if M is not spherical you have to integrate with respect to dM parts of the star to get the gravitational force at a given point outside the star, and if m is not point-like you have to integrate with respect to dm parts of the satellite to get the net gravitational force acting on the satellite)
 
Hi Guys what would you recommend for making a production restful web service in python? We currently use flask for prototyping and testing, but I read somewhere (on several discussions) that flask wasn't recommended for production use
 
@AndrasDeak They have CLFORTRAN so maybe that is a thing. Idk exactly tho. Don't get me wrong, I enjoy hardware optimization-esque stuff (for lack of a better term) but idk exactly what is going on. We didn't learn too much about SSE intrinsics in many of my math classes.
"in many" as in "none" but I did take an introduction to computer structures where we covered some basic SSE stuff. (but -O3 dominated any of the optimizations I ever made in that class lol)
@erotavlas The builtin in web server for flask isn't production ready, but it is easy enough to switch it out with another. I'm no expert on the matter, but there are production ready ones like GNUnicorn and NGINX etc. (Although you may want to check with other to figure out which one is best suited for your needs)
 
Hmm, the total momentum of my closed gravitational system is quadrupling over the course of 20 years, and I think this may be a problem
 
3:11 PM
@Kevin stupid conservation of energy... muddling up Kevin's experiments... grumble grumble
 
kevin'd (by proxy)
 
@Dair thanks
 
np
 
Or, scratch that, it quadruples in half a year, then descends to 90% of the original momentum in ten years, and then it rises up to 110% of the original momentum by year 20.
 
3:13 PM
is your integrator reliable enough?
 
rounding errors in circular orbits, perhaps?
 
There is something to be said for local conservation versus global conservation.
 
@AndrasDeak Almost certainly not.
 
@Kevin perhaps get a free tier license from WolframAlpha to use their integrator?
 
no way, just throw something from scipy.integrate at it
I will take this sacrifice on Kevin's behalf.
 
3:18 PM
@inspectorG4dget Begone proprietary software! :P
 
@Dair "but it's better to integrate" :P
 
My end goal is to determine the long-term behavior of two planets with nearly identical mass orbiting one star on circular orbits with nearly identical velocities and radii
 
Yeah, don't need precise integration for that at all ;)
 
Somehow I feel like the naiive equations used in the AP Physics textbooks aren't applicable to the problem at hand.
 
nothing for that sweet, sweet pun? I thought it was rather well differentiated from the rest :P
 
3:24 PM
Common wisdom is that this system is not stable, but I couldn't get a clear answer about how the system breaks down. My guesses are 1) one planet dives into the star, and the other moves to a wider orbit; 2) one planet speeds up until the star and the planets form an equilateral triangle; 3) one planet speeds up and collides with the other
 
@Kevin yesterday you mentioned that the "wobbling" of the star in this experiment might be enough to actually allow someone on one planet to determine if there was a counter-planet on the other side of their star by line-of-sight (you gave three means to determine if there was a counter-earth and the "wobbling" of the star was the third). Would this "wobbling" be significant enough to assume that your model will always end in imbalance and the collapse of the two-planet-perfect-counter-orbit?
 
@Kevin 2) sounds impossible
 
Oh, you just said as much
 
@Kevin I'm no dynamical systems expert but I think that the results you're looking for and how everything plays out are very sensitive to starting conditions.
 
I have bifurcation plots in mind...
 
3:26 PM
I should probably invest time into dynamical system given how often I end up going back to HPC lol.
 
m8_
So I figured out my question I posted a couple hours ago. But hoping some one could take a look to see if there is a better way to go about it, which I'm sure there is. pastebin.com/Th0br5k9. Appreciate any suggestions/feedback
 
@Dodge With perfectly identical masses and orbits, the star shouldn't wobble at all. In the scenario involving our actual solar system and a hypothetical Counter-Earth, our Sun wobbles because of the other planets in the solar system.
 
Ahhh, interesting
 
@AndrasDeak If 2 is impossible because the planet can't speed up on its own while conservation of momentum is upheld, then let's say that the other planet slows down to compensate.
@Dair Yes, quite possibly. But I'm curious if the outcome is sensitive in a predictable way, or in a chaotic way. Like, maybe the outcome is #1 if planet A's mass is slightly larger than planet B's, and the outcome is #2 if the masses are identical but the orbits are offset by 179.9 degrees instead of 180, and so on.
 
@Kevin No. typically M_sun >> m_planets, so the barycenter is inside the sun. So basically the two planets are tied to a rope that keeps them on a circular orbit, but then the planets also attract one another, destabilizing the triangle
 
3:34 PM
I was worried about that. I know "Earth orbits the sun, and a teapot follows Earth at L5" is a stable configuration, but I wasn't sure if it was stable if the teapot suddenly had the same mass as Earth.
 
yup, it wouldn't
well, or perhaps it would, because the middle of the "satellite" is also a stationary point of the potential...
but I still think it would destabilize
 
wim
what the canonical for this
def foo():
    exec("x = 123")
    print(x)   # NameError: name 'x' is not defined
 
if you want to do it right you probably have to find a self-consistent configuration of bodies where the overall net potential has extrema where each body is
@wim don't know, I just saw that a day or two ago here, I didn't know that's how it worked
 
Mildly surprising that its canonical is not easy to find, since "Why does this seemingly simple yet impractical code do something contrary to the intuition of you, the reader?" is usually a surefire recipe for a zillion upvotes and a spot in the HNQ sidebar
 
@wim I'd place 3 on there. a globals, dynamic vars, and a scoping canonical. Looking for them now.
 
3:43 PM
discord has the most secure 2-factor-auth I've ever seen: new login device detected -> verification email sent -> click verification link -> repeat from step 1 until discord stops sending you emails altogether -> be locked out of your account
3
 
Maybe it failed to skyrocket because you can't fit the entire code into the title
"it" being the hypothetical post answering this question, which may or may not exist
 
we've definitely had questions like that before, but I'm not sure if any of them are canonical-level quality
(I'm also not sure how to find them)
 
wim
IIRC there was a good answer from Antti
 
3:52 PM
The conversation we had in here the other day about this topic ended with me saying "Sometimes exec mutates the locals() dict and sometimes it doesn't and I don't know why" so I'd be quite keen to get a more satisfying conclusion
def f():
    exec("x=1")
    print(locals())

def g():
    exec("y=1")
    print(locals())
    return
    y = 2

f() #result: {'x': 1}
g() #result: {}
 
uuuh that's not what I expected
 
Me neither :>
 
wim
oh I didn't see that conversation
 
oh, nevermind, it was not just exec, but also mutating locals!
 
wim
oh the irony
 
3:56 PM
def f():
    locals()["x"] = 1
    print(locals())

def g():
    locals()["y"] = 2
    print(locals())
    return
    y = 2

f() #result: {'x': 1}
g() #result: {}
 
I remember in undergrad we learned this language called logic which was a declarative language (similar to Prolog). It had a syntax similar to Lisp. Iirc the motivation for the choice of Logic over prolog was Python and Scheme were already enough languages and adding a 3rd lang would be too much for an intro course. I recently saw there is a language/library called Z3 that allows for declarative programming in a bunch of languages including python. Maybe they should try that out.
 
Yeah, that's doubly wacky
 
wim
>>> def foo():
...    exec("x = 123")
...    exec("print(x)")
...
>>> foo()
123
 
@wim there was a precursor but the core discussion started here
 
wim
problem with exec ... solution, more exec!
 
3:59 PM
def h():
    exec("z=1")
    exec("print(z)")
    return
    z = 2

h()  # NameError: name 'z' is not defined
 
Another wacky question please:
 
01:00 - 16:0016:00 - 22:00

« first day (3232 days earlier)      last day (1713 days later) »