New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import error #7

Closed
sobolevn opened this Issue Apr 28, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@sobolevn
Owner

sobolevn commented Apr 28, 2015

I have experienced some very odd behaivor.
File structure:

  • settings
    • __ init__.py
    • first.py

In file __ init__.py:

include(
    'first.py',
    scope=locals()
)

In file first.py:

import os

class DevelopmentConfiguration(object):
    def test(self):
        # workaround: 
        # import os
        print os.path.join('root', 'subfolder')

test = DevelopmentConfiguration()
test.test()

This returns "NameError: global name 'os' is not defined".
Is it supposed to be like that?
There is a workaround to specify function-level imports, but it is an ugly solution.

I am using Python 2.7.5 and django-split-settings==0.1.1

@roxeteer

This comment has been minimized.

Collaborator

roxeteer commented Apr 28, 2015

Unfortunately I have to say that this project is more or less abandoned. I'm one of the original developers in this project, but I'm not very familiar with the Python internals that are causing this problem. However, I was able to reproduce the error.

It seems to occur only if a class is used. If you do simply

import os
print os.path.join('root', 'subfolder')

there's no error.

Maybe the error has something to do with the way django-split-settings works. What it actually does is that it creates one big settings file from the pieces that you give and then compiles it at once. So you can even have all the imports in one file which is included first and then use those imports in the files listed later. Not that it would help in your case, though.

I will close this issue because I don't see anything wrong in using the workaround of importing os inside the method.

@roxeteer roxeteer closed this Apr 28, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment