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

Python pearls required for iteration across fields of data structure

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

Jul 24 '07 #1
1 1093
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
Jul 24 '07 #2

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

Similar topics

7
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....
36
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...
29
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,...
5
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...
8
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...
852
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...
17
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...
14
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
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...
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.