Posts

Showing posts with the label Import

Alternative To Execfile In Python 3?

Answer : The 2to3 script replaces execfile(filename, globals, locals) by exec(compile(open(filename, "rb").read(), filename, 'exec'), globals, locals) This seems to be the official recommendation. You may want to use a with block to ensure that the file is promptly closed again: with open(filename, "rb") as source_file: code = compile(source_file.read(), filename, "exec") exec(code, globals, locals) You can omit the globals and locals arguments to execute the file in the current scope, or use exec(code, {}) to use a new temporary dictionary as both the globals and locals dictionary, effectively executing the file in a new temporary scope. execfile(filename) can be replaced with exec(open(filename).read()) which works in all versions of Python Newer versions of Python will warn you that you didn't close that file, so then you can do this is you want to get rid of that warning: with open(filename) as infile: ...

Can You Use Es6 Import Alias Syntax For React Components?

Answer : Your syntax is valid. JSX is syntax sugar for React.createElement(type) so as long as type is a valid React type, it can be used in JSX "tags". If Button is null, your import is not correct. Maybe Button is a default export from component-library. Try: import {default as StyledButton} from "component-library"; The other possibility is your library is using commonjs exports i.e. module.exports = foo . In this case you can import like this: import * as componentLibrary from "component-library"; Update Since this is a popular answer, here a few more tidbits: export default Button -> import Button from './button' const Button = require('./button').default export const Button -> import { Button } from './button' const { Button } = require('./button') export { Button } ...

Could Not Find Module `Data.Map' -- It Is A Member Of The Hidden Package

Image
Answer : These general steps were helpful for me to resolve similar issues: Use Hoogle or Stackage to find the package where the module resides Note that Hoogle and Stackage are case-sensitive . Looking up Data.Map in Hoogle yields a list similar to the one below. Stackage has a slightly different style, but the basics are the same (mostly because it also uses Hoogle for lookup). The lines in green under the result headings show the name(s) of the containing (1) package(s) (in small caps) and (2) module(s) (capitalized). Open project-name.cabal in project root and add required package under build-depends: library hs-source-dirs: src build-depends: base >= 4.7 && < 5 , containers exposed-modules: Lib Issue stack build to download and build dependencies (or stack ghci if you plan to use it in the REPL) The reason you can import Data.Char and Data.List is that they are part of the package base , which is included with GHC and is always...