473,738 Members | 4,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2631
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
20337
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()', this.pinginterval); - but is there no way to do this without using the literal ObjectName? If I write 'this.methodName()' I get "Line 1 Char 1: Object doesn't support this property or method." in IE, and nothing happens in Firebird.
2
2268
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 inserting 5 times on the Server. Yet doing the exact same thing from a standalone workstation works fine. Please advise -- Lou L Clarion Data Systems
23
2205
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 = 5;
17
4221
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 Set rs = Me.RecordsetClone rs.Find "=" & lngContractID If Not rs.EOF Then Me.Bookmark = rs.Bookmark I must site the Heisenberb Uncertainty Principal here, as it
32
8867
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 of "return 0;". He explained that "return" is not a function but a stament, like I didn't know already. The other colleagues also argreed with him :(. Can someone please explain what's so wrong about using "return" with
5
5687
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 error with following SQL statement: $_sql = <<<SQLDOC LOCK TABLES `table_name` WRITE; INSERT INTO `table_name` ('col_a', 'col_b') VALUES ('value_a1', 'value_a2');
1
2387
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 look for when evaluating someone's code is a try/catch block. While it isn't a perfect indicator, exception handling is one of the few things that quickly speak about the quality of code. Within seconds you might discover that the code author...
2
3396
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 I'd like the attention of fp as well as C++ gurus if available. The language I'm implementing - PILS - is dynamically
67
7384
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 constantly cursing at the goto statement, accusing it of being some sort of spawn of satan. So it seems we have a pickle here. The thing is, at first thought it seems that there aren't any viable alternatives which are better suited for this...
0
8969
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9263
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6751
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.