473,320 Members | 1,939 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,320 software developers and data experts.

Python IF THEN chain equivalence

I'm translating a program in Python that has this IF Then chain
IF x1 < limit: --- do a ---
IF x2 < limit: --- do b ---
IF x3 < limit: --- do c ---
.-----
------
IF x10 < limt: --- do j ---
THEN
THEN
-----
THEN
THEN
THEN

In other words, as long as 'xi' is less than 'limit' keep going
down the chain, and when 'xi' isn't less than 'limit' jump to end of
chain a continue.

Is this the equivalence in Python?

IF x1 < limit:
--- do a ---
elif x2 < limit:
--- do b ---
----
----
elif x10 < limit:
--- do j ---
Nov 13 '08 #1
15 3216
jzakiya schrieb:
I'm translating a program in Python that has this IF Then chain
IF x1 < limit: --- do a ---
IF x2 < limit: --- do b ---
IF x3 < limit: --- do c ---
.-----
------
IF x10 < limt: --- do j ---
THEN
THEN
-----
THEN
THEN
THEN

In other words, as long as 'xi' is less than 'limit' keep going
down the chain, and when 'xi' isn't less than 'limit' jump to end of
chain a continue.

Is this the equivalence in Python?

IF x1 < limit:
--- do a ---
elif x2 < limit:
--- do b ---
----
----
elif x10 < limit:
--- do j ---
Of course not. After "do a", it would stop.

You need to use

if x1 < limit:
do a
if x2 < limit:
do b
...
Alternatively, and depending on the nature of "do X", you can do

for x, todo in ((x1, do_a), (x2, do_b), ...):
if x < limit:
todo()
else:
break

This implies though that the "dos" are pure functions without (variable)
arguments.

Diez
Nov 13 '08 #2
I think you should rethink your post. The first case you posted makes no sense in any language I know. Also, a whole lot of nested IF's is a bad idea in any language. In Python, you will end up with code indented 40+ characters if you keep going.

----- Original Message ----
From: jzakiya <jz*****@mail.com>
To: py*********@python.org
Sent: Thursday, November 13, 2008 5:06:53 PM
Subject: Python IF THEN chain equivalence

I'm translating a program in Python that has this IF Then chain
IF x1 < limit: --- do a ---
IF x2 < limit: --- do b ---
IF x3 < limit: --- do c ---
.-----
------
IF x10 < limt: --- do j ---
THEN
THEN
-----
THEN
THEN
THEN

In other words, as long as 'xi' is less than 'limit' keep going
down the chain, and when 'xi' isn't less than 'limit' jump to end of
chain a continue.

Is this the equivalence in Python?

IF x1 < limit:
--- do a ---
elif x2 < limit:
--- do b ---
----
----
elif x10 < limit:
--- do j ---
--
http://mail.python.org/mailman/listinfo/python-list

__________________________________________________ ________________
Ask a question on any topic and get answers from real people. Go to Yahoo! Answers and share what you know at http://ca.answers.yahoo.com
Nov 13 '08 #3
On Nov 13, 5:21*pm, Alan Baljeu <alanbal...@yahoo.comwrote:
I think you should rethink your post. The first case you posted makes no sense in any language I know. *Also, a whole lot of nested IF's is a bad idea in any language. *In Python, you will end up with code indented 40+ characters if you keep going.

----- Original Message ----
From: jzakiya <jzak...@mail.com>
To: python-l...@python.org
Sent: Thursday, November 13, 2008 5:06:53 PM
Subject: Python IF THEN chain equivalence

I'm translating a program in Python that has this IF Then chain

IF *x1 < limit: * --- do a ---
* * IF *x2 < limit: *--- do b ---
* * * * IF x3 < limit: *--- do c ---
* * * * * * * * * * * *.-----
* * * * * * * * * * * * ------
* * * * * * * * * * IF *x10 < limt: --- do j ---
* * * * * * * * * * THEN
* * * * * * * * *THEN
* * * * * * * -----
* * * * * THEN
* * *THEN
THEN

