Import module from subfolderPython imports from subfoldersImporting my own modules in Google App EngineHow to import a directory with modules to Python path that is a symlink to original source from a subfolder?Import forked module in Python instead of installed moduleCreate a python package & install it as source distribution and not a .egg?Import module errorGetting error when importing from sibling packageImporting a class from one directory to another directoryPython Relative Imports “Above Top Level”Avoid to import the path when using subfolders in pythonCalling a function of a module by using its name (a string)How to import a module given the full path?Import a module from a relative pathImporting modules from parent folderHow can I get a list of locally installed Python modules?Why is Python running my module when I import it, and how do I stop it?How to import a module in Python with importlib.import_moduleHow to import an SQL file using the command line in MySQL?import subfolder in pythonHow to import and create my class from my module?
Converting 3x7 to a 1x7. Is it possible with only existing parts?
What things do I only get a limited opportunity to take photos of?
A Tale of Snake and Coffee
What made the Ancient One do this in Endgame?
The last tree in the Universe
New Site Design!
How to remove multiple elements from Set/Map AND knowing which ones were removed?
Does the use of English words weaken diceware passphrases
Reflecting Telescope Blind Spot?
Why does MAGMA claim that the automorphism group of an elliptic curve is order 24 when it is order 12?
What is the color associated with lukewarm?
Difference between "drift" and "wander"
How to know whether to write accidentals as sharps or flats?
Should I worry about having my credit pulled multiple times while car shopping?
How to avoid offending original culture when making conculture inspired from original
Struggling to present results from long papers in short time slots
At zero velocity, is this object neither speeding up nor slowing down?
Cremated People Pottery
Digital signature that is only verifiable by one specific person
Is it a bad idea to have an pen name within only an initial for a surname?
Why is gun control associated with the socially liberal Democratic party?
Does WiFi affect the quality of images downloaded from the internet?
Does anyone recognize these rockets, and their location?
How to make a villain when your PCs are villains?
Import module from subfolder
Python imports from subfoldersImporting my own modules in Google App EngineHow to import a directory with modules to Python path that is a symlink to original source from a subfolder?Import forked module in Python instead of installed moduleCreate a python package & install it as source distribution and not a .egg?Import module errorGetting error when importing from sibling packageImporting a class from one directory to another directoryPython Relative Imports “Above Top Level”Avoid to import the path when using subfolders in pythonCalling a function of a module by using its name (a string)How to import a module given the full path?Import a module from a relative pathImporting modules from parent folderHow can I get a list of locally installed Python modules?Why is Python running my module when I import it, and how do I stop it?How to import a module in Python with importlib.import_moduleHow to import an SQL file using the command line in MySQL?import subfolder in pythonHow to import and create my class from my module?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I want to import subfolders as modules. Therefore every subfolder contains a __init__.py
. My folder structure is like this:
src
main.py
dirFoo
__init__.py
foofactory.py
dirFoo1
__init__.py
foo1.py
dirFoo2
__init__.py
foo2.py
In my main script I import
from dirFoo.foofactory import FooFactory
In this factory file I include the sub modules:
from dirFoo1.foo1 import Foo1
from dirFoo2.foo2 import Foo2
If I call my foofactory I get the error, that python can't import the submodules foo1 and foo2:
Traceback (most recent call last):
File "/Users/tmp/src/main.py", line 1, in <module>
from dirFoo.foofactory import FooFactory
File "/Users/tmp/src/dirFoo/foofactory.py", line 1, in <module>
from dirFoo1.foo1 import Foo1
ImportError: No module named dirFoo1.foo1
python import module subdirectory
add a comment |
I want to import subfolders as modules. Therefore every subfolder contains a __init__.py
. My folder structure is like this:
src
main.py
dirFoo
__init__.py
foofactory.py
dirFoo1
__init__.py
foo1.py
dirFoo2
__init__.py
foo2.py
In my main script I import
from dirFoo.foofactory import FooFactory
In this factory file I include the sub modules:
from dirFoo1.foo1 import Foo1
from dirFoo2.foo2 import Foo2
If I call my foofactory I get the error, that python can't import the submodules foo1 and foo2:
Traceback (most recent call last):
File "/Users/tmp/src/main.py", line 1, in <module>
from dirFoo.foofactory import FooFactory
File "/Users/tmp/src/dirFoo/foofactory.py", line 1, in <module>
from dirFoo1.foo1 import Foo1
ImportError: No module named dirFoo1.foo1
python import module subdirectory
add a comment |
I want to import subfolders as modules. Therefore every subfolder contains a __init__.py
. My folder structure is like this:
src
main.py
dirFoo
__init__.py
foofactory.py
dirFoo1
__init__.py
foo1.py
dirFoo2
__init__.py
foo2.py
In my main script I import
from dirFoo.foofactory import FooFactory
In this factory file I include the sub modules:
from dirFoo1.foo1 import Foo1
from dirFoo2.foo2 import Foo2
If I call my foofactory I get the error, that python can't import the submodules foo1 and foo2:
Traceback (most recent call last):
File "/Users/tmp/src/main.py", line 1, in <module>
from dirFoo.foofactory import FooFactory
File "/Users/tmp/src/dirFoo/foofactory.py", line 1, in <module>
from dirFoo1.foo1 import Foo1
ImportError: No module named dirFoo1.foo1
python import module subdirectory
I want to import subfolders as modules. Therefore every subfolder contains a __init__.py
. My folder structure is like this:
src
main.py
dirFoo
__init__.py
foofactory.py
dirFoo1
__init__.py
foo1.py
dirFoo2
__init__.py
foo2.py
In my main script I import
from dirFoo.foofactory import FooFactory
In this factory file I include the sub modules:
from dirFoo1.foo1 import Foo1
from dirFoo2.foo2 import Foo2
If I call my foofactory I get the error, that python can't import the submodules foo1 and foo2:
Traceback (most recent call last):
File "/Users/tmp/src/main.py", line 1, in <module>
from dirFoo.foofactory import FooFactory
File "/Users/tmp/src/dirFoo/foofactory.py", line 1, in <module>
from dirFoo1.foo1 import Foo1
ImportError: No module named dirFoo1.foo1
python import module subdirectory
python import module subdirectory
asked Jan 21 '12 at 14:44
RazerRazer
3,42293879
3,42293879
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
There's no need to mess with your PYTHONPATH
or sys.path
here.
To properly use absolute imports in a package you should include the "root" packagename as well, e.g.:
from dirFoo.dirFoo1.foo1 import Foo1
from dirFoo.dirFoo2.foo2 import Foo2
Or you can use relative imports:
from .dirfoo1.foo1 import Foo1
from .dirfoo1.foo1 import Foo2
41
One thing to remember! add__init__.py
to every subfolder you are importing from.
– Aziz Alto
Sep 9 '15 at 1:33
5
Empty__init__.py
may do the job.
– cerebrou
Jan 13 '17 at 8:07
What would the syntax be if previouslyFoo1
was in the parent directory and one coded something likefrom Foo1 import *
. Is there a way to achieve that same effect so you don't have to prefix everything withFoo1
?
– jxramos
Apr 12 '17 at 23:41
@AzizAlto: without your comment this solution is not very useful
– Alex
Oct 19 '18 at 14:09
add a comment |
Just to notify here. (from a newbee, keviv22)
Never and ever for the sake of your own good, name the folders or files with spaces or symbols like "-" or "_". If you did so, you may face few issues. like mine, say, though your command for importing is correct, you wont be able to successfully import the desired files which are available inside such named folders.
Invalid Folder namings as follows:
- Generic-Classes-Folder
- Generic_Classes_Folder
valid Folder namings for above:
- GenericClassesFolder or Genericclassesfolder or genericClassesFolder (or like this without any spaces or special symbols among the words)
What mistake I did:
consider the file structure.
Parent
. __init__.py
. Setup
.. __init__.py
.. Generic-Class-Folder
... __init__.py
... targetClass.py
. Check
.. __init__.py
.. testFile.py
What I wanted to do?
- from testFile.py, I wanted to import the 'targetClass.py' file inside the Generic-Class-Folder file to use the function named "functionExecute" in 'targetClass.py' file
What command I did?
- from 'testFile.py', wrote command,
from Core.Generic-Class-Folder.targetClass import functionExecute
- Got errors like
SyntaxError: invalid syntax
Tried many searches and viewed many stackoverflow questions and unable to decide what went wrong. I cross checked my files multiple times, i used __init__.py
file, inserted environment path and hugely worried what went wrong......
And after a long long long time, i figured this out while talking with a friend of mine. I am little stupid to use such naming conventions. I should never use space or special symbols to define a name for any folder or file. So, this is what I wanted to convey. Have a good day!
(sorry for the huge post over this... just letting my frustrations go.... :) Thanks!)
8
Spaces and dashes ("-") would cause this, but underscores ("_") should still work fine.
– cowlinator
Aug 23 '17 at 22:46
add a comment |
Set your PYTHONPATH environment variable. For example like this PYTHONPATH=.:.. (for *nix family).
Also you can manually add your current directory (src in your case) to pythonpath:
import os
import sys
sys.path.insert(0, os.getcwd())
add a comment |
Say your project is structured this way:
+---MyPythonProject
| +---.gitignore
| +---run.py
| | +---subscripts
| | | +---script_one.py
| | | +---script_two.py
Inside run.py
, you can import scripts one and two by:
from subscripts import script_one as One
from subscripts import script_two as Two
Now, still inside run.py
, you'll be able to call their methods with:
One.method_from_one(param)
Two.method_from_two(other_param)
add a comment |
Had problems even when init.py existed in subfolder and all that was missing was adding 'as' after import
from folder.file import Class as Class
import folder.file as functions
That point is not very relevant and just a repetition.
– crisscross
Feb 7 at 15:16
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f8953844%2fimport-module-from-subfolder%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
There's no need to mess with your PYTHONPATH
or sys.path
here.
To properly use absolute imports in a package you should include the "root" packagename as well, e.g.:
from dirFoo.dirFoo1.foo1 import Foo1
from dirFoo.dirFoo2.foo2 import Foo2
Or you can use relative imports:
from .dirfoo1.foo1 import Foo1
from .dirfoo1.foo1 import Foo2
41
One thing to remember! add__init__.py
to every subfolder you are importing from.
– Aziz Alto
Sep 9 '15 at 1:33
5
Empty__init__.py
may do the job.
– cerebrou
Jan 13 '17 at 8:07
What would the syntax be if previouslyFoo1
was in the parent directory and one coded something likefrom Foo1 import *
. Is there a way to achieve that same effect so you don't have to prefix everything withFoo1
?
– jxramos
Apr 12 '17 at 23:41
@AzizAlto: without your comment this solution is not very useful
– Alex
Oct 19 '18 at 14:09
add a comment |
There's no need to mess with your PYTHONPATH
or sys.path
here.
To properly use absolute imports in a package you should include the "root" packagename as well, e.g.:
from dirFoo.dirFoo1.foo1 import Foo1
from dirFoo.dirFoo2.foo2 import Foo2
Or you can use relative imports:
from .dirfoo1.foo1 import Foo1
from .dirfoo1.foo1 import Foo2
41
One thing to remember! add__init__.py
to every subfolder you are importing from.
– Aziz Alto
Sep 9 '15 at 1:33
5
Empty__init__.py
may do the job.
– cerebrou
Jan 13 '17 at 8:07
What would the syntax be if previouslyFoo1
was in the parent directory and one coded something likefrom Foo1 import *
. Is there a way to achieve that same effect so you don't have to prefix everything withFoo1
?
– jxramos
Apr 12 '17 at 23:41
@AzizAlto: without your comment this solution is not very useful
– Alex
Oct 19 '18 at 14:09
add a comment |
There's no need to mess with your PYTHONPATH
or sys.path
here.
To properly use absolute imports in a package you should include the "root" packagename as well, e.g.:
from dirFoo.dirFoo1.foo1 import Foo1
from dirFoo.dirFoo2.foo2 import Foo2
Or you can use relative imports:
from .dirfoo1.foo1 import Foo1
from .dirfoo1.foo1 import Foo2
There's no need to mess with your PYTHONPATH
or sys.path
here.
To properly use absolute imports in a package you should include the "root" packagename as well, e.g.:
from dirFoo.dirFoo1.foo1 import Foo1
from dirFoo.dirFoo2.foo2 import Foo2
Or you can use relative imports:
from .dirfoo1.foo1 import Foo1
from .dirfoo1.foo1 import Foo2
answered Jan 21 '12 at 16:18
Rob WoutersRob Wouters
11.9k22832
11.9k22832
41
One thing to remember! add__init__.py
to every subfolder you are importing from.
– Aziz Alto
Sep 9 '15 at 1:33
5
Empty__init__.py
may do the job.
– cerebrou
Jan 13 '17 at 8:07
What would the syntax be if previouslyFoo1
was in the parent directory and one coded something likefrom Foo1 import *
. Is there a way to achieve that same effect so you don't have to prefix everything withFoo1
?
– jxramos
Apr 12 '17 at 23:41
@AzizAlto: without your comment this solution is not very useful
– Alex
Oct 19 '18 at 14:09
add a comment |
41
One thing to remember! add__init__.py
to every subfolder you are importing from.
– Aziz Alto
Sep 9 '15 at 1:33
5
Empty__init__.py
may do the job.
– cerebrou
Jan 13 '17 at 8:07
What would the syntax be if previouslyFoo1
was in the parent directory and one coded something likefrom Foo1 import *
. Is there a way to achieve that same effect so you don't have to prefix everything withFoo1
?
– jxramos
Apr 12 '17 at 23:41
@AzizAlto: without your comment this solution is not very useful
– Alex
Oct 19 '18 at 14:09
41
41
One thing to remember! add
__init__.py
to every subfolder you are importing from.– Aziz Alto
Sep 9 '15 at 1:33
One thing to remember! add
__init__.py
to every subfolder you are importing from.– Aziz Alto
Sep 9 '15 at 1:33
5
5
Empty
__init__.py
may do the job.– cerebrou
Jan 13 '17 at 8:07
Empty
__init__.py
may do the job.– cerebrou
Jan 13 '17 at 8:07
What would the syntax be if previously
Foo1
was in the parent directory and one coded something like from Foo1 import *
. Is there a way to achieve that same effect so you don't have to prefix everything with Foo1
?– jxramos
Apr 12 '17 at 23:41
What would the syntax be if previously
Foo1
was in the parent directory and one coded something like from Foo1 import *
. Is there a way to achieve that same effect so you don't have to prefix everything with Foo1
?– jxramos
Apr 12 '17 at 23:41
@AzizAlto: without your comment this solution is not very useful
– Alex
Oct 19 '18 at 14:09
@AzizAlto: without your comment this solution is not very useful
– Alex
Oct 19 '18 at 14:09
add a comment |
Just to notify here. (from a newbee, keviv22)
Never and ever for the sake of your own good, name the folders or files with spaces or symbols like "-" or "_". If you did so, you may face few issues. like mine, say, though your command for importing is correct, you wont be able to successfully import the desired files which are available inside such named folders.
Invalid Folder namings as follows:
- Generic-Classes-Folder
- Generic_Classes_Folder
valid Folder namings for above:
- GenericClassesFolder or Genericclassesfolder or genericClassesFolder (or like this without any spaces or special symbols among the words)
What mistake I did:
consider the file structure.
Parent
. __init__.py
. Setup
.. __init__.py
.. Generic-Class-Folder
... __init__.py
... targetClass.py
. Check
.. __init__.py
.. testFile.py
What I wanted to do?
- from testFile.py, I wanted to import the 'targetClass.py' file inside the Generic-Class-Folder file to use the function named "functionExecute" in 'targetClass.py' file
What command I did?
- from 'testFile.py', wrote command,
from Core.Generic-Class-Folder.targetClass import functionExecute
- Got errors like
SyntaxError: invalid syntax
Tried many searches and viewed many stackoverflow questions and unable to decide what went wrong. I cross checked my files multiple times, i used __init__.py
file, inserted environment path and hugely worried what went wrong......
And after a long long long time, i figured this out while talking with a friend of mine. I am little stupid to use such naming conventions. I should never use space or special symbols to define a name for any folder or file. So, this is what I wanted to convey. Have a good day!
(sorry for the huge post over this... just letting my frustrations go.... :) Thanks!)
8
Spaces and dashes ("-") would cause this, but underscores ("_") should still work fine.
– cowlinator
Aug 23 '17 at 22:46
add a comment |
Just to notify here. (from a newbee, keviv22)
Never and ever for the sake of your own good, name the folders or files with spaces or symbols like "-" or "_". If you did so, you may face few issues. like mine, say, though your command for importing is correct, you wont be able to successfully import the desired files which are available inside such named folders.
Invalid Folder namings as follows:
- Generic-Classes-Folder
- Generic_Classes_Folder
valid Folder namings for above:
- GenericClassesFolder or Genericclassesfolder or genericClassesFolder (or like this without any spaces or special symbols among the words)
What mistake I did:
consider the file structure.
Parent
. __init__.py
. Setup
.. __init__.py
.. Generic-Class-Folder
... __init__.py
... targetClass.py
. Check
.. __init__.py
.. testFile.py
What I wanted to do?
- from testFile.py, I wanted to import the 'targetClass.py' file inside the Generic-Class-Folder file to use the function named "functionExecute" in 'targetClass.py' file
What command I did?
- from 'testFile.py', wrote command,
from Core.Generic-Class-Folder.targetClass import functionExecute
- Got errors like
SyntaxError: invalid syntax
Tried many searches and viewed many stackoverflow questions and unable to decide what went wrong. I cross checked my files multiple times, i used __init__.py
file, inserted environment path and hugely worried what went wrong......
And after a long long long time, i figured this out while talking with a friend of mine. I am little stupid to use such naming conventions. I should never use space or special symbols to define a name for any folder or file. So, this is what I wanted to convey. Have a good day!
(sorry for the huge post over this... just letting my frustrations go.... :) Thanks!)
8
Spaces and dashes ("-") would cause this, but underscores ("_") should still work fine.
– cowlinator
Aug 23 '17 at 22:46
add a comment |
Just to notify here. (from a newbee, keviv22)
Never and ever for the sake of your own good, name the folders or files with spaces or symbols like "-" or "_". If you did so, you may face few issues. like mine, say, though your command for importing is correct, you wont be able to successfully import the desired files which are available inside such named folders.
Invalid Folder namings as follows:
- Generic-Classes-Folder
- Generic_Classes_Folder
valid Folder namings for above:
- GenericClassesFolder or Genericclassesfolder or genericClassesFolder (or like this without any spaces or special symbols among the words)
What mistake I did:
consider the file structure.
Parent
. __init__.py
. Setup
.. __init__.py
.. Generic-Class-Folder
... __init__.py
... targetClass.py
. Check
.. __init__.py
.. testFile.py
What I wanted to do?
- from testFile.py, I wanted to import the 'targetClass.py' file inside the Generic-Class-Folder file to use the function named "functionExecute" in 'targetClass.py' file
What command I did?
- from 'testFile.py', wrote command,
from Core.Generic-Class-Folder.targetClass import functionExecute
- Got errors like
SyntaxError: invalid syntax
Tried many searches and viewed many stackoverflow questions and unable to decide what went wrong. I cross checked my files multiple times, i used __init__.py
file, inserted environment path and hugely worried what went wrong......
And after a long long long time, i figured this out while talking with a friend of mine. I am little stupid to use such naming conventions. I should never use space or special symbols to define a name for any folder or file. So, this is what I wanted to convey. Have a good day!
(sorry for the huge post over this... just letting my frustrations go.... :) Thanks!)
Just to notify here. (from a newbee, keviv22)
Never and ever for the sake of your own good, name the folders or files with spaces or symbols like "-" or "_". If you did so, you may face few issues. like mine, say, though your command for importing is correct, you wont be able to successfully import the desired files which are available inside such named folders.
Invalid Folder namings as follows:
- Generic-Classes-Folder
- Generic_Classes_Folder
valid Folder namings for above:
- GenericClassesFolder or Genericclassesfolder or genericClassesFolder (or like this without any spaces or special symbols among the words)
What mistake I did:
consider the file structure.
Parent
. __init__.py
. Setup
.. __init__.py
.. Generic-Class-Folder
... __init__.py
... targetClass.py
. Check
.. __init__.py
.. testFile.py
What I wanted to do?
- from testFile.py, I wanted to import the 'targetClass.py' file inside the Generic-Class-Folder file to use the function named "functionExecute" in 'targetClass.py' file
What command I did?
- from 'testFile.py', wrote command,
from Core.Generic-Class-Folder.targetClass import functionExecute
- Got errors like
SyntaxError: invalid syntax
Tried many searches and viewed many stackoverflow questions and unable to decide what went wrong. I cross checked my files multiple times, i used __init__.py
file, inserted environment path and hugely worried what went wrong......
And after a long long long time, i figured this out while talking with a friend of mine. I am little stupid to use such naming conventions. I should never use space or special symbols to define a name for any folder or file. So, this is what I wanted to convey. Have a good day!
(sorry for the huge post over this... just letting my frustrations go.... :) Thanks!)
edited Mar 25 at 2:29
Josnidhin
9,06573257
9,06573257
answered Jan 27 '17 at 12:04
Vivek22Vivek22
369414
369414
8
Spaces and dashes ("-") would cause this, but underscores ("_") should still work fine.
– cowlinator
Aug 23 '17 at 22:46
add a comment |
8
Spaces and dashes ("-") would cause this, but underscores ("_") should still work fine.
– cowlinator
Aug 23 '17 at 22:46
8
8
Spaces and dashes ("-") would cause this, but underscores ("_") should still work fine.
– cowlinator
Aug 23 '17 at 22:46
Spaces and dashes ("-") would cause this, but underscores ("_") should still work fine.
– cowlinator
Aug 23 '17 at 22:46
add a comment |
Set your PYTHONPATH environment variable. For example like this PYTHONPATH=.:.. (for *nix family).
Also you can manually add your current directory (src in your case) to pythonpath:
import os
import sys
sys.path.insert(0, os.getcwd())
add a comment |
Set your PYTHONPATH environment variable. For example like this PYTHONPATH=.:.. (for *nix family).
Also you can manually add your current directory (src in your case) to pythonpath:
import os
import sys
sys.path.insert(0, os.getcwd())
add a comment |
Set your PYTHONPATH environment variable. For example like this PYTHONPATH=.:.. (for *nix family).
Also you can manually add your current directory (src in your case) to pythonpath:
import os
import sys
sys.path.insert(0, os.getcwd())
Set your PYTHONPATH environment variable. For example like this PYTHONPATH=.:.. (for *nix family).
Also you can manually add your current directory (src in your case) to pythonpath:
import os
import sys
sys.path.insert(0, os.getcwd())
edited Jan 21 '12 at 16:06
Splat
743310
743310
answered Jan 21 '12 at 15:04
Max KamenkovMax Kamenkov
1,23511517
1,23511517
add a comment |
add a comment |
Say your project is structured this way:
+---MyPythonProject
| +---.gitignore
| +---run.py
| | +---subscripts
| | | +---script_one.py
| | | +---script_two.py
Inside run.py
, you can import scripts one and two by:
from subscripts import script_one as One
from subscripts import script_two as Two
Now, still inside run.py
, you'll be able to call their methods with:
One.method_from_one(param)
Two.method_from_two(other_param)
add a comment |
Say your project is structured this way:
+---MyPythonProject
| +---.gitignore
| +---run.py
| | +---subscripts
| | | +---script_one.py
| | | +---script_two.py
Inside run.py
, you can import scripts one and two by:
from subscripts import script_one as One
from subscripts import script_two as Two
Now, still inside run.py
, you'll be able to call their methods with:
One.method_from_one(param)
Two.method_from_two(other_param)
add a comment |
Say your project is structured this way:
+---MyPythonProject
| +---.gitignore
| +---run.py
| | +---subscripts
| | | +---script_one.py
| | | +---script_two.py
Inside run.py
, you can import scripts one and two by:
from subscripts import script_one as One
from subscripts import script_two as Two
Now, still inside run.py
, you'll be able to call their methods with:
One.method_from_one(param)
Two.method_from_two(other_param)
Say your project is structured this way:
+---MyPythonProject
| +---.gitignore
| +---run.py
| | +---subscripts
| | | +---script_one.py
| | | +---script_two.py
Inside run.py
, you can import scripts one and two by:
from subscripts import script_one as One
from subscripts import script_two as Two
Now, still inside run.py
, you'll be able to call their methods with:
One.method_from_one(param)
Two.method_from_two(other_param)
answered Sep 25 '18 at 20:34
Flavio WuenscheFlavio Wuensche
5,14013235
5,14013235
add a comment |
add a comment |
Had problems even when init.py existed in subfolder and all that was missing was adding 'as' after import
from folder.file import Class as Class
import folder.file as functions
That point is not very relevant and just a repetition.
– crisscross
Feb 7 at 15:16
add a comment |
Had problems even when init.py existed in subfolder and all that was missing was adding 'as' after import
from folder.file import Class as Class
import folder.file as functions
That point is not very relevant and just a repetition.
– crisscross
Feb 7 at 15:16
add a comment |
Had problems even when init.py existed in subfolder and all that was missing was adding 'as' after import
from folder.file import Class as Class
import folder.file as functions
Had problems even when init.py existed in subfolder and all that was missing was adding 'as' after import
from folder.file import Class as Class
import folder.file as functions
answered Dec 21 '18 at 3:00
Tomas TrdlaTomas Trdla
215
215
That point is not very relevant and just a repetition.
– crisscross
Feb 7 at 15:16
add a comment |
That point is not very relevant and just a repetition.
– crisscross
Feb 7 at 15:16
That point is not very relevant and just a repetition.
– crisscross
Feb 7 at 15:16
That point is not very relevant and just a repetition.
– crisscross
Feb 7 at 15:16
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f8953844%2fimport-module-from-subfolder%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown