Using Pickle.dump() to Save a PKL file to an Object - class

I am trying to save a pkl file to an object M of the class obstacle_struct() using pickle.dump(). The line of code in question is:
pickle.dump(M,open('RRT_Models.pkl','wb'))
I am getting the following error:
"pickle.dump(M,open('RRT_Models.pkl', 'wb'))
_pickle.PicklingError: Can't pickle <class 'main.obstacle_struct'>: attribute lookup obstacle_struct on main failed"
Any input is highly appreciated.

Related

Netcdf error when calling http in scala

I am trying to get http://dd.weather.gc.ca/ensemble/naefs/grib2/raw/12/018/CMC_naefs-geps-raw_RH_TGL_2m_latlon0p5x0p5_2018070712_P018_allmbrs.grib2 file with NetCDF:
def read(path: String): NetcdfDataset = {
NetcdfDataset.openDataset(path)
}
but I get
java.nio.file.InvalidPathException: Illegal char <:> at index 4:
http://dd.weather.gc.ca/ensemble/naefs/grib2/raw/12/018/CMC_naefs-geps-raw_RH_TGL_2m_latlon0p5x0p5_2018070712_P018_allmbrs.grib2
I have "edu.ucar" % "netcdfAll" % "4.6.3". What should I do to get this file? I already tried to load grib2 file from disk with this method and it goes OK.
It looks like the function NetcdfDataset.openDataset doesn't accept URLs, but only local paths. I suggest you download the .grib2 file to your computer and then pass the path to the downloaded file to the openDataset function,
e.g.
NetcdfDataset.openDataset("/home/kuba/Downloads/CMC_naefs-geps-raw_RH_TGL_2m_latlon0p5x0p5_2018070712_P018_allmbrs.grib2")

python: Imported class does not change, when edited, saved and reimported

I'm new to Python and trying to understand classes. Not sure the following error is coming from the use of my IDE, which is Spyder, or if it is intended behaviour.
I define a class message in the file C:\mydir\class_def.py. Here is what the file contains:
class message:
def __init__(self,msg1,msg2):
self.msg1 = msg1
self.msg2 = msg2
I have another script were I want to execute code, called execute.py. In this script I import the class and make an instance of the class object. Here is the code from the script execute.py:
import os
os.chdir('C:\mydir')
from class_def import message
message_obj = message('Hello','world')
So far no problems!
Then I edit class_def.py to the following:
class message:
def __init__(self,msg1):
self.msg1 = msg1
and edit execute.py to match the new class, so removing one input tomessage:
import os
os.chdir('C:\mydir')
from class_def import message
message_obj = message('Hello')
and I get the following error:
TypeError: __init__() takes exactly 3 arguments (2 given)
It seems like Python keeps the old version of class_def.py and does not import the new one, even though it is saved.
Is this normal behaviour or is Spyder doing something funny?
If you have a .pyc file such as class_def.pyc, delete it.
I'd remove all .pyc files in your working directory and then try again. If that doesn't work, maybe you're not using the module you think you are? To be certain try something like:
import myModule
print myModule.__file__ #This will give you the path to the .pyc file your program loaded
#or
import myModule
import os
print os.path.dirname(myModule.__file__)
try those out so you can be certain that you're actually using the file you're modifying. Hope that helps!

Meteor error in trying to use collections

I am currently pulling data from collections in the MongoDB but there are 2 in particular that will not work either giving me the following error:
Exception from sub Assets id i574gxNDc9RdHERNn TypeError: Cannot call method 'find' of undefined
Or:
TypeError: Cannot call method 'attachSchema' of undefined
Or:
Object # has no method 'attachSchema'
depending on how I configure it. Does anyone have an idea of what I am doing wrong. I am using the same code for the ones that work as well as the ones that are throwing errors.
The collection looks like this:
Assets = Collections.Assets = Meteor.Assets;
Querying in server/publish.js:
Meteor.publish("Assets", function (){
return Meteor.Assets.find({});
});
Changing it to:
new Mongo.Collection('Assets');
Gives error:
Exception from sub Assets id ZgzZyNYPmMr5gtFGn TypeError: Cannot call method 'find' of undefined
Running the following from the command line in the top (root) directory of the project might fix this (it helped me):
meteor add aldeed:collection2

drools - Unable to Analyse Expression

I have defined some rules in DRL file, and its my first program of creating a drl file. I am getting the error "unable to analyse expression".Here is my code:
package rules
import com.sample.Applicant.appli;
rule "Is of valid age"
when
$a : appli ( age < 18 ) // appli is my class name
// age is a variable in that class
then
$a.setValid( false ); // setValid is a method of appli
end
and getting the error:
Unable to Analyse Expression age < 18:
[Error: unable to resolve method using strict-mode: com.sample.Applicant$appli.age()]
[Near : {... age < 18 ....}]
^
[Line: 16, Column: 4] : [Rule name='Is of valid age']
Make sure in the class appli, age is either public or has a public getAge() method.
Even I was getting similar error 'Unable to Analyse Expression....' while validating a DRL file in Drools Workbench 6.4.0 Final. I checked Data Object, its fields, access specifier of the setters and getters. All seemed OK. Then I saved my data object and came back to DRL file and did validating. Suddenly the above error was gone and I saw message 'Successfully Validated'. My mistake was though I had created the Data Object in Drools Workbench, I had forgotten to save it by clicking 'Save' button.
So I would suggest you, if you are 100% sure that your Data Object and DRL files are correct, save these first and then validate DRL file again.

Getting the following error in my console while trying to import products using CSV

Fatal error: Call to a member function getName() on a non-object in /home/magentosite/public_html/store/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php on line 390
I am using Magento core import functionality in Magento 1.7.0.2
How can I solve this?
You have to load the product first
$mageProduct = Mage::getModel('catalog/product')->loadByAttribute('sku',$SKU);
Thanks