In other words, as long as * *'xi' is less than 'limit' keep going
down the chain, and when 'xi' isn't less than 'limit' jump to end of
chain a continue.

Is this the equivalence in Python?

IF *x1 < limit:
* * * * --- do a *---
elif x2 < limit:
* * * * --- do b ---
----
----
elif x10 < limit:
* * * *--- do j ---

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

* * * __________________________________________________ ________________
Ask a question on any topic and get answers from real people. Go to Yahoo! Answers and share what you know athttp://ca.answers.yahoo.com

In the code the 'xi's and 'limit' are variables and the --- do letters
---
phrases are simply writes to any array: an_array[xi]=0

Actually, the code makes perfectly good sense, and is a necessity of
the algorithm I'm implementing, and works perfectly good in Forth, and
can be
written quite nicely within a normal page width.

I was just hoping I could perform the equivalent chain in Python
without
having to grossly indent the source code past the normal width of a
printed page.
But if that's the only way to do it in Python, then so be it.
Nov 13 '08 #4
On 2008-11-13, jzakiya <jz*****@mail.comwrote:
I'm translating a program in Python that has this IF Then chain
IF x1 < limit: --- do a ---
IF x2 < limit: --- do b ---
IF x3 < limit: --- do c ---
.-----
------
IF x10 < limt: --- do j ---
THEN
THEN
-----
THEN
THEN
THEN
The placement of the THEN statements makes absolutely no sense
in any language I've ever seen.
In other words, as long as 'xi' is less than 'limit' keep going
down the chain, and when 'xi' isn't less than 'limit' jump to end of
chain a continue.

Is this the equivalence in Python?

IF x1 < limit:
--- do a ---
elif x2 < limit:
--- do b ---
----
----
elif x10 < limit:
--- do j ---
No. That's not the same at all.
Here's one solution:

while True:
if x1 limit: break
do a
if x2 limit: break
do b
if x3 limit: break
do c
...
if x10 limit: break
do j
break

--
Grant Edwards grante Yow! Eisenhower!! Your
at mimeograph machine upsets
visi.com my stomach!!
Nov 13 '08 #5
On 2008-11-13, Grant Edwards <invalid@invalidwrote:
On 2008-11-13, jzakiya <jz*****@mail.comwrote:
>I'm translating a program in Python that has this IF Then chain
IF x1 < limit: --- do a ---
IF x2 < limit: --- do b ---
IF x3 < limit: --- do c ---
.-----
------
IF x10 < limt: --- do j ---
THEN
THEN
-----
THEN
THEN
THEN

The placement of the THEN statements makes absolutely no sense
in any language I've ever seen.
>In other words, as long as 'xi' is less than 'limit' keep going
down the chain, and when 'xi' isn't less than 'limit' jump to end of
chain a continue.

Is this the equivalence in Python?

IF x1 < limit:
--- do a ---
elif x2 < limit:
--- do b ---
----
----
elif x10 < limit:
--- do j ---

No. That's not the same at all.
Here's one solution:

while True:
if x1 limit: break
do a
if x2 limit: break
do b
if x3 limit: break
do c
...
if x10 limit: break
do j
break
Oops. I botched the case where xN == limit. Each of the tests
should be xN >= limit.

--
Grant Edwards grante Yow! ... I see TOILET
at SEATS ...
visi.com
Nov 13 '08 #6
On 2008-11-13 23:31, jzakiya wrote:
On Nov 13, 5:21 pm, Alan Baljeu <alanbal...@yahoo.comwrote:
>I think you should rethink your post. The first case you posted makes no sense in any language I know. Also, a whole lot of nested IF's is a bad idea in any language. In Python, you will end up with code indented 40+ characters if you keep going.

----- Original Message ----
From: jzakiya <jzak...@mail.com>
To: python-l...@python.org
Sent: Thursday, November 13, 2008 5:06:53 PM
Subject: Python IF THEN chain equivalence

