Petr,

This is a cool problem treading on the grounds of PyMO/Python/System
integration.  You could create a wrapper function that takes the
absolute path to the file, then chdir to the directory with the file,
and import the file. Once you os.chdir somewhere, cmd.pwd() should
return the new directory.  Also, instead of importing the file you
could os.chdir to the directory and then to cmd.do("run %s" %
fileName).

Here's an example of the former idea:

import os
from os import path

def myRun(fileName):
  p=path.dirname(fileName)
  f=path.basename(fileName)
  if f.endswith(".py"): f = f[:-3]

  os.chdir(p)
  # import using a string
  __import__(f)


To test, create a python script called "a.py" in "/tmp" and run with,
  myRun("/tmp/a.py")

You could extend the above to run a specific function within your file.

Cheers,

-- Jason

On Wed, Apr 14, 2010 at 2:53 AM, Petr Benes <60...@mail.muni.cz> wrote:
> Dear pyMol users,
> I am developing a python script for pyMol. If a user clicks File->Run
> and selects the script (for example "c:/test/myScript.py"), how do I
> determine the path of the script, i.e. ("c:/test/") from inside the
> running script?
> I tried various python possibilities (os.path.abspath(__file__),
> inspect.getfile(sys._getframe(1))), all of them point to the pyMol
> __init__.py file which is not what I need.
>
> Thank you. Petr Benes.
>
> ------------------------------------------------------------------------------
> Download Intel&#174; Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
> Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
> Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net
>



-- 
Jason Vertrees, PhD
PyMOL Product Manager
Schrodinger, LLC

(e) jason.vertr...@schrodinger.com
(o) +1 (603) 374-7120

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net

Reply via email to