relative-path

How to get an absolute file path in Python

人走茶凉 提交于 2019-11-26 00:23:49
问题 Given a path such as \"mydir/myfile.txt\" , how do I find the file\'s absolute path relative to the current working directory in Python? E.g. on Windows, I might end up with: \"C:/example/cwd/mydir/myfile.txt\" 回答1: >>> import os >>> os.path.abspath("mydir/myfile.txt") 'C:/example/cwd/mydir/myfile.txt' Also works if it is already an absolute path: >>> import os >>> os.path.abspath("C:/example/cwd/mydir/myfile.txt") 'C:/example/cwd/mydir/myfile.txt' 回答2: You could use the new Python 3.4

How to use relative paths without including the context root name?

北城余情 提交于 2019-11-26 00:09:04
问题 To working my static file (CSS, JS) I have to write absolute path like /AppName/templates/style/main.css . Is there any solution, that I could write relative path like style/main.css ? 回答1: If your actual concern is the dynamicness of the webapp context (the "AppName" part), then just retrieve it dynamically by HttpServletRequest#getContextPath(). <head> <link rel="stylesheet" href="${pageContext.request.contextPath}/templates/style/main.css" /> <script src="${pageContext.request.contextPath}

Import a module from a relative path

你说的曾经没有我的故事 提交于 2019-11-25 23:57:17
问题 How do I import a Python module given its relative path? For example, if dirFoo contains Foo.py and dirBar , and dirBar contains Bar.py , how do I import Bar.py into Foo.py ? Here\'s a visual representation: dirFoo\\ Foo.py dirBar\\ Bar.py Foo wishes to include Bar , but restructuring the folder hierarchy is not an option. 回答1: Assuming that both your directories are real Python packages (do have the __init__.py file inside them), here is a safe solution for inclusion of modules relatively to

Relative imports for the billionth time

对着背影说爱祢 提交于 2019-11-25 22:15:17
问题 I\'ve been here: http://www.python.org/dev/peps/pep-0328/ http://docs.python.org/2/tutorial/modules.html#packages Python packages: relative imports python relative import example code does not work Ultimate answer to relative python imports Relative imports in Python Python: Disabling relative import and plenty of URLs that I did not copy, some on SO, some on other sites, back when I thought I\'d have the solution quickly. The forever-recurring question is this: With Windows 7, 32-bit Python

Convert absolute path into relative path given a current directory using Bash

大兔子大兔子 提交于 2019-11-25 20:29:54
Example: absolute="/foo/bar" current="/foo/baz/foo" # Magic relative="../../bar" How do I create the magic (hopefully not too complicated code...)? modulus0 Using realpath from GNU coreutils 8.23 is the simplest, I think: $ realpath --relative-to="$file1" "$file2" For example: $ realpath --relative-to=/usr/bin/nmap /tmp/testing ../../../tmp/testing xni $ python -c "import os.path; print os.path.relpath('/foo/bar', '/foo/baz/foo')" gives: ../../bar Offirmo This is a corrected, fully functional improvement of the currently best rated solution from @pini (which sadly handle only a few cases)

Are PHP include paths relative to the file or the calling code?

依然范特西╮ 提交于 2019-11-25 19:11:37
I'm having trouble understanding the ruleset regarding PHP relative include paths. If I run file A.PHP- and file A.PHP includes file B.PHP which includes file C.PHP, should the relative path to C.PHP be in relation to the location of B.PHP, or to the location of A.PHP? That is, does it matter which file the include is called from, or only what the current working directory is- and what determines the current working directory? Pekka 웃 It's relative to the main script, in this case A.php. Remember that include() just inserts code into the currently running script. That is, does it matter which