LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   python mkdir ~/.foo (https://www.linuxquestions.org/questions/programming-9/python-mkdir-%7E-foo-284687/)

datadriven 01-31-2005 08:01 PM

python mkdir ~/.foo
 
This is probably simple but I just can't seem to find the answer.

From the command line

mkdir ~/.foo

will make a directory .foo/ in the home folder of the current user.

in python

import os
os.mkdir("~/.foo")

Will die with an error
Code:

SyntaxError: invalid syntax
>>> os.mkdir("~/.foo")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
OSError: [Errno 2] No such file or directory: '~/.foo'

Is there an easy way around this so I can write an app that will store config files in the users home directory without knowing the actual path of the users home directory?

datadriven 01-31-2005 11:51 PM

I was right it was simple.

import os,os.path
homedir = os.path.expanduser('~')
foo_folder = homedir + "/.foo"
os.mkdir(foo_folder)


All times are GMT -5. The time now is 08:33 PM.