473,396 Members | 2,033 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,396 software developers and data experts.

test assignmet problem

So I tried this

if(not (attr=global_re.match(line)) ):
break

it says invalid syntax [on the =]
so it is not possible to do test and assignment in C style?
how can I write this otherwise?

Thnx
PAolo
--
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
Apr 23 '06 #1
5 910
Paolo Pantaleo wrote:
So I tried this

if(not (attr=global_re.match(line)) ):
break

it says invalid syntax [on the =]
so it is not possible to do test and assignment in C style?
how can I write this otherwise?

With fewer parentheses for a start, but all you have to do here is to do
the assignment and the test on separate lines:

attr = global_re.match(line)
if not attr:
break

In other cases you may have to work a bit harder to restructure your code.
Apr 23 '06 #2

"Paolo Pantaleo" <pa***********@gmail.com> wrote in message
news:ma***************************************@pyt hon.org...
So I tried this

if(not (attr=global_re.match(line)) ):
break

it says invalid syntax [on the =]
... because this syntax is not valid ...

so it is not possible to do test and assignment in C style?
... no it's not, see
http://www.python.org/doc/faq/genera...-an-expression

how can I write this otherwise?
... is this so bad?...

attr=global_re.match(line)
if not attr:
break

... or, since you don't seem to be doing much with attr, you could just do

if not global_re.match(line):
break

... and get rid of all those distracting ()'s!
Apr 23 '06 #3
2006/4/23, Paul McGuire <pt***@austin.rr._bogus_.com>:

"Paolo Pantaleo" <pa***********@gmail.com> wrote in message
news:ma***************************************@pyt hon.org...
So I tried this

if(not (attr=global_re.match(line)) ):
break

it says invalid syntax [on the =]
... because this syntax is not valid ...

so it is not possible to do test and assignment in C style?
... no it's not, see
http://www.python.org/doc/faq/genera...-an-expression

how can I write this otherwise?
... is this so bad?...

attr=global_re.match(line)
if not attr:
break

... or, since you don't seem to be doing much with attr, you could justdo

if not global_re.match(line):
break

... and get rid of all those distracting ()'s!
--
http://mail.python.org/mailman/listinfo/python-list


Thnx for the help,
actually the problme is not solved

i have [well I want to do...] something like:

if a=b():
do stuff with a
else if a=c():
do stuff with b
else:
do other stuff

well, two solutions are

a1=b()
a2=c()

if a1:
do stuff with a1
else if a2:
do stuff with a2
else:
do other stuff
the other is
if b():
a=b()
do stuff with a
else if c():
a=c()
do stuff with b
else:
do other stuff

Even if none is exactly the same about:
* the number of times the b() and c() functions are executed
* the final value of a

I think the right one is:

a=b()
if a:
do stuff with a
else:
a=c()
if a=c():
do stuff with b
else:
do other stuff
PAolo
--
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
Apr 24 '06 #4
Paolo Pantaleo wrote:
(snip)
Thnx for the help,
actually the problme is not solved

i have [well I want to do...] something like:

if a=b():
do stuff with a
else if a=c():
do stuff with b
where does this 'b' come from ?
else:
do other stuff

well, two solutions are

a1=b()
a2=c()

if a1:
do stuff with a1
else if a2:
do stuff with a2
else:
do other stuff
if the call to b() returns a non-false value, the call to c() is useless.

the other is
if b():
a=b()
do stuff with a
else if c():
a=c()
do stuff with b
else:
do other stuff
You still have useless function calls.
Even if none is exactly the same about:
* the number of times the b() and c() functions are executed
* the final value of a

I think the right one is:

a=b()
if a:
do stuff with a
else:
a=c()
if a=c():
do stuff with b
else:
do other stuff


Almost :

a = b()
if a:
do_stuff_with_b(a)
else:
a = c()
if a:
do_stuff_with_c(a)
else:
do_other_stuff()
Now there are probably better ways to write this, but this would require
more knowledge about your real code.

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Apr 25 '06 #5
bruno at modulix wrote:
Almost :

a = b()
if a:
do_stuff_with_b(a)
else:
a = c()
if a:
do_stuff_with_c(a)
else:
do_other_stuff()
Now there are probably better ways to write this, but this would require
more knowledge about your real code.


if there are more than a couple of options you can generalise code such as
this to use a for loop:

for guard, action in [
(b, do_stuff_with_b),
(c, do_stuff_with_c),
]:
if guard():
action(a)
break
else:
do_other_stuff()
Apr 25 '06 #6

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

Similar topics

0
by: Randell D. | last post by:
Folks, Ever since reading an interesting article in Linux Format on PHP whereby suggested code writing was made that could enhance performance on a server, I've started testing various bits of...
5
by: Jan Roland Eriksson | last post by:
Some more fine tuning and inclusion of last suggested text from regulars has been done to this test post #4 of the mFAQ. As usual, rip it up anywhere you feel that it's appropriate to do so. ...
0
by: Tim Haughton | last post by:
I've just released an article on using Test Driven Development with C# and Windows Forms. GUI's are often difficult to test, so I thought it might be of interest. The article along with the...
18
by: Scott David Daniels | last post by:
There has been a bit of discussion about a way of providing test cases in a test suite that _should_ work but don't. One of the rules has been the test suite should be runnable and silent at every...
8
by: Vladimir S. Oka | last post by:
Please ignore... Thanks Vladimir
3
by: Alex | last post by:
Hello. Maybe someone can help me. My development computer has: WindowsXP SP2 and MSSQL Server 2000 and IIS 5.0(or 5.1) Our webserver has: Windows2003 SP1 and MSSQL Server 2005 and IIS 6.0 We are...
2
by: Pierre Rouleau | last post by:
Hi all, I have a consistent test case where os.popen3() hangs in Windows. The system hangs when retrieving the lines from the child process stdout. I know there were several reports related to...
1
by: --== Alain ==-- | last post by:
Hi, I have a huge problem... My property does not appear in the "propertyGrid" of "test Container", when i test my custom control. Here is the custom control code : namespace...
176
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.