Esempio n. 1
0
#coding:utf8

import os


def scrabs(f):
    '''
    この関数を実行したスクリプトの絶対パスを返す
    f : 関数実行元の __file__
    '''
    if os.path.isabs(f):
        return f
    else:
        return os.path.normpath(os.path.join(os.getcwd(),f))    

if __name__ == '__main__':
    print os.getcwd() # スクリプトを実行したディレクトリのパス。このスクリプトの位置ではない。
    print __file__
    
    print scrabs(__file__)
    
    if os.path.isabs(__file__):
        print __file__
    else:
        print os.path.normpath(os.path.join(os.getcwd(),__file__))
    from lib.OS import scrabs
    print scrabs(__file__)
    print scrabs(__file__,'A/index.html')
    
Esempio n. 2
0
#!/usr/bin/python
#coding:utf8
# Created:  2013-11-10
#

import os

print os.path.abspath('sample.txt')
from lib.OS import scrabs
print scrabs(__file__,'sample.txt')
Esempio n. 3
0
#!/usr/bin/python
#coding:utf8
# Created:  2013-11-12
#

import bz2
from lib.OS import scrabs

# 圧縮
with bz2.BZ2File(scrabs(__file__,'sample.txt.bz2'),'w') as w:
    with open(scrabs(__file__,'sample.txt')) as r:
        w.write(r.read())

# 解凍
with bz2.BZ2File(scrabs(__file__,'sample.txt.bz2')) as r:
    with open(scrabs(__file__,'sample2.txt'),'w') as w:
        w.write(r.read())