EnesYildirim / netcdf4-python

Automatically exported from code.google.com/p/netcdf4-python
Other
0 stars 0 forks source link

Feature request: make Variable._name attribute public #165

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I don't have a bug to report but I have a feature request. I don't know if this 
is the correct place for it but I couldn't find anything else. Please tell me 
if I should post this somewhere else.

I am implementing a function that returns the data path of a ncdf Variable 
(e.g.) '/group1/group2/var1'. However, if I have a Variable called var1, the 
only way for me to access its name is via the private attribute var1._name. 
Could you add a public attribute called 'name' to the Variable class please? 

By the way, thanks for this great library.

Original issue reported on code.google.com by titus...@gmail.com on 22 Feb 2013 at 2:30

GoogleCodeExporter commented 8 years ago
Another request (I didn't want to make a new issue) since it's very much 
related. I also am implementing a function that returns the data path of a 
dimension (so '/group1/group2/dim1'. Just as with the Variable, the Dimension 
class only has a private '_name' attribute, can you make this public as well? 

Also, the Dimension class is missing a 'group' attribute that returns a 
reference to its group (the Variable class does have this group-attribute). I 
think would be useful to add this to the Dimension class as well. Please let me 
know what you think. 

Original comment by titus...@gmail.com on 22 Feb 2013 at 2:57

GoogleCodeExporter commented 8 years ago
There is already a 'path' attribute for Group and Dataset instances, were you 
aware of that?

I can't add an attribute 'name' to the Variable class, since it would conflict 
with the netCDF CF attribute of the same name.  (Same thing for the Dimension 
class).  In this case the underscore was mainly to avoid that name clash, not 
to make in private (in the sense that clients should not access it).

I would suggest just appending grp.path and var._name. 

Regarding a group attribute for the Dimension class, I went ahead and added a 
"_grp" attribute in svn (just like Variable._grp).  Is that what you had in 
mind? 

Original comment by whitaker.jeffrey@gmail.com on 22 Feb 2013 at 4:38

GoogleCodeExporter commented 8 years ago
Thank you for your quick response.

> There is already a 'path' attribute for Group and Dataset instances, were you 
aware of that?

Yes I was, and currently my code does indeed append grp.path and var._name. Now 
that you confirmed that I can use this, I will continue to do so. However, 
other people still may think it is a private member since the Python convention 
says that attributes starting with an underscore are private (see PEP8, 
http://www.python.org/dev/peps/pep-0008/#designing-for-inheritance). I urge you 
to remove leading underscore from all variables that you consider public. If 
you want to avoid name clashes you can append an underscore at the end.

Except for programmers, tools such as pylint also consider these attributes  
private. It may also the reason why the Variable._name attribute isn't present 
in the documentation which, I presume, is auto-generated.

> Regarding a group attribute for the Dimension class, I went ahead and added a 
"_grp" attribute in svn (just like Variable._grp).  Is that what you had in 
mind? 

I couldn't get it too work but I am probably doing something wrong (it's been a 
long day). I didn't find a Variable._grp nor a Dimension._grp attribute, only a 
Variable.group() method that returns a Group object. If you could add a similar 
group() method to the Dimension class, I would be very grateful.

Original comment by titus...@gmail.com on 22 Feb 2013 at 6:32

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Just added a Dimension.group() method (svn revision 1230).  Closing....

Original comment by whitaker.jeffrey@gmail.com on 7 Mar 2013 at 11:35