Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems subclassing netCDF3.Dataset #38

Closed
dopplershift opened this issue Feb 26, 2014 · 3 comments
Closed

Problems subclassing netCDF3.Dataset #38

dopplershift opened this issue Feb 26, 2014 · 3 comments

Comments

@dopplershift
Copy link
Member

From merckelb...@yahoo.com on February 18, 2010 11:15:16

Hi,

I'm trying to generate a subclass of netCDF3.Dataset, basically by doing

import netCDF3

class Mynetcdf(netCDF3.Dataset):
def init(self,somelist):
netCDF3.Dataset.ini(self,'tmp.nc','w')
self.somelist=somelist

alist=['a','b','c']

mncdf=Mynetcdf(alist)

Now, mncdf.somelist is in fact a string!

I'm using python 2.6 on ubuntu 9.04 and version netCDF 0.9

Any idea what goes wrong here?

Thanks a lot!

Lucas Merckelbach

Original issue: http://code.google.com/p/netcdf4-python/issues/detail?id=38

@dopplershift
Copy link
Member Author

From whitaker.jeffrey@gmail.com on February 18, 2010 10:35:03

Lucas: You are setting an netcdf dataset attribute when you do
self.somelist=somelist. The list of strings is being cast to a string, and a string
dataset attribute is added to the file.

[mac28:~/python/netcdf4-python] jwhitaker% ncdump tmp.nc
netcdf tmp {

// global attributes:
:somelist = "abc" ;
}

If you want to create a python attribute that won't be written to the netcdf file, do

self.dict['somelist']=somelist

-Jeff

@dopplershift
Copy link
Member Author

From merckelb...@yahoo.com on February 19, 2010 10:43:10

Hi Jeff,

Thanks a lot. That works!

Lucas

@dopplershift
Copy link
Member Author

From whitaker.jeffrey@gmail.com on February 25, 2014 18:04:09

Status: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant