How to use a self argument in a function define outside the class. AttributeError: 'function' object has no attribute 'data'

Hi everyone, I have a class “MolecularDataset” which has a argument at line 35 to line 39 as shown in the first pic. I want to access this “” argument in a function “data_noniid” defined outside the class as in the second pic but I have tried both “” and “” but I get an error "AttributeError: ‘function’ object has no attribute ‘data’ ". How can I use the argument in the “data_noniid”.

Based on the pictures, the attribute will be created inside the generate method, so you would need to call it first:

dataset = MolecularDataset()

Also, note that line34 has a condition to create, which is then used in line37+ without a guard, so it could easily fail.

PS: you can post code snippets by wrapping them into three backticks ```, which would make debugging easier and would allow the search to index your post.

Ok I got what you meant by the args. You meant “filename, add_h, filters, size, validation, test"

Yes, exactly. I’ve used args as a placeholder for the actual input arguments for generate.