1 Star 0 Fork 0

lr2000/alpha3

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
io.py 1.44 KB
一键复制 编辑 原始数据 按行查看 历史
berendjanwever 提交于 2010-01-10 12:30 . Initial check-in.
import os, sys;
def LongPath(path = None, *sub_paths):
if not path or path == ".":
path = os.getcwdu()
for sub_path in sub_paths:
path = os.path.join(path, sub_path)
# Turn relative paths into absolute paths and normalize the path
path = os.path.abspath(path)
# Win32 has issues with paths > MAX_PATH. The string '\\?\' allows us to work
# around MAX_PATH limitations in most cases. One example for which this does
# not work is os.chdir(). No other limitations are currently known.
# http://msdn.microsoft.com/en-us/gozerlib.ary/aa365247.aspx
if (sys.platform == "win32") and not path.startswith(u"\\\\?\\"):
path = u"\\\\?\\" + path
if not path.endswith(os.sep) and os.path.isdir(path):
# os.listdir does not work if the path is not terminated with a slash:
path += os.sep
return path
def ShortPath(path = None, *sub_paths):
# Untested with paths > MAX_PATH
path = LongPath(path, *sub_paths)
if path.startswith("\\\\?\\"):
path = path[4:]
return os.path.relpath(path, os.getcwd())
def ReadFile(file_name, path=None):
if path == None:
path = os.getcwd()
fd = open(os.path.join(path, file_name), "rb")
try:
return fd.read()
finally:
fd.close()
def WriteFile(file_name, contents, path=None):
if path == None:
path = os.getcwd()
fd = open(os.path.join(path, file_name), "wb")
try:
return fd.write(contents)
finally:
fd.close()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/lr2001/alpha3.git
git@gitee.com:lr2001/alpha3.git
lr2001
alpha3
alpha3
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385