python : various type of getting variables from other file
can some give me right code to get variables from other file
getting variables or function from other python file
getting v in A.py to B.py
1. /var/www/Project/sub/A.py
/var/www/Project/sub/B.py
B.y
from A import v
2. /var/www/Project/sub/stuff/A.py
/var/www/Project/sub/B.py
B.y
from stuff.A import v
3. /var/www/Project/sub/stuff/A.py
/var/www/Project/sub/stuff/B.py
B.y
import os, sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)))
from stuff.B import v
/var/www/Project/sub/A.py
/var/www/Project/sub/stuff/B.py
B.y
import os, sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(file), os.pardir)))
from B import v
is this how system goes? is this code right?
python import path rules
add a comment |
can some give me right code to get variables from other file
getting variables or function from other python file
getting v in A.py to B.py
1. /var/www/Project/sub/A.py
/var/www/Project/sub/B.py
B.y
from A import v
2. /var/www/Project/sub/stuff/A.py
/var/www/Project/sub/B.py
B.y
from stuff.A import v
3. /var/www/Project/sub/stuff/A.py
/var/www/Project/sub/stuff/B.py
B.y
import os, sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)))
from stuff.B import v
/var/www/Project/sub/A.py
/var/www/Project/sub/stuff/B.py
B.y
import os, sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(file), os.pardir)))
from B import v
is this how system goes? is this code right?
python import path rules
If this question is about the problem from the previous question asked by you earlier today then the problem is circular import. Please learn about possible solutions from already answered questions - stackoverflow.com/search?q=python%20circular%20import.
– Poolka
Nov 21 '18 at 16:13
@Poolka thanks for your solution(circular import), was just wondering about clean way to access other python file in several situation. im aware of your answer about previous question i asked today:) thanks!
– 임지웅
Nov 21 '18 at 16:24
OK. Wish you luck with the research.
– Poolka
Nov 21 '18 at 16:27
Possible duplicate of How to import other Python files?
– Joooeey
Nov 21 '18 at 19:30
add a comment |
can some give me right code to get variables from other file
getting variables or function from other python file
getting v in A.py to B.py
1. /var/www/Project/sub/A.py
/var/www/Project/sub/B.py
B.y
from A import v
2. /var/www/Project/sub/stuff/A.py
/var/www/Project/sub/B.py
B.y
from stuff.A import v
3. /var/www/Project/sub/stuff/A.py
/var/www/Project/sub/stuff/B.py
B.y
import os, sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)))
from stuff.B import v
/var/www/Project/sub/A.py
/var/www/Project/sub/stuff/B.py
B.y
import os, sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(file), os.pardir)))
from B import v
is this how system goes? is this code right?
python import path rules
can some give me right code to get variables from other file
getting variables or function from other python file
getting v in A.py to B.py
1. /var/www/Project/sub/A.py
/var/www/Project/sub/B.py
B.y
from A import v
2. /var/www/Project/sub/stuff/A.py
/var/www/Project/sub/B.py
B.y
from stuff.A import v
3. /var/www/Project/sub/stuff/A.py
/var/www/Project/sub/stuff/B.py
B.y
import os, sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)))
from stuff.B import v
/var/www/Project/sub/A.py
/var/www/Project/sub/stuff/B.py
B.y
import os, sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(file), os.pardir)))
from B import v
is this how system goes? is this code right?
python import path rules
python import path rules
edited Nov 21 '18 at 16:02
임지웅
asked Nov 21 '18 at 15:52


