0

I've written a python file and am trying to import it but it's not recognized. The file was saved as gentleboost_c_class.c in C:\User\apps\My documents. I tried to import it like this:

import gentleboost_c_class as gbc

But I get this error:

NameError: name 'gentleboost_c_class' is not defined

gentleboost_c_class.py begins like this:

from sklearn.externals.six.moves import zip
import numpy as np
import statsmodels.api as sm
class GentleBoostC:

.....

It compiles fine. Both files are in the same folder. What am I doing wrong?

6
  • How is python going to know where gentleboost_c_class is located? Commented May 14, 2014 at 15:58
  • Where is the file that you're importing from located? (i.e. not gentleboost_c_class.py but the other file) Commented May 14, 2014 at 16:00
  • You're getting a NameError, not an ImportError. Seems to me that you import your module as gbc, but later try to refer to it as gentleboost_c_class. Commented May 14, 2014 at 16:05
  • Both files the one I'm importing into, and the one I'm importing, are in the same folder, as I just mentioned at the end of the question. Commented May 14, 2014 at 16:05
  • 1
    @user961627 that's a different problem then. As the error message states, a module object is not callable, but you're trying to do that with gbc(). What are you actually trying to do? Instanciate the class GentleBoostC? Then it would be gbc.GentleBoostC(). Commented May 14, 2014 at 16:10

1 Answer 1

1

You're getting a NameError, not an ImportError.

So it seems to me that you import your module as gbc, but later try to refer to it as gentleboost_c_class.

If you import the module with

import gentleboost_c_class as gbc

that means it will be available under the global name gbc, but not as gentleboost_c_class.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.