Problem in class import

I need to run an application where files and folders are organized in different directories in linux. In the srv / directory I have a classone.py that imports another class that is found in another var/net/ classtwo.py directory. I realized that the script doesn’t run because it doesn’t matter the file maybe due to permissions issues, but I gave permissions to test it but it still doesn’t matter? Below is an example of the code:

from index import Index
o_html = Index().view()
self.wfile.write(bytes(o_html, "utf8"))

Hi Joäo. People will need more evidence to work with. What error message do you get?

If the problem is with import, as you suspect, then knowing the value of sys.path would be essential:

import sys; print(sys.path)

Import from arbitrary locations can be confusing, and it may be better to try some examples with your code in your working directory, which will be first on sys.path. Then try importing code from a directory under your home (user) directory. (Look up the PYTHONPATH environment variable.) Finally repeat the experiment with the directories you intend it to work with.

This bit is wrong:

because self is an undefined variable, but do you even get that far?

There is no error, when running the application in the browser the index.py page is completely blank with no error message ?

By the sound of it, you’re not running classone.py as an application. A server is running it (somehow) and presenting the results to your web browser. This leaves you (and us) with no clue how it fails.

How do you know it is a “problem in class import”? There is nothing visibly wrong with the import statement. Line 3 has the problem that self is undefined.

I’m sure you would work this out if you could run the code yourself, without the browser and server in the way, in an IDE or at the prompt. The trick with debugging is to narrow down to just the bit that is going wrong, and make it fail in the open, where you can explore exactly how.

The error message might be in the log of the server. However, I think this is a difficult way to debug code.

1 Like