
Hello, I'm trying to write my own Chimera extension. First of all, I'd like to thank you for providing so much useful information and so many examples on your site, it's extremely helpful. But there's one problem that might be a serious issue once I try to share this extension with other people. I don't know why, every time I need the extension to write a file, I have to determine an exact path to the localisation where I want the file to be placed. Otherwise it always creates the file on the desktop (I use Windows 7). Is there any way to make Chimera create new files in the extension's directory without giving it an accurate path? Thank you in advance for your help, Mateusz

On May 7, 2011, at 1:07 PM, Mateusz Dobrychłop wrote:
Hello,
I'm trying to write my own Chimera extension. First of all, I'd like to thank you for providing so much useful information and so many examples on your site, it's extremely helpful.
But there's one problem that might be a serious issue once I try to share this extension with other people. I don't know why, every time I need the extension to write a file, I have to determine an exact path to the localisation where I want the file to be placed. Otherwise it always creates the file on the desktop (I use Windows 7).
Is there any way to make Chimera create new files in the extension's directory without giving it an accurate path?
Hi Mateusz, I think the answer is no, you cannot get Chimera to write new files in the extension's directory without giving an "accurate" (full) path. That said, it isn't that hard to generate the full path, since the Python module attribute __file__ gives the full path to that module source file. So to write the file "x.y" in the extension's directory you would: import os.path dir, fname = os.path.split(__file__) out = open(os.path.join(dir, "x.y"), "w") This raises the question of why you are writing a file into the extension directory. Is it a temporary file of some sort? If so, Chimera has a function (OpenSave.osTemporaryFile) for generating a temporary file path that will be removed when Chimera quits. So using that to open a temporary file ending in ".y" would be: from OpenSave import osTemporaryFile tmpPath = osTemporaryFile(suffix=".y") out = open(tmpPath, "w") --Eric Eric Pettersen UCSF Computer Graphics Lab http://www.cgl.ucsf.edu
participants (2)
-
Eric Pettersen
-
Mateusz Dobrychłop