Home Download Buy Blog Forum Support

Window open_file

Window open_file

Postby badkins on Wed Apr 18, 2012 12:22 pm

Hello,

Apologies in advance for such a newbie question. I have searched the Forum and have tried numerous approaches, but I can't seem to get the Window open_file function to open a file! I have a TextCommand plugin with the following code that does not work, I get the error from Sublime: "Unable to open /home/public_html/asciidoc/functions/sys_init.txt". Help greatly appreciated! I am on a Windows computer. Note: the call to os.path.exists is successful.

Code: Select all
    filepath = '/home/public_html/asciidoc/functions/'
    filename = 'sys_init.txt'
    if os.path.exists(filepath+filename):
        v = sublime.active_window().open_file(filepath+filename)
    else:
        print('Oops!')
    return 0
Regards!
Brad Adkins
badkins
 
Posts: 2
Joined: Wed Apr 18, 2012 11:53 am
Location: Seattle, Washington USA

Re: Window open_file

Postby jps on Wed Apr 18, 2012 12:54 pm

It should work if you prepend the drive letter to the path
jps
Site Admin
 
Posts: 3077
Joined: Wed Mar 19, 2008 12:33 pm

Re: Window open_file

Postby agibsonsw on Wed Apr 18, 2012 1:00 pm

because 'os.path.exists' defaults to a different root than Sublime's 'open_file' - which defaults to the current project folder, or Packages path, I believe.

In case it's an issue, print() is Python 3.0 and ST defaults to its own local copy of Python 2.6 or 2.7.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Window open_file

Postby badkins on Wed Apr 18, 2012 10:34 pm

Thank you! Adding "C:" to the path worked! It would have taken me some time to try that. That is interesting stuff indeed! I'm not accustomed to including a drive letter in the path, my experience has been that the default drive is assumed. Live and learn!
Regards!
Brad Adkins
badkins
 
Posts: 2
Joined: Wed Apr 18, 2012 11:53 am
Location: Seattle, Washington USA


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 1 guest