I'm translating a program in Python that has this IF Then chain

IF x1 < limit: --- do a ---
IF x2 < limit: --- do b ---
IF x3 < limit: --- do c ---
.-----
------
IF x10 < limt: --- do j ---
THEN
THEN
-----
THEN
THEN
THEN

In other words, as long as 'xi' is less than 'limit' keep going
down the chain, and when 'xi' isn't less than 'limit' jump to end of
chain a continue.

Is this the equivalence in Python?

IF x1 < limit:
--- do a ---
elif x2 < limit:
--- do b ---
----
----
elif x10 < limit:
--- do j ---

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

__________________________________________________ ________________
Ask a question on any topic and get answers from real people. Go to Yahoo! Answers and share what you know athttp://ca.answers.yahoo.com


In the code the 'xi's and 'limit' are variables and the --- do letters
---
phrases are simply writes to any array: an_array[xi]=0

Actually, the code makes perfectly good sense, and is a necessity of
the algorithm I'm implementing, and works perfectly good in Forth, and
can be
written quite nicely within a normal page width.

I was just hoping I could perform the equivalent chain in Python
without
having to grossly indent the source code past the normal width of a
printed page.
But if that's the only way to do it in Python, then so be it.
You should probably consider using a function and then
convert the conditions to define return points:

def do_something(...args...):

if x1 >= limit:
return
...do a...
if x2 >= limit:
return
...do b...
etc.

That is provided I understand the flow of control in your
example... it's kind of strange to have THEN mark the *end*
of the then-branch in an if-then-else construct.

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source (#1, Nov 13 2008)
>>Python/Zope Consulting and Support ... http://www.egenix.com/
mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
__________________________________________________ ______________________
2008-11-12: Released mxODBC Connect 0.9.3 http://python.egenix.com/

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
Nov 13 '08 #7
On Nov 13, 5:48*pm, "M.-A. Lemburg" <m...@egenix.comwrote:
On 2008-11-13 23:31, jzakiya wrote:
On Nov 13, 5:21 pm, Alan Baljeu <alanbal...@yahoo.comwrote:
I think you should rethink your post. The first case you posted makes no sense in any language I know. *Also, a whole lot of nested IF's is a bad idea in any language. *In Python, you will end up with code indented 40+ characters if you keep going.
----- Original Message ----
From: jzakiya <jzak...@mail.com>
To: python-l...@python.org
Sent: Thursday, November 13, 2008 5:06:53 PM
Subject: Python IF THEN chain equivalence
I'm translating a program in Python that has this IF Then chain
IF *x1 < limit: * --- do a ---
* * IF *x2 < limit: *--- do b ---
* * * * IF x3 < limit: *--- do c ---
* * * * * * * * * * * *.-----
* * * * * * * * * * * * ------
* * * * * * * * * * IF *x10 < limt: --- do j ---
* * * * * * * * * * THEN
* * * * * * * * *THEN
* * * * * * * -----
* * * * * THEN
* * *THEN
THEN
In other words, as long as * *'xi' is less than 'limit' keep going
down the chain, and when 'xi' isn't less than 'limit' jump to end of
chain a continue.
Is this the equivalence in Python?
IF *x1 < limit:
* * * * --- do a *---
elif x2 < limit:
* * * * --- do b ---
----
----
elif x10 < limit:
* * * *--- do j ---
--http://mail.python.org/mailman/listinfo/python-list
* * * __________________________________________________ ________________
Ask a question on any topic and get answers from real people. Go to Yahoo! Answers and share what you know athttp://ca.answers.yahoo.com
In the code the 'xi's and 'limit' are variables and the --- do letters
---
phrases are simply writes to any array: * an_array[xi]=0
Actually, the code makes perfectly good sense, and is a necessity of
the algorithm I'm implementing, and works perfectly good in Forth, and
can be
written quite nicely within a normal page width.
I was just hoping I could perform the equivalent chain in Python
without
having to grossly indent the source code past the normal width of a
printed page.
But if that's the only way to do it in Python, then so be it.

You should probably consider using a function and then
convert the conditions to define return points:

def do_something(...args...):

* * if x1 >= limit:
* * * * return
* * ...do a...
* * if x2 >= limit:
* * * * return
* * ...do b...
* * etc.

That is provided I understand the flow of control in your
example... it's kind of strange to have THEN mark the *end*
of the then-branch in an if-then-else construct.

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source *(#1, Nov 13 2008)>>Python/Zope Consulting and Support ... * * * *http://www.egenix.com/
>mxODBC.Zope.Database.Adapter ... * * * * * *http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ... * * * *http://python.egenix.com/

__________________________________________________ ______________________
2008-11-12: Released mxODBC Connect 0.9.3 * * *http://python.egenix..com/

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::

* *eGenix.com Software, Skills and Services GmbH *Pastor-Loeh-Str.48
* * D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
* * * * * *Registered at Amtsgericht Duesseldorf: HRB 46611
It's interesting to see people think it's strange to have code that
has multiple nested levels of IF THEN. Apparently you haven't seen
any Forth, assembly, et al code. All you're doing is having the branch
point for each conditional be the end of the chain, otherwise it falls
through to the code after the conditional. This is done all the time
in languages that let you actually manipulate the hardware.

Just as a suggestion :-) a little humility would go a long way toward
being open minded and receptive to different paradigms. I've written
this program I'm doing now in Python in 3 other languages (including
Python, which I'm trying to make more efficient) and I seek to be
flexible in my software linguistic capabilities.

I asked a very narrow question about a very specific language
mechanism, and I know exactly what and why I'm doing what I'm doing.

I'll try some of the suggestions and see if they make the routine
faster in Python.
Nov 13 '08 #8
On 2008-11-14 00:19, jzakiya wrote:
On Nov 13, 5:48 pm, "M.-A. Lemburg" <m...@egenix.comwrote:
>>>From: jzakiya <jzak...@mail.com>
To: python-l...@python.org
Sent: Thursday, November 13, 2008 5:06:53 PM
Subject: Python IF THEN chain equivalence
I'm translating a program in Python that has this IF Then chain
IF x1 < limit: --- do a ---
IF x2 < limit: --- do b ---
IF x3 < limit: --- do c ---
.-----
------
IF x10 < limt: --- do j ---
THEN
THEN
-----
THEN
THEN
THEN
You should probably consider using a function and then
convert the conditions to define return points:

def do_something(...args...):

if x1 >= limit:
return
...do a...
if x2 >= limit:
return
...do b...
etc.

That is provided I understand the flow of control in your
example... it's kind of strange to have THEN mark the *end*
of the then-branch in an if-then-else construct.

It's interesting to see people think it's strange to have code that
has multiple nested levels of IF THEN.
Not at all, that's fairly common in a lot of languages. It's not
common to mark the end of the then-part using the THEN keyword,
though. You'd normally expect the body of the then-part after the
keyword.
Apparently you haven't seen
any Forth, assembly, et al code. All you're doing is having the branch
point for each conditional be the end of the chain, otherwise it falls
through to the code after the conditional. This is done all the time
in languages that let you actually manipulate the hardware.

Just as a suggestion :-) a little humility would go a long way toward
being open minded and receptive to different paradigms.
Without giving any hint as to what the quoted snippet
of code is written in, how do you expect people to make
any sense of it ? Especially when using an RPN stack oriented
language in a Python forum.

There's a reason why we hide Python byte code running on the
VM stack machine from Python users ;-)

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source (#1, Nov 14 2008)
>>Python/Zope Consulting and Support ... http://www.egenix.com/
mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
__________________________________________________ ______________________
2008-11-12: Released mxODBC Connect 0.9.3 http://python.egenix.com/

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
Nov 14 '08 #9
jzakiya:
I asked a very narrow question about a very specific language
mechanism, and I know exactly what and why I'm doing what I'm doing.
You are of course free to use Python as you want. And probably some of
the answers weren't fully polite.
But it's interesting to see why they have given such answers. While
your code can be fit for Forth or assembly, it may be unfit, in its
current form, for the usual practices of Python programming (or C#/
Java programming, etc). In high-level languages large trees of very
nested ifs are seen as error-prone, not much readable, brittle... So
some alternative solutions are often used (even if they may be a
little slower).
If you need speed you may use Psyco too.

Bye,
bearophile
Nov 14 '08 #10
On Nov 13, 4:39*pm, Grant Edwards <invalid@invalidwrote:
On 2008-11-13, jzakiya <jzak...@mail.comwrote:
I'm translating a program in Python that has this IF Then chain
IF *x1 < limit: * --- do a ---
* * IF *x2 < limit: *--- do b ---
* * * * IF x3 < limit: *--- do c ---
* * * * * * * * * * * *.-----
* * * * * * * * * * * * ------
* * * * * * * * * * IF *x10 < limt: --- do j ---
* * * * * * * * * * THEN
* * * * * * * * *THEN
* * * * * * * -----
* * * * * THEN
* * *THEN
THEN

The placement of the THEN statements makes absolutely no sense
in any language I've ever seen.
It looks like Visual Basic.

IF a THEN
do_a
IF b THEN
do_b
IF c THEN
do_c
END IF
END IF
END IF

Words different, but same structure.
>
In other words, as long as * *'xi' is less than 'limit' keep going
down the chain, and when 'xi' isn't less than 'limit' jump to end of
chain a continue.
Is this the equivalence in Python?
*IF *x1 < limit:
* * * * --- do a *---
*elif x2 < limit:
* * * * --- do b ---
*----
*----
*elif x10 < limit:
* * * *--- do j ---

No. *That's not the same at all.

Here's one solution:

while True:
* if x1 limit: break
* do a
* if x2 limit: break
* do b
* if x3 limit: break
* do c
* ...
* if x10 limit: break
* do j
* break *

--
Grant Edwards * * * * * * * * * grante * * * * * * Yow! Eisenhower!! *Your
* * * * * * * * * * * * * * * * * at * * * * * * * mimeograph machine upsets
* * * * * * * * * * * * * * * *visi.com * * * * * *my stomach!!
Nov 14 '08 #11
jzakiya wrote:
I'm translating a program in Python that has this IF Then chain
IF x1 < limit: --- do a ---
IF x2 < limit: --- do b ---
IF x3 < limit: --- do c ---
.-----
------
IF x10 < limt: --- do j ---
THEN
THEN
-----
THEN
THEN
THEN

In other words, as long as 'xi' is less than 'limit' keep going
down the chain, and when 'xi' isn't less than 'limit' jump to end of
chain a continue.
if x1 < limit:
do a
if x2 < limit:
do b
if x3 < limit:
do c
Nov 14 '08 #12
On 2008-11-14, Ethan Furman <et***@stoneleaf.uswrote:
jzakiya wrote:
>I'm translating a program in Python that has this IF Then chain
IF x1 < limit: --- do a ---
IF x2 < limit: --- do b ---
IF x3 < limit: --- do c ---
.-----
------
IF x10 < limt: --- do j ---
THEN
THEN
-----
THEN
THEN
THEN

In other words, as long as 'xi' is less than 'limit' keep going
down the chain, and when 'xi' isn't less than 'limit' jump to end of
chain a continue.

if x1 < limit:
do a
if x2 < limit:
do b
if x3 < limit:
do c
.
.
.
etc
That doesn't do what the OP specified. If any of the
conditions fail, it should "jump" to the end and not execute
_any_ further "do" statements regardless of the values of
subsequent conditions.
On the plus side, it's easy to read and understand -- on the
minus side, it doesn't jump to the end once the tests start
failing.
If all you want is easy to read and understand, then this is
event simpler:
sys.exit(0)

--
Grant

Nov 14 '08 #13
Grant Edwards wrote:
On 2008-11-14, Ethan Furman <et***@stoneleaf.uswrote:
>jzakiya wrote:
>>I'm translating a program in Python that has this IF Then chain
IF x1 < limit: --- do a ---
IF x2 < limit: --- do b ---
IF x3 < limit: --- do c ---
.-----
------
IF x10 < limt: --- do j ---
THEN
THEN
-----
THEN
THEN
THEN

In other words, as long as 'xi' is less than 'limit' keep going
down the chain, and when 'xi' isn't less than 'limit' jump to end of
chain a continue.
if x1 < limit:
do a
if x2 < limit:
do b
if x3 < limit:
do c
.
.
.
etc

That doesn't do what the OP specified. If any of the
conditions fail, it should "jump" to the end and not execute
_any_ further "do" statements regardless of the values of
subsequent conditions.
Ack -- I was aware of the lack of jump, but missed that x7 might be less
than limit even if x6 is greater -- thanks.
>On the plus side, it's easy to read and understand -- on the
minus side, it doesn't jump to the end once the tests start
failing.

If all you want is easy to read and understand, then this is
event simpler:
sys.exit(0)
<sheepish grin>
~ethan~
Nov 14 '08 #14
On Fri, 14 Nov 2008 01:24:32 +0100, M.-A. Lemburg wrote:
>Apparently you haven't seen
any Forth, assembly, et al code. All you're doing is having the branch
point for each conditional be the end of the chain, otherwise it falls
through to the code after the conditional. This is done all the time
in languages that let you actually manipulate the hardware.

Just as a suggestion a little humility would go a long way toward
being open minded and receptive to different paradigms.

Without giving any hint as to what the quoted snippet of code is written
in, how do you expect people to make any sense of it ? Especially when
using an RPN stack oriented language in a Python forum.

There's a reason why we hide Python byte code running on the VM stack
machine from Python users ;-)
It's not like Forth is precisely an obscure little language. For a time,
it was possibly more popular than C. Or predated C? Whatever. I know I
learned about Forth long before I had even heard of C.

