Re: How can I format an integer ?
Re: How can I format an integer ?
- Subject: Re: How can I format an integer ?
- From: André Berg <email@hidden>
- Date: Fri, 07 Nov 2008 12:03:43 +0100
Hi Skeeve,
Thank you very much for sharing this with us. As I haven't used
Perl much, I didn't know about the elegant solution to the
switched monetary and decimal separator problem you posted
with that Perl script.
I actually came to HERE strings (and HERE docs but those
didn't work so well) to get away from having to escape
double-quotes. For larger script this was driving me slowly
insane but that's just me ofc.
Because in Python you can also use single-quotes
to denote strings which means then you wouldn't have to escape
double-quotes any longer but this also means you can't use
"quoted form of". Of course the technique you are describing
works well too if you don't mind escaping double-quotes.
I use both depending on the size of the (Python) script. For smaller
scripts I use python -c and for larger scripts I use
set shellscript to "/usr/local/bin/python <<<\"
script here
\""
do shell script (shellscript)
Yes, you will still have to escape double-quotes but when using
strings with single quotes there's rarely a need to escape anything
at all. This of course only works with languages that can use single
quotes to delimit their strings.
Cheers
André
--- Original Nachricht ---
Absender: Skeeve
Datum: 07.11.2008 8:39 Uhr
André Berg schrieb:
I have also found that you can use normal Python syntax in HERE strings
once you figure out the backslash-salad that is.
You don't need to. Once I also found that for perl but soon learned
that ther is a better way and I guess the same is true for python.
In shell you can type:
perl -e 'script here'
I guess in python it's
python -c 'script here'
The solution when you want to do that with AS is:
do shell script "python -c " & (quoted form of "script here")
With this you only have to take care of backslashing quotes and
backslashes. I think that's an easy task. At least you don't have to
take care for a proper "HERE" - end string, can use linebrakes and
indents for formatting purposes and you get the advantage that the
python/perl script still can read STDIN for processing (small example
with too much code):
do shell script "echo " & myNumber " | perl -e " & (quoted form "
use strict;
use warnings;
while (<>) {
tr/,./.,/;
print;
}
")
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden