error in importing a file in another file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shubh vanvat
    New Member
    • Nov 2016
    • 1

    error in importing a file in another file

    i have a file name student which i want to import in modify file i have used
    import student
    and
    student file has a lot of functions which i want to import
    i have even used
    from student import *
    but in both cases i am getting an error
    "no module name student"
  • Zakoss
    New Member
    • Nov 2016
    • 6

    #2
    This is hacky and even dirty, and in my opinion the language shouldn't impose its way of loading files across the filesystem. In PHP we solved the problem by letting the userland code register multiple autoloading functions that are called when a namespace/class is missing.

    Comment

    • dwblas
      Recognized Expert Contributor
      • May 2008
      • 626

      #3
      import searches the python path, so it can not find the file because it is in some other directory. To print the path, use the code below. You can also add the directory that the file is in to the python path so it searches that directory as well.
      Code:
      import sys
      print sys.path

      Comment

      Working...