임지웅임지웅
315
315
If this question is about the problem from the previous question asked by you earlier today then the problem is circular import. Please learn about possible solutions from already answered questions - stackoverflow.com/search?q=python%20circular%20import.
– Poolka
Nov 21 '18 at 16:13
@Poolka thanks for your solution(circular import), was just wondering about clean way to access other python file in several situation. im aware of your answer about previous question i asked today:) thanks!
– 임지웅
Nov 21 '18 at 16:24
OK. Wish you luck with the research.
– Poolka
Nov 21 '18 at 16:27
Possible duplicate of How to import other Python files?
– Joooeey
Nov 21 '18 at 19:30
add a comment |
If this question is about the problem from the previous question asked by you earlier today then the problem is circular import. Please learn about possible solutions from already answered questions - stackoverflow.com/search?q=python%20circular%20import.
– Poolka
Nov 21 '18 at 16:13
@Poolka thanks for your solution(circular import), was just wondering about clean way to access other python file in several situation. im aware of your answer about previous question i asked today:) thanks!
– 임지웅
Nov 21 '18 at 16:24
OK. Wish you luck with the research.
– Poolka
Nov 21 '18 at 16:27
Possible duplicate of How to import other Python files?
– Joooeey
Nov 21 '18 at 19:30
If this question is about the problem from the previous question asked by you earlier today then the problem is circular import. Please learn about possible solutions from already answered questions - stackoverflow.com/search?q=python%20circular%20import.
– Poolka
Nov 21 '18 at 16:13
If this question is about the problem from the previous question asked by you earlier today then the problem is circular import. Please learn about possible solutions from already answered questions - stackoverflow.com/search?q=python%20circular%20import.
– Poolka
Nov 21 '18 at 16:13
@Poolka thanks for your solution(circular import), was just wondering about clean way to access other python file in several situation. im aware of your answer about previous question i asked today:) thanks!
– 임지웅
Nov 21 '18 at 16:24
@Poolka thanks for your solution(circular import), was just wondering about clean way to access other python file in several situation. im aware of your answer about previous question i asked today:) thanks!
– 임지웅
Nov 21 '18 at 16:24
OK. Wish you luck with the research.
– Poolka
Nov 21 '18 at 16:27
OK. Wish you luck with the research.
– Poolka
Nov 21 '18 at 16:27
Possible duplicate of How to import other Python files?
– Joooeey
Nov 21 '18 at 19:30
Possible duplicate of How to import other Python files?
– Joooeey
Nov 21 '18 at 19:30
add a comment |
1 Answer
1
active
oldest
votes
if you have two files at the same directory, you can simply import one file to the other:
test1.py:
a = 5
b = 10
test2.py:
import test1
print test1.a
print test1.b
or:
from test1 import a,b
print a
print b
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%2f53415818%2fpython-various-type-of-getting-variables-from-other-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
if you have two files at the same directory, you can simply import one file to the other:
test1.py:
a = 5
b = 10
test2.py:
import test1
print test1.a
print test1.b
or:
from test1 import a,b
print a
print b
add a comment |
if you have two files at the same directory, you can simply import one file to the other:
test1.py:
a = 5
b = 10
test2.py:
import test1
print test1.a
print test1.b
or:
from test1 import a,b
print a
print b
add a comment |
if you have two files at the same directory, you can simply import one file to the other:
test1.py:
a = 5
b = 10
test2.py:
import test1
print test1.a
print test1.b
or:
from test1 import a,b
print a
print b
if you have two files at the same directory, you can simply import one file to the other:
test1.py:
a = 5
b = 10
test2.py:
import test1
print test1.a
print test1.b
or:
from test1 import a,b
print a
print b
answered Nov 21 '18 at 16:02
nerd100nerd100
875
875
add a comment |
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%2f53415818%2fpython-various-type-of-getting-variables-from-other-file%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
If this question is about the problem from the previous question asked by you earlier today then the problem is circular import. Please learn about possible solutions from already answered questions - stackoverflow.com/search?q=python%20circular%20import.
– Poolka
Nov 21 '18 at 16:13
@Poolka thanks for your solution(circular import), was just wondering about clean way to access other python file in several situation. im aware of your answer about previous question i asked today:) thanks!
– 임지웅
Nov 21 '18 at 16:24
OK. Wish you luck with the research.
– Poolka
Nov 21 '18 at 16:27
Possible duplicate of How to import other Python files?
– Joooeey
Nov 21 '18 at 19:30