LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-31-2005, 08:01 PM   #1
datadriven
Member
 
Registered: Jun 2003
Location: Holly Hill, Florida
Distribution: Slackware 10.1
Posts: 317

Rep: Reputation: 30
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?
 
Old 01-31-2005, 11:51 PM   #2
datadriven
Member
 
Registered: Jun 2003
Location: Holly Hill, Florida
Distribution: Slackware 10.1
Posts: 317

Original Poster
Rep: Reputation: 30
I was right it was simple.

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What is foo bar satimis Programming 25 04-26-2019 08:21 PM
For foo in bar; do angel115 Programming 1 11-16-2005 04:52 PM
grep -r foo /* alles32 Linux - General 2 09-19-2004 06:20 PM
"mkdir: cannot create directory `foo': Read-only file system" on FAT32 maddes Linux - Hardware 1 11-26-2003 06:19 PM
Foo? MasterC Linux - General 2 05-27-2003 03:17 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration