prosseek
prosseek

Reputation: 191079

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 do with bash?

Upvotes: 0

Views: 296

Answers (2)

mipadi
mipadi

Reputation: 411042

import os
os.environ["TM_FILEPATH"]

(os.environ is how you access environment variables in Python. It's a dictionary-like object.)

Upvotes: 2

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799180

You probably want os.environ['TM_FILEPATH'] instead.

Upvotes: 1

Related Questions