No, Yes ^_^ezzieyguywuf wrote: ↑Sat Sep 07, 2019 1:34 pm is that assumption a good one? Or is this particular test poorly written, and needs to import FreeCAD itself?
Discussion: using FreeCAD or App namespaces, which is prefered
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Discussion: using FreeCAD or App namespaces, which is prefered
-
- Posts: 437
- Joined: Wed Sep 15, 2010 9:38 am
Re: Discussion: using FreeCAD or App namespaces, which is prefered
There are even another alternatives: and .
These are just other places to find the modules, as a proof:
There is also but this one is not equivalent to "FreeCAD":
I wanted to used in all macros of the official macro repository but some people (I think people on Windows) complained that there was no freecad module (small letters). What is currently used in the official macros is . Uses of "FreeCAD" and "App" are then replaced with "app". Once one of the variants settles down, this should be a matter of changing one line in each macro.
Gaël
Code: Select all
from freecad import app
Code: Select all
from freecad import gui
These are just other places to find the modules, as a proof:
Code: Select all
>>> app is App
True
>>> gui is FreeCADGui
True
Code: Select all
import freecad
Code: Select all
>>> import freecad
>>> freecad is FreeCAD
False
Code: Select all
from freecad import app
Code: Select all
import FreeCAD as app
Gaël
Re: Discussion: using FreeCAD or App namespaces, which is prefered
In my opinion it makes sense to wait for Qt 6 and to first see what they understand under the term "introducing more Pythonic API". After i guess we can discuss if FreeCAD should have more Pythonic API, closer to Qt one, i guess Python bindings. After i guess we can discuss if new import module style needs to or should adapt more. As currently we likely wouldn't be able to decide if FreeCAD/freecad/App/app ... should be used. In addition if other libraries would do the same, for example it would not be numpy but it would be app. That likely wouldn't end up all that good. For now therefore use:
That is the most consistent solution, and it aligns well with C++ counterpart. Don't assume, in your code, somebody else already did the imports.
P.S. As for the new import style modules, and the current situation, best if @looo describes what makes the most sense.
Code: Select all
import FreeCAD as App
import FreeCADGui as Gui
P.S. As for the new import style modules, and the current situation, best if @looo describes what makes the most sense.
Re: Discussion: using FreeCAD or App namespaces, which is prefered
I guess it's quite simple. We never fully moved towards new-style modules and we support both methods. If we would move fully towards new-style modules this will have a similar impact as the change from python2 to python3. Means that we most likely fully break backwards compatibility. Thats why I suggest to use new-style where possible and use the old way if there is no other option.
Regarding the topic, I did some experiments with "from freecad import app" and actually I don't have issues with this. But I don't see a big issue with using something like this:
Code: Select all
import FreeCAD as app