I want to apply a method (replaceFieldsAndIndices) in my class to a
number of attributes of a data structure.
Specifically, to give some context, in the variable j below, I want to
replace wildcards with values.
I wanted to avoid cluttering the code with multiple calls to the
method replaceFieldsAndIndices.
The code below is WRONG, but hopefully illustrates what I am trying to
achieve.
Any suggestions how to code this is an efficient and maintainable (and
correct) manner?
# BAD code begins
wildcards = None
if trap:
for c in translation.expressionList:
wildcards += (c.rpn, c.format)
for c in translation.conditionList:
wildcards += (c.match, c.min, c.max, c.format)
else:
for c in translation.conditionRuleList:
wildcards += (c.format, c.condition, c.expression)
for c in translation.rules:
wildcards += (c.match, c.min, c.max, c.bit, c.format)
for i in wildcards:
for j in i:
try:
j = self.replaceFieldsAndIndices(j, rcn, rcu,
rcp, indices)
except:
# Ignore errors if condition has no format.
pass
# BAD code ends 1 1094
On Tue, 24 Jul 2007 02:26:15 -0700, NetHead wrote:
The code below is WRONG, but hopefully illustrates what I am trying to
achieve.
Any suggestions how to code this is an efficient and maintainable (and
correct) manner?
[…]
for i in wildcards:
for j in i:
try:
j = self.replaceFieldsAndIndices(j, rcn, rcu,
rcp, indices)
except:
# Ignore errors if condition has no format.
pass
Maybe you shouldn't silence all exceptions with a bare except here. This
swallows any errors in `replaceFieldsAndIndices()`. Maybe some of them
are not the exception you expect, but real errors in your program!?
Ciao,
Marc 'BlackJack' Rintscj This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: svilen |
last post by:
hello again.
i'm now into using python instead of another language(s) for
describing structures of data, including names, structure,
type-checks, conversions, value-validations, metadata etc....
|
by: Andrea Griffini |
last post by:
I did it.
I proposed python as the main language for our next CAD/CAM
software because I think that it has all the potential needed
for it. I'm not sure yet if the decision will get through, but...
|
by: Frank Millman |
last post by:
Hi all
I am writing a multi-user accounting/business system. Data is stored in
a database (PostgreSQL on Linux, SQL Server on Windows). I have written
a Python program to run on the client,...
|
by: Michael Sperlle |
last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems
to need changes to the kernel before it can be installed, and I have no
intention of going through whatever hell that would...
|
by: sonald |
last post by:
Hi,
I am using python2.4.1
I need to pass russian text into python and validate the same.
Can u plz guide me on how to make my existing code support the
russian text.
Is there any module...
|
by: Mark Tarver |
last post by:
How do you compare Python to Lisp? What specific advantages do you
think that one has over the other?
Note I'm not a Python person and I have no axes to grind here. This is
just a question for...
|
by: Adam Olsen |
last post by:
As was seen in another thread, there's a great deal of confusion
with regard to surrogates. Most programmers assume Python's unicode
type exposes only complete characters. Even CPython's own...
|
by: Thomas Mlynarczyk |
last post by:
Hello,
I started to write a lexer in Python -- my first attempt to do something
useful with Python (rather than trying out snippets from tutorials). It
is not complete yet, but I would like some...
|
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...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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: 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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |