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,437
  • 15
  • 21
user1357015
  • 10,429
  • 19
  • 62
  • 104

1 Answers1

7

You can use os.path.expanduser:

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