cs50/python-cs50

CS50 module prevents ability to import local python files

Filip62 opened this issue · 2 comments

### Note: This does not happen on CS50 Web IDE.
### Note: I was using VSCode on my PC.
### Note: It is not necessarily an issue, but I think you should definitely point it out in the course.

While working on pset7 from CS50 on edX,

In the application.py, if I imported the CS50 module before I import the functions in helpers.py,
which is located in the same directory as application.py.

application.py:

import cs50
import re
from flask import Flask, abort, redirect, render_template, request
from html import escape
from werkzeug.exceptions import default_exceptions, HTTPException

from helpers import lines, sentences, substrings

Then I get this error:

Traceback (most recent call last):
  File "/home/filip/Web/Workspace/similarities/application.py", line 7, in <module>
    from helpers import lines, sentences, substrings
ModuleNotFoundError: No module named 'helpers'

But if I move the

import cs50

below

from helpers import lines, sentences, substrings

or if I move the

from helpers import lines, sentences, substrings

above the

import cs50

statement,

Modified application.py:

import re
from flask import Flask, abort, redirect, render_template, request
from html import escape
from werkzeug.exceptions import default_exceptions, HTTPException

from helpers import lines, sentences, substrings

import cs50

then everything works fine, because the CS50 module erases the local directory from sys.path from which apllication.py was ran after the local helpers import is done.

Thanks for catching this, @Filip62! We'll roll out a fix soon!