1

Under a linux structure, i've noticed that the following works:

import sys
sys.path.append("/home/username/fullpathname/")
import my_module

however the following does not

import sys
sys.path.append("~/fullpathname")
import my_module

is there a way to use the "~" operator? I don't understand why python wants the full directory. Thank you!

Venge
  • 2,417
  • 16
  • 21
user1357015
  • 11,168
  • 22
  • 66
  • 111

1 Answers1

7

You can use os.path.expanduser:

import sys, os
sys.path.append(os.path.expanduser("~/fullpathname"))
import mymodule
Venge
  • 2,417
  • 16
  • 21