473,387 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Using something other than ';' to separate statements

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
Jul 18 '05 #1
9 2614
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
Jul 18 '05 #2
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 <pe***@engcorp.com> 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

Jul 18 '05 #3
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
Jul 18 '05 #4
On Wed, 30 Mar 2005 14:26:20 -0500, Peter Hansen <pe***@engcorp.com> 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
Jul 18 '05 #5
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: \n print "a > 5"\nelse:\n print "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é

Jul 18 '05 #6
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
Jul 18 '05 #7
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...
Jul 18 '05 #8
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/worksh...oceedings.html
Army Signal Corps: Cu Chi, Class of '70
Author: Teach Yourself Python in 24 Hours
Jul 18 '05 #9
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
Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
2
by: Lou L | last post by:
Are there any known issues for developing using Virtual PC. We're using it on a XP Pro system, with a Virtual PC Session being Windows 2003 Server running Sql Server? Our insert statements are...
23
by: Mark Anderson | last post by:
A 'for' loop takes 3 arguments (initialize; test; increment). The 'test' must equate as true or false This doesn't work... x = 5; for (y=1; (y==5); y+=1) { alert(x * y); } ...nor does... x...
17
by: Danny J. Lesandrini | last post by:
The following code works with a standard MDB to navigate to a particluar record (with a DAO recordset, of course) but it's giving me problems in an ADP I'm working on. Dim rs As ADODB.Recordset...
32
by: Mike Machuidel | last post by:
Hi, I'm a game developer programming mostly in C and ASM for about 7 years. Today at work a colleague (a C++ programmer) yelled at me I'm a bad C programmer because I use "return(0);" instead...
5
by: Tom | last post by:
I've used heredocs for single SQL statements without a problem. Also, I've tried this using the SQL form on PhpMyAdmin and it works so I conclude it should work in PHP. Problem: getting syntax...
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
2
by: Ole Nielsby | last post by:
First, bear with my xpost. This goes to comp.lang.c++ comp.lang.functional with follow-up to comp.lang.c++ - I want to discuss an aspect of using C++ to implement a functional language, and...
67
by: Rui Maciel | last post by:
I've been delving into finite state machines and at this time it seems that the best way to implement them is through an intense use of the goto statement. Yet, everyone plus their granmother is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.