• PHP程序员函数习惯 Python实现 funlib


    #/usr/bin/env python
    #-*- coding:utf-8 -*-

    import sys
    reload(sys)
    sys.setdefaultencoding('utf-8')
    import os
    import os.path

    def getpwd():
        #获取脚本路径
        path = sys.path[0]
        #判断为脚本文件还是py2exe编译后的文件,如果是脚本文件,则返回的是脚本的目录,如果是py2exe>编译后的文件,则返回的是编译后的文件路径
        if os.path.isdir(path):
            return path
        elif os.path.isfile(path):
            return os.path.dirname(path)

    def file_get_contents(filename):
        if not filename:
            print '==== ' + filename + ' is Null! ===='
            return 0
        if not os.path.exists(filename):
            print '====' + filename + ' is not exist! ===='
            return 0
        f = open(filename, 'r')
        text = f.read()
        f.close()
        return text

    def file_put_contents(filename, contents):
        if not filename:
            print '==== ' + filename + ' is Null! ===='
            return 0
        dirname = os.path.dirname(filename)
        if dirname and not os.path.exists(dirname):
            os.makedirs(dirname, 0777)

        f = open(filename, 'w+')
        f.write(contents)
        f.close()
        return 1

    def scandir(dirname, mod = ''):
        if not filename:
            print '==== ' + filename + ' is Null! ===='
            return 0
        if not os.path.exists(filename):
            print '====' + filename + ' is not exist! ===='
            return 0
        if os.path.isfile(dirname):
            dirname = os.path.dirname(dirname)
        dirinfo = {'parent': '', 'dirs': '', 'files': ''}
        for parent,dirs,files in os.walk(dirname):
            dirinfo['parent'] = parent
            dirinfo['dirs']  = dirs
            dirinfo['files'] = files
        if mod == 'dir':
            del dirinfo['files']
            return dirinfo
        if mod == 'file':
            del dirinfo['dirs']
            return dirinfo
        return dirinfo
    #============= Add Date 2013-12-17 14:00 ======================

    更新页面:

    http://www.hacktea8.com/read-htm-tid-9476-ds-1.html

  • 相关阅读:
    HTML 5 视频/音频
    vue 未完待续
    asp.net中使用log4net
    图片预加载:jquery 图片预加载功能,可以实现先模糊在清晰的显示
    IIS配置PHP环境
    学习ASP.Net的过滤器
    最好用的jQuery插件,240多个,绝对的JQUERY插件库
    Windows7&IIS7.5部署Discuz全攻略
    AjaxPro使用
    ASP.NET XML读取、增加、修改和删除操作
  • 原文地址:https://www.cnblogs.com/zhongbin/p/3478781.html
Copyright © 2020-2023  润新知