[Pythonmac-SIG] HFS versus POSIX paths (changed from fixing the documentation)
Daniel Lord
daniellord at mac.com
Thu Apr 20 23:33:01 CEST 2006
I changed the topic so many can avoid it and we don't bore them to
tears ;-)
On Apr 20, 2006, at 2:02, has wrote:
> As for working with HFS paths (and a pox on scriptable apps that
> require them, btw, because they're fundamentally unreliable), you
> ought to be able to use Carbon.CF to translate between POSIX/
> Windows/HFS path styles. Unfortunately, I suspect getting in and
> out of there may be one of the areas that's broken.
I am writing an app combining excel and python/appscript to fetch
quotes from the web and value stock portfolios .
But I give up on using appscript with Excel--some things just don't
work because I think the terminology is seriously warped if no
broken. Applescriptworks but appscript doesn't.
I instead build a text Applescript from strings and use popen2 to
invoke osascript like this example which reads in the stock symbols
from a named range in an excel spreadsheet:
def readSymbolList(self, workbook, worksheet, range):
_getSymbolsScript = """tell app "Microsoft Excel"
return Value of Range "%s" of Worksheet "%s" of
Workbook "%s"
end tell"""
# read symbols from spreadsheet
cout, cin = popen2.popen2( "/usr/bin/osascript -e \'%s\'" % \
(_getSymbolsScript % (range, worksheet, workbook)))
symbols = cout.readline()[:-1]
symbols = re.sub(",\s",",",symbols)
if (self.DEBUG):
print __module__, "::","symbols=", repr(symbols)
# create symbolList
symbolList = []
symbols = string.split(symbols, ",")
if (self.DEBUG):
print __module__, "::","stocks=", repr(symbols)
for symbol in symbols:
if (symbol != '0'):
symbolList.append(symbol)
cout.close()
cin.close()
return symbolList
> I wouldn't mind adding a makewithhfspath class method and hfspath
> instance method to macfile's Alias and File classes, but I'd want
> to be sure I had a correct implementation first, however, as it's
> not quite as trivial as it sounds on the surface (e.g. volume names
> are not a direct translation in either direction).
If you really desire to you can but I just wrote a quick hack using
re.sub() that correctly converts the paths I use so my needs are met.
Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/pythonmac-sig/attachments/20060420/f9924bd1/attachment.html
More information about the Pythonmac-SIG
mailing list