Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{
"metadata": {
"language": "Julia",
"name": "load module from string"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": "module Foo\n mod = \"ARE.Clients.Aspen\"\n eval(Expr(:using, :ARE, :Clients, symbol(\"Aspen\")))\n\n export vp\n\n function vp(d)\n validate_parameters(d)\n end\nend\n\nusing Foo\nparams = Dict{String, Any}()\nparams[\"Discretization\"] = 0.01\nparams[\"Return_Period\"] = 0.001\nvp(params)",
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 1,
"text": "(true,\"OK.\")"
},
{
"output_type": "stream",
"stream": "stderr",
"text": "Warning: could not import Base.foldl into NumericExtensions\nWarning: could not import Base.foldr into NumericExtensions\nWarning: could not import Base.sum! into NumericExtensions\nWarning: could not import Base.maximum! into NumericExtensions\nWarning: could not import Base.minimum! into NumericExtensions\n"
}
],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": "module Bar\n export load_strategy\n function load_strategy(strategy::String)\n eval(Expr(:using, :ARE, :Clients, symbol(strategy)))\n return eval(symbol(strategy))\n end\nend",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": "using Bar",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": "Strategy = load_strategy(\"Aspen\")",
"language": "python",
"metadata": {},
"outputs": [
{
"ename": "LoadError",
"evalue": "_eval not defined\nat In[3]:1",
"output_type": "pyerr",
"traceback": [
"_eval not defined\nat In[3]:1",
" in load_strategy at In[1]:4"
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": "params = Dict{String, Any}()\nparams[\"Discretization\"] = 0.01\nparams[\"Return_Period\"] = 0.001\n\nStrategy.validate_parameters(params)",
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 6,
"text": "(true,\"OK.\")"
}
],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": "",
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment