Obtain the current path through Python Programming
When writing various applications, obtaining the current path has always been a classic problem. Only by obtaining the current path can we further find all other files in the same path. The Python programming language can also obtain the current path through some system calls.
The module provided in this Article can not only obtain the current path, but also form a URI string used by sqlobject to synthesize the database path with the specified file name in the current path.
The following code is available for your research:
#-*-Coding: GBK -*-
# File: curpath. py
# Date: 2006-12-23
# Authro: gashero
# Copyright @ 1999-2006, Harry gashero Liu.
"""
An idiot Module
Used only to obtain the current path
"""
Import OS
_ Localdir = OS. Path. dirname (_ file __)
_ Curpath = OS. Path. normpath (OS. Path. Join (OS. getcwd (), _ localdir ))
Curpath = _ curpath
# Dbfullpath = OS. Path. Join (curpath, sqlitedbfilename)
Def getsqlobjecturi (dbfilename ):
"Gets the connection string of sqlobject in the current path, in Uri format """
Global curpath
Dbpath = curpath. Replace (":", "|"). Replace ("//","/")
Return Unicode ("SQLite:/" + dbpath + "/" + dbfilename, "GBK"). encode ("UTF-8 ")
To a line:
Curpath = OS. Path. normpath (OS. Path. Join (OS. getcwd (), OS. Path. dirname (_ file __)))
You can:
Fullpath = OS. Path. Join (curpath, filename)