The use of $TM_FILEPATH with Python in TextMate
I'm making a TextMate command with python. The job is to get the current file name, get the html file name by changing the extension name, and run safari to open the html file.
#!/usr/bin/env python
import os.path
import os
oldName = $TM_FILEPATH
(name, ext) = os.path.splitext(oldName)
rename = name + ".html"
os.system("open -a Safari %s" % rename)
The problem is that python doesn't seem to understand $TM_FILENAME, as I get the following error.
File "/tmp/temp_textmate.A9q270", line 5 oldName = $TM_FILEPATH ^ SyntaxError: invalid syntax
What's wrong? How can I use $TM_FILEPATH just like I开发者_StackOverflow社区 do with bash?
import os
os.environ["TM_FILEPATH"]
(os.environ
is how you access environment variables in Python. It's a dictionary-like object.)
You probably want os.environ['TM_FILEPATH']
instead.
精彩评论