

- Google earth desktop relative paths for icons full#
- Google earth desktop relative paths for icons code#
- Google earth desktop relative paths for icons windows#
Suppose we have the following directory structure: Tests On the other hand I found a solution that I prefer based on the same idea. Now this looks a bit odd to me, because if you move some_script.py around, the path to the root of our project may change (we would need to modify parents). # When we have different types of files in the `src_path`įor template_path in src_path.glob('*.ini'):įrom what suggest others and from pathlib documentation, a simple and clear solution is the following (suppose the file we need to refer to: Test/data/users.csv: # This file location: Tests/src/long/module/subdir/some_script.pyĬSV_USERS_PATH = PROJECT_ROOT / 'data' / 'users.csv' Moreover, we can select and check and copy/move those template files with pathlib: if src_path != cwd: Src_path_2 = (mod_path / relative_path_2).resolve() Src_path_1 = (mod_path / relative_path_1).resolve() Relative_path_1 = 'same/parent/with/helper/script/' # `src_path`: with the future power, it's just so straightforward Mod_path = Path(helper_script._file_).parent # `mod_path`: According to the accepted answer and combine with future power # `cwd`: current directory is straightforward
Google earth desktop relative paths for icons code#
Now let's solve this with the the amazing pathlib: # Hope you don't be imprisoned by legacy Python code :)
Google earth desktop relative paths for icons full#

Google earth desktop relative paths for icons windows#
However, this raises an exception on my Windows machine. '/System/Library/Frameworks/amework/Versions/2.5/lib/python2.5/lib. For example, I can do this on my Mac: > import collections #note that collections is a C extension in Python 2.5 However, I do know that there are some quirks with _file_ on C extensions. If so, that doesn't appear to be the case on my system (python 2.5.1 on OS X 10.5.7): #foo.py I'm assuming you mean the _main_ script when you mention running the file directly. when you run the file directly rather than importing it)?

:-)Īm I correct in thinking that _file_ is not always available (e.g. UPDATE: I'm responding to a comment here so I can paste a code sample. Note that if you're using setuptools, you should probably use its package resources API instead. This will give you the absolute path to the file you're looking for. In the file that has the script, you want to do something like this: import osįilename = os.path.join(dirname, 'relative/path/to/file/you/want')
