1import importlib.util
2import os
3
4def find_file(filename, search_path):
5 for root, dirs, files in os.walk(search_path):
6 if filename in files:
7 return os.path.join(root, filename)
8 return None
9
10file_path = find_file('info.py', os.getcwd())
11
12spec = importlib.util.spec_from_file_location("info", file_path)
13info = importlib.util.module_from_spec(spec)
14spec.loader.exec_module(info)
15X = info.POSITION + 1
cannot import name 'Х' from 'solution' (/tmp/solution.py)
File "/tmp/test_runner.py", line 75, in main
loaded_test = importlib.import_module('test', test_module)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 995, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/tmp/test.py", line 3, in <module>
from solution import Х
Георги Кунчев
21.11.2024 18:20Не. Само една версия на човек се брои.
|
Йоан Байчев
21.11.2024 18:04Да речем кача само аз един файл 73 пъти тогава POSITION = 73?
|
Георги Кунчев
21.11.2024 17:49Нито едното, ако трябва да съм честен.
Но това не е от значение.
|
Йоан Байчев
21.11.2024 17:42Добре а тези решения качени ли са вече във вашата директория или след минаване на срока тогава, предполагам второто?
|
Георги Кунчев
21.11.2024 17:33Качи пак и виж. Нямаш лимит
|
Йоан Байчев
21.11.2024 17:29Изписа ми нещо дълго и червено, но не видях какво?
|
t | 1 | import importlib.util | t | 1 | import importlib.util |
2 | import os | 2 | import os | ||
3 | 3 | ||||
4 | def find_file(filename, search_path): | 4 | def find_file(filename, search_path): | ||
5 | for root, dirs, files in os.walk(search_path): | 5 | for root, dirs, files in os.walk(search_path): | ||
6 | if filename in files: | 6 | if filename in files: | ||
7 | return os.path.join(root, filename) | 7 | return os.path.join(root, filename) | ||
8 | return None | 8 | return None | ||
9 | 9 | ||||
10 | file_path = find_file('info.py', os.getcwd()) | 10 | file_path = find_file('info.py', os.getcwd()) | ||
11 | 11 | ||||
12 | spec = importlib.util.spec_from_file_location("info", file_path) | 12 | spec = importlib.util.spec_from_file_location("info", file_path) | ||
13 | info = importlib.util.module_from_spec(spec) | 13 | info = importlib.util.module_from_spec(spec) | ||
14 | spec.loader.exec_module(info) | 14 | spec.loader.exec_module(info) | ||
15 | X = info.POSITION + 1 | 15 | X = info.POSITION + 1 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
n | 1 | from info import POSITION | n | 1 | import importlib.util |
2 | import os | ||||
2 | 3 | ||||
t | t | 4 | def find_file(filename, search_path): | ||
5 | for root, dirs, files in os.walk(search_path): | ||||
6 | if filename in files: | ||||
7 | return os.path.join(root, filename) | ||||
8 | return None | ||||
9 | |||||
10 | file_path = find_file('info.py', os.getcwd()) | ||||
11 | |||||
12 | spec = importlib.util.spec_from_file_location("info", file_path) | ||||
13 | info = importlib.util.module_from_spec(spec) | ||||
14 | spec.loader.exec_module(info) | ||||
3 | X = POSITION + 1 | 15 | X = info.POSITION + 1 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
n | 1 | import importlib.util | n | 1 | from info import POSITION |
2 | import os | ||||
3 | 2 | ||||
t | 4 | def find_file(filename, search_path): | t | ||
5 | for root, dirs, files in os.walk(search_path): | ||||
6 | if filename in files: | ||||
7 | return os.path.join(root, filename) | ||||
8 | return None | ||||
9 | |||||
10 | file_path = find_file('info.py', os.getcwd()) | ||||
11 | |||||
12 | spec = importlib.util.spec_from_file_location("info", file_path) | ||||
13 | info = importlib.util.module_from_spec(spec) | ||||
14 | spec.loader.exec_module(info) | ||||
15 | X = info.POSITION + 1 | 3 | X = POSITION + 1 | ||
16 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
t | 1 | import importlib.util | t | 1 | import importlib.util |
2 | import os | 2 | import os | ||
3 | 3 | ||||
4 | def find_file(filename, search_path): | 4 | def find_file(filename, search_path): | ||
5 | for root, dirs, files in os.walk(search_path): | 5 | for root, dirs, files in os.walk(search_path): | ||
6 | if filename in files: | 6 | if filename in files: | ||
7 | return os.path.join(root, filename) | 7 | return os.path.join(root, filename) | ||
8 | return None | 8 | return None | ||
9 | 9 | ||||
10 | file_path = find_file('info.py', os.getcwd()) | 10 | file_path = find_file('info.py', os.getcwd()) | ||
11 | 11 | ||||
12 | spec = importlib.util.spec_from_file_location("info", file_path) | 12 | spec = importlib.util.spec_from_file_location("info", file_path) | ||
13 | info = importlib.util.module_from_spec(spec) | 13 | info = importlib.util.module_from_spec(spec) | ||
14 | spec.loader.exec_module(info) | 14 | spec.loader.exec_module(info) | ||
15 | X = info.POSITION + 1 | 15 | X = info.POSITION + 1 | ||
16 | 16 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|