python: from modules import abc.py does not work - module

I have recently switched from python 2.7 to python 3.2
considering following folder structure:
~/my_program
~/my_program/modules
where *my_program* is the root of the application, containing main script called main.py
*my_program/modules* is used to store all additional classes and subscripts
in python2.x I was able to import any file "module" the same way I do import standard modules
from modules import abc.py
however, while I try to launch the same program in python3.2 I get the error message saying:
File "/my_program/modules/__init__.py" line 1
import abc, def
ImportError: No module named abc
Please advise

It's a good example you are using, because "abc" is in fact a module in the standard library. So in fact, if you in Python 3 do import abc that will work just fine, but you will get the standard library module.
In Python 2, if you had a local module called abc.py, that import abc would import the local module instead. That means you couldn't import the module from the standard library.
In Python 3, this has been changed, and you now need to use the fully qualified name, in your case probably from modules import abc.

Where are you storing the module you created? When I create a module, I do the following:
Create a folder in the lib\sitepackages folder in your python folder ex: myModules
Save a blank python file named init.py in this folder. The file does not have to contain any syntax. Later on, you can set module requirements in this file if you wish.
Save your module into this folder ex: myGamesModule.py
In idle (or whichever python connected IDE you use) type:
from myModules import myGamesModule or from myModules import myGamesModule as myGmMod
That should import your module and then you can call the classes etc ex myGmMod.Player()
I am sure that this is correct, as I have just done it and it was ok.
I have found that sometimes, if I create a blank text file in the module folder and rename it to init.py, it has caused me problems before. I usually just open IDLE and save a init.py file from there into my module folder and then use whichever IDE I use (sublime) to create and save the rest of the files.
Also, for some reason, the text box has disallowed the underscores I am using in this text so where you see init.py, it should be (underscoreunderscore*init*underscoreunderscore.py without any asterix

Related

How do you import a reference to a dart file when you only know the file name? Extension methods and others

To import a file in Dart (using IntelliJ) I will usually use start typing the name of a function, class or variable and select enter. Alternatively I might type the name of the class and press alt+enter on it. This will then give me an option to import the file reference.
For extension methods this doesn't work and sometimes I know the name of the package (file) I want to import but can't remember the name of the function.
Is there a way to use the filename to lookup and insert an import statement with the full package address?
Edit
Unfortunately my originally accepted answer doesn't always work. For example with extension methods. I'm trying to add a reference and it seems impossible to do without typing the full reference to the extension.
Edit2
Found out there is an open issue to fix this
https://github.com/dart-lang/sdk/issues/40365
You can write import 'som...' and ctrl+space for auto-complete and get IntelliJ to make suggestion across all packages imported with pubspec and files across the project. If the file is inside a package, it will automatically insert the full path.

Rollup - Preserve modules + css

Can't find any resources online, but i'm trying to optimize our in-house component library, which i'm trying to make more tree shaker friendly.
How with rollup can i leave .css files in the output along with maintain their import in the file.
I.E
Foo.js (inside import "./foo.css")
Foo.css
Output.
Foo.js (inside import "./foo.css" remains) created into module
Foo.css
This seems as straight forward as possible and iv'e found similar threads asking for this but zero responses. https://github.com/egoist/rollup-plugin-postcss/issues/204
Allowing this will basically mean when people who consume my project will only get critical css automatically.
I.E Import { Foo } from "xyz/foo" will automatically import the accompanying css file.
Unfortunately I couldn't find a solution with Rollup for what you're looking for. However, if you're open to using Webpack there's a plugin that would make this possible called MiniCssExtractPlugin. It creates CSS files per JS file and would achieve the structure you're wanting.

The location of .config for geotiler on Windows

I'm working in jupyter notebook on Windows with matplotlib basemaps and I want to use geotiler with the basemaps. I'm writing a program and as part of it, it will generate a map and plot data points on it. However, the maps that my code generates often are over a small part of the world and have no defining features. My solution was to import the geotiler library and display it over the map with an alpha so the maps generated would be identifiable. However, when I use the geotiler.Map() function, I get a message saying that the configuration file does not exist.
The code and the error message
How do I locate the .config folder on Windows, if it exists, and where should I create it if it doesn't? I already tried my user folder but that didn't seem to work. Thanks in advance.
Figured it out.
The read_config() method in the source code tries to get the HOME environment variable, which for Windows is blank, and appends the path for the config to that. Importing os and manually setting the HOME variable to wherever you placed your .config folder seems to do the trick. You can do this with os.environ['HOME'] = 'C:\Users\YourName'.

intellij cannot resolve symbol "File"

I have this in my script
import groovy.io.FileType
.....
derp = new File("blah")
The script works but inetillij complains it cant resolve "File" and it suggested I import a totally different wrong library for it (com.jidesoft.icons.IconSet)
I already tried invalidating cache and restarting
How do I get intelllij to import groovy.io.FileType? I cant even find a way to suppress error either it doesnt give me that option
groovy.io.FileType is an enum class. It appears your variable derp would be of type File, not FileType.
You can statically import enums from the FileType class (for example):
import static groovy.io.FileType.*
In my Intellij on Java 8 the File class comes from the java.io package in a .groovy file.

Parse error on input 'exposing' for Elm

I'm just starting to learn Elm today, and I'm just trying to run a simple 'hello, world!' tutorial which I found online. I'm using a Mac with OS10.12 and I'm sure I've updated Node correctly but I keep getting the following error:
module Main exposing (..)
import Html exposing (text)
main =
text "Hello, World!"
parse error on input ‘exposing’
|
1 | module Main exposing (..)
| ^^^^^^^^
[Finished in 0.3s with exit code 1]
I'm using Sublime text editor and I'm pretty sure I read all the install and setup instructions properly, the problem I'm having is that if I don't include that top line 'module Main exposing (..)' then the build command automatically includes that line and then throws this parsing error. How do I fix this, and why does the builder automatically add a line it doesn't like?
If you don't add a module declaration, Elm will use this one instead:
module Main exposing (..)
Elm expects this module to be in a file called Main.elm. Are you sure that your file is named Main.elm. Make sure you capitalize the name of the file: Main.elm not main.elm.
You can call it however you want...
module Hello exposing (..)
... but then this declaration should be in a file Hello.elm
It could help us, if you could post the contents of your elm-package.json file and the folder structure of the directory you started working in.
If you just want to get started, it might be a good idea to write your first Elm program in the online editor
It takes away a bit of the hassle of setting up a development environment if all you want to do is get to know Elm and decide if you like it.
There is another online editor for Elm. This instance already has the program you were trying to compile inside: https://ellie-app.com/3LBvgqYfGa1/0