Other RPN languages include Postscript, not exactly unheard of either.
Open Firmware is Forth-like, and as you point out yourself, Python byte
code also is a stack-based language.

In conclusion, I'm not sure which is more disappointing: that the OP
couldn't be bothered to mention he was using a Forth-like syntax, or that
so many people failed to recognize it.

Anyway, for what it's worth, here's my translation into Python.

if x1 < limit:
a()
if x2 < limit:
b()
if x3 < limit:
c()
# blah blah blah...
if x10 < limt:
j()
Not very nice code. I think a better way is something like this:

keys = [x1, x2, x3, x4, x5, x6, x7, x8, x9, x10]
functions = [a, b, c, d, e, f, g, h, i, j]

for key, function in zip(keys, functions):
if key < limit:
function()
else:
break

--
Steven
Nov 14 '08 #15
jzakiya wrote:
On Nov 13, 5:48 pm, "M.-A. Lemburg" <m...@egenix.comwrote:
>On 2008-11-13 23:31, jzakiya wrote:
>>On Nov 13, 5:21 pm, Alan Baljeu <alanbal...@yahoo.comwrote:
I think you should rethink your post. The first case you posted makes no sense in any language I know. Also, a whole lot of nested IF's is a bad idea in any language. In Python, you will end up with code indented 40+ characters if you keep going.
----- Original Message ----
From: jzakiya <jzak...@mail.com>
To: python-l...@python.org
Sent: Thursday, November 13, 2008 5:06:53 PM
Subject: Python IF THEN chain equivalence
I'm translating a program in Python that has this IF Then chain
IF x1 < limit: --- do a ---
IF x2 < limit: --- do b ---
IF x3 < limit: --- do c ---
.-----
------
IF x10 < limt: --- do j ---
THEN
THEN
-----
THEN
THEN
THEN
In other words, as long as 'xi' is less than 'limit' keep going
down the chain, and when 'xi' isn't less than 'limit' jump to end of
chain a continue.
Is this the equivalence in Python?
IF x1 < limit:
--- do a ---
elif x2 < limit:
--- do b ---
----
----
elif x10 < limit:
--- do j ---
--http://mail.python.org/mailman/listinfo/python-list
__________________________________________________ ________________
Ask a question on any topic and get answers from real people. Go to Yahoo! Answers and share what you know athttp://ca.answers.yahoo.com
In the code the 'xi's and 'limit' are variables and the --- do letters
---
phrases are simply writes to any array: an_array[xi]=0
Actually, the code makes perfectly good sense, and is a necessity of
the algorithm I'm implementing, and works perfectly good in Forth, and
can be
written quite nicely within a normal page width.
I was just hoping I could perform the equivalent chain in Python
without
having to grossly indent the source code past the normal width of a
printed page.
But if that's the only way to do it in Python, then so be it.
You should probably consider using a function and then
convert the conditions to define return points:

