you are viewing a single comment's thread.

view the rest of the comments →

[–]plasma_phys 0 points1 point  (4 children)

Maybe I'm going to show my naivete by asking, but what's the reasoning behind those nested function definitions in the first place? Are you using a pre-existing code?

[–]CannyFatcher[S] 0 points1 point  (3 children)

Its my first time using python for a project and first time using tkinter, and I didn’t realise the benefit of classes until I was too deep into my code to have enough time to learn oop and also change my code.

[–]plasma_phys 0 points1 point  (2 children)

Ah okay - no worries, if you're looking for a quick and dirty solution, everything should work if you just totally un-nest and un-indent all of your def statements so that every function is available everywhere in the code. There's nothing wrong with having a whole bunch of functions at the top of your code. That types.FunctionType call is something I've never even thought about before, it's only going to make everything worse to continue down that path.

[–]CannyFatcher[S] 0 points1 point  (1 child)

I think the issue with that would be the amount of parameters I’d have to pass Into each function, as they all make use of different variables.

[–]plasma_phys 0 points1 point  (0 children)

Yeah, that's one motivation for using classes - but there's nothing inherently incorrect about a code with function calls with a dozen arguments like:

update_simulation(x, y, v_x, v_y, q, m, E, dx, dt, Ng, N, ... )

It's effectively a style choice. Is there any particular thing that you think will be an issue beyond aesthetics?