mainpyFormex - Support: sr #108742, numpy call in plugins. which way?

 
 

sr #108742: numpy call in plugins. which way?

Submitter:  francesco <francio>
Submitted:  Fri 06 Feb 2015 08:39:18 AM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  4 - Important Privacy:  Public
Assigned to:  None Open/Closed:  Open
Operating System:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 06 Feb 2015 09:40:38 AM UTC, comment #2: 

The prefered way to import numpy in a pyFormex module is to use
  import numpy
or
  import numpy as np

If you use a lot of numpy definitions, I prefer the latter because it saves some typing and makes code more readable. I think we could make this version into a standard for pyFormex modules. It is also a version that is used a lot in manuals and tutorials found on the net.

However, pyFormex provides a modeling language to the user, and how an individual uses this in his scripts and applications is completely up to him.

Now for convenience (esp. to beginning users), the full set of defines from numpy is part the pyFormex modeling language. The
pyFormex language consists of everything defined in script.py (plus everything in gui.draw for the gui version).
Therefore we have a chain of import * collecting all these:
in script.py: from formex import *
in formex.py: from coords import *
in coords.py: from arraytools import *
in arraytools.py: from numpy import *

So this is the chain that makes everyhing from numpy available in user scripts. And because these modules use a lot of the defines they import, we may just leave these as they are.

But in all other cases we should try to avoid importing everything. Especially because most modules define classes
and their functionality is available by just having the class
name or an instance.

Certainly in new code: do not use import *

Benedict Verhegghe <bverheg>
Group administrator
Fri 06 Feb 2015 08:39:18 AM UTC, comment #1: 

This item has been reassigned from the project pyFormex bugs tracker to your tracker.

The original report is still available at bugs #44194

Following are the information included in the original report:

[field #0]                  Item ID: 44194
[field #1]                 Group ID: 10866
[field #2]              Open/Closed: Open
[field #3]                 Severity: 4 - Important
[field #4]                  Privacy: Public
[field #9]                 Category: Plugins
[field #10]             Submitted by: francio
[field #11]              Assigned to: bverheg
[field #12]             Submitted on: Fri 06 Feb 2015 06:53:56 AM CET
[field #13]                  Summary: numpy call in plugins. which way?
[field #14]      Original Submission: I noticed this problem with the new upfates of fe_tools

Numpy is not called explicitely so it is not recognized.
How numpy should be called in the plugins?


from numpy import *

#or

import numpy as np


Some plugins dont call it at all as it is inherited from other libraries, some use the first call, some the second.

1 Shall we define a general rule and force the call always in the same way?

2 Must this be done also for plugins (e.g trisurface) that get numpy from some other library.

[field #16]               Item Group: None
[field #17]                   Status: None
[field #18]        Component Version: None
[field #19]         Operating System: None
[field #20]          Reproducibility: None
[field #21]               Size (loc): None
[field #22]            Fixed Release: None
[field #23]          Planned Release: None
[field #24]                   Effort: 0.00
[field #28]                 Priority: 5 - Normal
[field #31]         Percent Complete: 0%
[field #33]                  Release: None
[field #58]     Custom Select Box #1: None
[field #59]     Custom Select Box #2: None
[field #60]     Custom Select Box #3: None
[field #61]     Custom Select Box #4: None
[field #62]     Custom Select Box #5: None
[field #63]     Custom Select Box #6: None
[field #64]     Custom Select Box #7: None
[field #65]     Custom Select Box #8: None
[field #66]     Custom Select Box #9: None
[field #67]    Custom Select Box #10: None

Benedict Verhegghe <bverheg>
Group administrator
Fri 06 Feb 2015 08:39:18 AM UTC, original submission:  

I noticed this problem with the new upfates of fe_tools

Numpy is not called explicitely so it is not recognized.
How numpy should be called in the plugins?


from numpy import *

#or

import numpy as np


Some plugins dont call it at all as it is inherited from other libraries, some use the first call, some the second.

1 Shall we define a general rule and force the call always in the same way?

2 Must this be done also for plugins (e.g trisurface) that get numpy from some other library.

francesco <francio>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bverheg (Posted a comment)
  • -email is unavailable- added by francio (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-02-06 bverheg Reassign itempyFormex, bug #44194 pyFormex, sr #108742

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code