#πŸ”’ can't import file contents - not sure about project structure

16 messages Β· Page 1 of 1 (latest)

keen marsh
#

I am in src/heavy/automation_code.py. I am trying to access helper functions in src/utils/helper_functions.py Code:

folder_directory = Path(__file__).resolve().parent.parent; print(f'folder_directory: {folder_directory}')
sys.path.insert(0, str(folder_directory))
gritty voidBOT
#

@keen marsh

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

keen marsh
#

actually I found the problem. Helper functions also calls imports. How should I fix that? I want helper functions to not call functions from main (just the blank functions), as I've seen some AI research repo implement it that way

#

helper functions was just blank functions not getting called by main. But when I call that file all code will actually be run right?

shrewd nebula
#

to clarify if i understand the problem

file A imports file B, but you don't want some part of file B to run? @keen marsh

#

i cant tell if ur trying to say that is the problem

or cyclic dependency is the problem
or generic import not found error

keen marsh
#

hey so just looked this up. apparently imports.py containing all common imports is not supposed to be a thing

#

helper_functions.py was at the same level as imports.py. I was importing from imports.py in the helper_functions.py file. When I tried calling imports from another level it said error, but I think it was cuz of a circular import

shrewd nebula
#

does it actually say circular import in the error (are u importing imports.py from helper_functions.py?) and how are you running the file?

#

just checking haha in case we did the same mistake

#

posting the exact error trace would help a lot : D

#

( i gtg in 14 minutes)

gritty voidBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.