def do_something(...args...):

if x1 >= limit:
return
...do a...
if x2 >= limit:
return
...do b...
etc.

That is provided I understand the flow of control in your
example... it's kind of strange to have THEN mark the *end*
of the then-branch in an if-then-else construct.

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source (#1, Nov 13 2008)>>Python/Zope Consulting and Support ... http://www.egenix.com/
>>>>mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
_________________________________________________ _______________________
2008-11-12: Released mxODBC Connect 0.9.3 http://python.egenix.com/

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::

eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611

It's interesting to see people think it's strange to have code that
has multiple nested levels of IF THEN. Apparently you haven't seen
any Forth, assembly, et al code. All you're doing is having the branch
point for each conditional be the end of the chain, otherwise it falls
through to the code after the conditional. This is done all the time
in languages that let you actually manipulate the hardware.

Just as a suggestion :-) a little humility would go a long way toward
being open minded and receptive to different paradigms. I've written
this program I'm doing now in Python in 3 other languages (including
Python, which I'm trying to make more efficient) and I seek to be
flexible in my software linguistic capabilities.

I asked a very narrow question about a very specific language
mechanism, and I know exactly what and why I'm doing what I'm doing.
Well in my case what you are doing is pissing me off by failing to
explain your original requirements sufficiently well and then taking a
condescending attitude towards genuine efforts to help by people whose
reputations I know and respect.

One wonders why someone at your stratospheric ability level would even
need any help from the likes of us.

You talk about the need for humility: physician, heal thyself. However
good you may be at software, you demonstrate a marked lack of
interpersonal skills.
I'll try some of the suggestions and see if they make the routine
faster in Python.
That's a good idea.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

Nov 17 '08 #16

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

Similar topics

467
by: mike420 | last post by:
THE GOOD: 1. pickle 2. simplicity and uniformity 3. big library (bigger would be even better) THE BAD:
176
by: Thomas Reichelt | last post by:
Moin, short question: is there any language combining the syntax, flexibility and great programming experience of Python with static typing? Is there a project to add static typing to Python? ...
41
by: Xah Lee | last post by:
here's another interesting algorithmic exercise, again from part of a larger program in the previous series. Here's the original Perl documentation: =pod merge($pairings) takes a list of...
10
by: Xah Lee | last post by:
another functional exercise with lists. Here's the perl documentation. I'll post a perl and the translated python version in 48 hours. =pod parti(aList, equalFunc) given a list aList of...
12
by: Jay | last post by:
ok, i thought for 2 seconds i might have created a Keylogger in python but i still have one major think stopping me... PYTHON. when i run the program i have python create a file named keylog2.log...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
26
by: hide1713 | last post by:
HI I'm currently using Python. I find that a instance variable must confined with self, for example: class a: def __init__(self): self.aa=10 def bb(self): print self.aa # See .if in c++,I...
4
by: neptundancer | last post by:
Hi, to extend my skills, I am learning python. I have written small program which computes math expression like "1+2*sin(y^10)/cos(x*y)" and similar, so far only + - * / ^ sin con tan sqrt are...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.