[SOLVED]Basic Python question - Related to my WB -last bug fix

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Post Reply
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

[SOLVED]Basic Python question - Related to my WB -last bug fix

Post by mariwan »

can anyone explain why this was failing?

Code: Select all

def getDirectionAxis(s=Gui.Selection.getSelectionEx()):
"s" couldn't get the selection. It was empty

I needed to take it back to how it was . i.e.

Code: Select all

def getDirectionAxis(s=None):

	s=Gui.Selection.getSelectionEx()
Thanks in advance
Last edited by mariwan on Sun Oct 24, 2021 9:56 am, edited 1 time in total.
User avatar
jonasb
Posts: 162
Joined: Tue Dec 22, 2020 7:57 pm

Re: Basic Python question - Related to my WB -last bug fix

Post by jonasb »

https://docs.python-guide.org/writing/gotchas/ wrote:Python's default arguments are evaluated once when the function is defined, not each time the function is called (like it is in say, Ruby).
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: Basic Python question - Related to my WB -last bug fix

Post by mariwan »

jonasb wrote: Sat Oct 23, 2021 8:37 pm
https://docs.python-guide.org/writing/gotchas/ wrote:Python's default arguments are evaluated once when the function is defined, not each time the function is called (like it is in say, Ruby).
Thank you very much Jonasb.
Correct, that must be the reason ... But it is not logical. I call that as a bug in python.
Anyway, I did what is required even if I didn't know that. I am new in python.
Thank you again.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Basic Python question - Related to my WB -last bug fix

Post by TheMarkster »

mariwan wrote: Sun Oct 24, 2021 9:56 am
jonasb wrote: Sat Oct 23, 2021 8:37 pm
https://docs.python-guide.org/writing/gotchas/ wrote:Python's default arguments are evaluated once when the function is defined, not each time the function is called (like it is in say, Ruby).
Thank you very much Jonasb.
Correct, that must be the reason ... But it is not logical. I call that as a bug in python.
Anyway, I did what is required even if I didn't know that. I am new in python.
Thank you again.
I would argue it's not a bug in python *if* it results in faster execution.
Post Reply