I have the following scenario in python3
from phase_2d import phase_2d #where phase_2d is a python file phase_2d.py
I then edit this file and want to test the changes, without having to quit python and reload everything.
imp.reload(phase_2d)
returns the error 'Type:Error: reload() argument must be module'
Since you imported the phase_2d class from the module phase_2d, when you call imp.reload(phase_2d), the phase_2d being passed to the reload command is the class, not the module. In order to use the reload command, you must import the actual module, or otherwise get a reference to the module. For example, you could do something like this:
import phase_2d
from phase_2d import phase_2d as p2d
...
imp.reload(phase_2d)
Or, if you really only want to import the single class from the module, you could use the inspect module to get the parent module from the class (http://docs.python.org/2/library/inspect.html#inspect.getmodule)
import inspect
from phase_2d import phase_2d
....
imp.reload(inspect.getmodule(phase_2d))
Related
I wanna import a dotile, which is on the project's root, and parse it within my middleware
something like:
import browserListDefinitions from './.browserslistrc';
but I get the TS error: TS2307: Cannot find module './.browserslistrc' or its corresponding type declarations.
I've defined the following within global.d.ts:
declare module '.browserslistrc' {}
but nothing changes. Should I install a raw loader and set it properly?
I am trying to import my JSON files into the same directory but once I import the first one, the latter one overrides the former one:
The first import:
After the second one:
As you can see above, the first file was placed inside the latter one. How can I import multiple JSON files in the same directory level?
Assuming that you import the data using the console, any data in the JSON file replaces the existing location where you run the import. There is no way to change this behavior.
What you can do is import the data to a different location in the console. So if you open the recipes node to import the first JSON, and open the searches node for the second JSON, the two imports won't overwrite each other.
If you want to import them into the root of the database, you'll have to merge the two JSON files yourself and then import them in one go.
I have a fresh MeteorJS project and I have only installed chessboardjs and chessjs as follows
meteor npm install --save chessboardjs
meteor npm install --save chess.js
In my client main.js I have also imported the above packages as follows;
import Chessboardjs from 'chessboardjs';
import Chessjs from 'chessjs';
According to chessboardjs documentation, the way to display a board is as follows;
For html
<div id="board1" style="width: 400px"></div>
and for JS
var board1 = Chessboard('board1', 'start')
My question is how do I get to display this in MeteorJS and how do I get the two chess npm packages to work together?
Any working examples will be highly appreciated.
Maybe I should also mention that the whole purpose is to have a two player game.
There are three issues here.
Imports typo
importing css
Rendering
First your imports and the function you call need to be the same. You imports are
import Chessboardjs from 'chessboardjs';
import Chessjs from 'chessjs';
but they should be
import Chessboard from 'chessboardjs';
import Chessjs from 'chess.js';
Second, the npm package import usually not automatically imports the css as well. You need to actively locate it's path within the node_modules/chessboardjs folder and import it:
import 'chessboardjs/www/css/chessboard.css'
Finally, the Chessboard function can't inject code into the DOM, if the target element (the div with id board1) has not been rendered, yet.
To fix this you need to call it within onRendered:
Template.myTemplate.onRendered(function () {
var board1 = Chessboard('board1', 'start')
})
It won't work in onCreated, because the onCreated callback is called before the first time the Template has been rendered.
See http://blazejs.org/api/templates.html#Template-onRendered
I installed bootstrap-colorpicker npm package and I'm trying to import to my meteor app.
I did read "Using npm packages" and I tried to use their example: "import moment from 'moment';". but the problem is the there is a hyphen/dash in the middle of the name and it throws an error.
where should I look in the package to know how to import a npm package?
here is what i did:
import bootstrap-colorpicker from 'bootstrap-colorpicker';
Template.Test.onRendered(function() {
$('#m-color-picker').colorpicker();
});
I want the #m-color-picker to turn into a color picker, but it gives me error for the hyphen/dash.
You can use any name you like for the module in your code, eg
import bootstrapColorpicker from 'bootstrap-colorpicker';
or
import colorpicker from 'bootstrap-colorpicker';
Easy as that
For the second part of your question:
Usually the 'getting started' part of the README file should tell you how to import a module, although some older packages only mention how to require a package, which I presume is where you are coming from.
Quite often the default export will be what you need, so for example, referring to the momentjs web site:
var moment = require('moment');
You can usually assume this:
import moment from 'moment';
Basically this is taking the top level object from the module.
Your specific package doesn't seem to export anything, but just has some side-effects (perhaps it monkey-patches itself into jQuery?), so you can even drop the first part of the import and just say:
import 'bootstrap-colorpicker';
I'm restructuring my Meteor/Blaze app to keep related items in 'modules'. But I'm experiencing an issue with the first template.
My file structure is this:
/imports
/modules
index.js
/admin
index.js
methods.js
/client
adminPage.html
adminPage.js
The index.js files are loading fine. The adminPage.js is being imported alongside adminPage.html. But when I created Template.adminPage.onCreated(...) I got an error message, that I cannot call a function on undefined.
Calling console.log(Template) in the adminPage.js file returns this:
Section showing the admin page in console.log output.
But if I run console.log(Template.adminPage) I get undefined. I'm not sure what to look for next.
I found the issue. Instead of the correct:
import { Template } from 'meteor/templating';
I used
import Template from 'meteor/templating';
You are probably missing an import statement in /imports/modules/admin/client/adminPage.js. At the top of this file add the following:
import './adminPage.html';