Using something other than ';' to separate statements

2005-03-30 Thread Jaime Wyant
I know I've seen this somewhere, but can't seem to google it.  Is
there a way to use an alternate statement separator, other than the
default ';'?

jw
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using something other than ';' to separate statements

2005-03-30 Thread Terry Reedy

Jaime Wyant [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
I know I've seen this somewhere, but can't seem to google it.  Is
 there a way to use an alternate statement separator, other than the
 default ';'?

Other than \n, no.  Both are builtin to the language definition and 
interpreter.

Terry J. Reedy



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using something other than ';' to separate statements

2005-03-30 Thread Peter Hansen
Jaime Wyant wrote:
I know I've seen this somewhere, but can't seem to google it.  Is
there a way to use an alternate statement separator, other than the
default ';'?
The validity of Terry's answer (which is true for the general case)
aside, it might be possible to do what you are trying to do
if you could explain what it is you are really trying to accomplish,
rather than just asking about how you think you should accomplish
it...
(Ideas involving string.replace and exec come to mind, but
it's impossible to say whether that might work in your
context until you provide more background.)
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using something other than ';' to separate statements

2005-03-30 Thread Jaime Wyant
Well, I'm embedding python in an old C console app.  This app uses a
lot of ; delimited records.

I want to allow the execution of arbitrary python statements inside
some of these records.  I was hoping there was an easy way to set the
statement terminator.  I will simply make up a new terminator and do
some string substitution to turn my new terminator into python's ';'.

Thanks ya'll,
jw

On Wed, 30 Mar 2005 11:58:42 -0500, Peter Hansen [EMAIL PROTECTED] wrote:
 Jaime Wyant wrote:
  I know I've seen this somewhere, but can't seem to google it.  Is
  there a way to use an alternate statement separator, other than the
  default ';'?
 
 The validity of Terry's answer (which is true for the general case)
 aside, it might be possible to do what you are trying to do
 if you could explain what it is you are really trying to accomplish,
 rather than just asking about how you think you should accomplish
 it...
 
 (Ideas involving string.replace and exec come to mind, but
 it's impossible to say whether that might work in your
 context until you provide more background.)
 
 -Peter
 --
 http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using something other than ';' to separate statements

2005-03-30 Thread Peter Hansen
Jaime Wyant wrote:
Well, I'm embedding python in an old C console app.  This app uses a
lot of ; delimited records.
I want to allow the execution of arbitrary python statements inside
some of these records.  I was hoping there was an easy way to set the
statement terminator.  I will simply make up a new terminator and do
some string substitution to turn my new terminator into python's ';'.
You refer to it here as a statement terminator, but in
the first posting you called it a statement separator.
I believe it is just a separator, not a terminator, and
as such is not even required unless you need/want to have
two statements on the same line.
In all the tens of thousands of lines of Python code
I've written, I don't believe I've ever used a single
semicolon to separate two statements.
Perhaps you don't need them either...
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using something other than ';' to separate statements

2005-03-30 Thread André Roberge
Jaime Wyant wrote:
[snip]
After goofing around with this idea, I've realized you can't be very
expressive with a bunch of python statements strung together.  My
biggest problem is that I can't figure out (i don't think you can),
how to do conditionals that are strung together:
# This won't work
if a  5: print a  5;else print Doh
I've decided to just call a function from the semicolon delimited
record, using the return value in my `C' app...
The following might work based on the context:
code = '''if a  5: \nprint a  5\nelse:\nprint Doh\n'''
or, formatted differently
code = '''
if a  5:
print a  5
else:
print Doh
'''
Then, you could do
exec(code)
Yeah, I tried to make it work, but it just won't.  At least not in a
satisfactory way.
Thanks!
jw
André
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using something other than ';' to separate statements

2005-03-30 Thread Jaime Wyant
On Wed, 30 Mar 2005 14:26:20 -0500, Peter Hansen [EMAIL PROTECTED] wrote:
 Jaime Wyant wrote:
  Well, I'm embedding python in an old C console app.  This app uses a
  lot of ; delimited records.
 
  I want to allow the execution of arbitrary python statements inside
  some of these records.  I was hoping there was an easy way to set the
  statement terminator.  I will simply make up a new terminator and do
  some string substitution to turn my new terminator into python's ';'.
 
 You refer to it here as a statement terminator, but in
 the first posting you called it a statement separator.
 I believe it is just a separator, not a terminator, and
 as such is not even required unless you need/want to have
 two statements on the same line.

Yeah, my thinking was that a separator implied terminator, because to
separate something has to have a beginning / ending.  Sorry for the
inconsistency.

Anyway, I did want to be able to string a handful of statements
together in one string.  The python statements were one of the
semicolon delimited fields I'm working with -- which is where my
problem lied.

After goofing around with this idea, I've realized you can't be very
expressive with a bunch of python statements strung together.  My
biggest problem is that I can't figure out (i don't think you can),
how to do conditionals that are strung together:

# This won't work
if a  5: print a  5;else print Doh

I've decided to just call a function from the semicolon delimited
record, using the return value in my `C' app...

 In all the tens of thousands of lines of Python code
 I've written, I don't believe I've ever used a single
 semicolon to separate two statements.
 
 Perhaps you don't need them either...

Yeah, I tried to make it work, but it just won't.  At least not in a
satisfactory way.

Thanks!
jw
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using something other than ';' to separate statements

2005-03-30 Thread Michael Hoffman
Jaime Wyant wrote:
# This won't work
if a  5: print a  5;else print Doh
This will:
[Doh, a  5][a  5]
I highly discourage using it though--it's somewhat obtuse.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using something other than ';' to separate statements

2005-03-30 Thread Peter Hansen
Michael Hoffman wrote:
Jaime Wyant wrote:
# This won't work
if a  5: print a  5;else print Doh

This will:
[Doh, a  5][a  5]
I highly discourage using it though--it's somewhat obtuse.
It's also limited to evaluating expressions, which is
probably not very useful to the OP...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using something other than ';' to separate statements

2005-03-30 Thread Ivan Van Laningham
Hi All--

Michael Hoffman wrote:
 
 Jaime Wyant wrote:
 
  # This won't work
  if a  5: print a  5;else print Doh
 
 This will:
 
 [Doh, a  5][a  5]
 
 I highly discourage using it though--it's somewhat obtuse.


Bad Michael.  Bad, bad Michael.

Metta,
Ivan
--
Ivan Van Laningham
God N Locomotive Works
http://www.andi-holmes.com/
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps:  Cu Chi, Class of '70
Author:  Teach Yourself Python in 24 Hours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using something other than ';' to separate statements

2005-03-30 Thread Michael Hoffman
Ivan Van Laningham wrote:
Bad Michael.  Bad, bad Michael.
:(
Well personally I consider it better to tell people of hacks
like that with a warning not to use them than let them
discover them on their own (without such a warning).
Plus dubious Python hacks that should never be used in
production code are fun, which is what c.l.p. is all about!
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list