A very basic questions on importing modules created locally.
I am unable to import a locally created module. The module exists in the current working directory


Am i missing something?
I'm finding local library names must begin with a capital letter. If I keep all my local files in a folder called Code, I can import them; if it's called code, I cannot. (The names of subfolders and subfiles don't seem to suffer that restriction.)
This appears to be a Jupyter restriction, not a Python one -- from the command-line Python repl I can import whatever local .py file I want.
%%capture
%run myModule.ipynb
You will get all functions/variables defined in myModule file. This will also overwrite variables of your current notebook but
from Mymodule import person
has also that effect.
import os
#if you want to know current working dir
os.getcwd()
#if you want to change
os.chdir('G:/a-2017-master')
# if you want to list dir
os.listdir()
['.DS_Store', '.gitignore', 'cs109a_hw0.ipynb', 'hwassets', 'Labs', 'Lectures', 'Midterms', 'Module.py', 'Projects', 'README.md', 'Sections', 'pycache']
import os
import Module as m
a = 10
b = 29
print(f"Addition of {a} and {b} : ",m.add(a,b))
Here is an example from the W3schools Tutorial to create module locally:
(keras) ninjawarrior@ninjas-MBP cookiecutter % pwd
/Users/ninjawarrior/miniconda3/environments_files/pythonbasics/Python_Tutorial_w3schools/mymodules/cookiecutter
(keras) ninjawarrior@ninjas-MBP cookiecutter % ls -lrt
total 16
-rw-r--r-- 1 ninjawarrior staff 46 Oct 12 12:47 cookie.py
drwxr-xr-x 3 ninjawarrior staff 96 Oct 12 12:50 __pycache__
-rw-r--r-- 1 ninjawarrior staff 751 Oct 12 12:56 Importing_module_locally.ipynb
def greeting(name):
print("Hello, " + name)
`
import mymodule
mymodule.greeting("Jonathan")
Result : Hello, Jonathan
Hope this helps !
from foldername.myModule import Person