Hello everybody.
I'm wondering how to iterate over a tuple like this
[A,B,C,D]
while saving A and C in a list.
My problem is that C sometimes is a tuple of the same structure
itself...
thanks!
korovev 9 1259 ko*******@gmail.com wrote:
Hello everybody.
I'm wondering how to iterate over a tuple like this
[A,B,C,D]
while saving A and C in a list.
My problem is that C sometimes is a tuple of the same structure
itself...
thanks!
korovev
First of all [A,B,C,D] is a list not a tuple. (A,B,C,D) is a tuple.
Without a better example or explanation of what you are trying to do it is
difficult, but I'll give it a try:
myTuple=(A,B,C,D)
for n, item enumerate(myTuple):
if n in (0,2):
myList.append(item)
-Larry
[cut]
>
Without a better example or explanation of what you are trying to do it is
difficult
You're right.
Actually i'm parsing an xml file using pyrxp, which returns something
like this:
(tagName, attributes, list_of_children, spare)
Where list_of_children might "be a list with elements that are 4-
tuples or plain strings".
In other terms, if I have something like this:
('<tagA><tagB>bobloblaw</tagB></tagA>')
it's parsed like this:
('tagA', None, [('tagB', None, ['bobloblaw], None)], None)...
Fact is that my xml is much more deep... and I'm not sure how to
resolve it
thanx
On Fri, 26 Oct 2007 05:54:24 -0700, korovev76 wrote:
[cut]
>> Without a better example or explanation of what you are trying to do it is difficult
You're right.
Actually i'm parsing an xml file using pyrxp, which returns something
like this:
(tagName, attributes, list_of_children, spare)
Where list_of_children might "be a list with elements that are 4-
tuples or plain strings".
In other terms, if I have something like this:
('<tagA><tagB>bobloblaw</tagB></tagA>')
it's parsed like this:
('tagA', None, [('tagB', None, ['bobloblaw], None)], None)...
Fact is that my xml is much more deep... and I'm not sure how to
resolve it
Resolve *what*? The problem isn't clear yet; at least to me. Above you
say what you get. What exactly do you want? Examples please.
Ciao,
Marc 'BlackJack' Rintsch
Resolve *what*? The problem isn't clear yet; at least to me. Above you
say what you get. What exactly do you want? Examples please.
Sorry for my poor english, but I meant: how can I obtain a list of A
and C starting from something like this?
(A,B,C,D)
that could be
('tagA', None, [('tagB', None, ['bobloblaw], None)], None)
but also
('tagA', None, description, None)
when I don't know if C is a tuple or not?
I guess that, at least, within the cicle I may test if C is a tuple
or not.. And then apply the same cicle for C... and so on
Am i right?
ciao
korovev
ciao
korovev ko*******@gmail.com wrote:
>
[cut]
>> Without a better example or explanation of what you are trying to do it is difficult
You're right.
Actually i'm parsing an xml file using pyrxp, which returns something
like this:
(tagName, attributes, list_of_children, spare)
Where list_of_children might "be a list with elements that are 4-
tuples or plain strings".
In other terms, if I have something like this:
('<tagA><tagB>bobloblaw</tagB></tagA>')
it's parsed like this:
('tagA', None, [('tagB', None, ['bobloblaw], None)], None)...
Fact is that my xml is much more deep... and I'm not sure how to
resolve it
Probably you want some sort of visitor pattern.
e.g. (warning untested pseudo code ahead)
def walkTree(tree, visitor):
tag, attrs, children, spare = tree
fn = getattr(visitor, 'visit_'+tag, None)
if not fn: fn = visitor.visitDefault
fn(tag, attrs, children, spare)
for child in children:
if isinstance(child, tuple):
walktree(child, visitor)
else:
visitor.visitContent(child)
class Visitor:
def visitDefault(self, t, a, c, s): pass
def visitContent(self, c): pass
.... then when you want to use it you subclass Visitor adding appropriate
visit_tagA, visit_tabB methods for the tags which interest you. You walk
the tree, and store whatever you want to save in your visitor subclass
instance.
On 26 Ott, 19:23, Dennis Lee Bieber <wlfr...@ix.netcom.comwrote:
(A,B,C,D)
that could be
('tagA', None, [('tagB', None, ['bobloblaw], None)], None)
"C" isn't a tuple in your example either. It is a one-element list
(the single element INSIDE the list is a tuple whose third element is a
list containing a non-terminated string -- so the entire structure is
invalid)
i'm not sure what u mean with "the entire structure is invalid"...
that's exactly what I got while parsing... ko*******@gmail.com wrote:
On 26 Ott, 19:23, Dennis Lee Bieber <wlfr...@ix.netcom.comwrote:
(A,B,C,D) that could be ('tagA', None, [('tagB', None, ['bobloblaw], None)], None)
"C" isn't a tuple in your example either. It is a one-element list (the single element INSIDE the list is a tuple whose third element is a list containing a non-terminated string -- so the entire structure is invalid)
i'm not sure what u mean with "the entire structure is invalid"...
that's exactly what I got while parsing...
Your structure is correct. Dennis just didn't read all the matching
parens and brackets properly.
>
--
Michael Torrie
Assistant CSR, System Administrator
Chemistry and Biochemistry Department
Brigham Young University
Provo, UT 84602
+1.801.422.5771
On Fri, 26 Oct 2007 14:26:24 -0600, Michael L Torrie wrote: ko*******@gmail.com wrote:
[snip]
>>>('tagA', None, [('tagB', None, ['bobloblaw], None)], None)
^
Syntax error behind ``'bobloblaw``.
>> "C" isn't a tuple in your example either. It is a one-element list (the single element INSIDE the list is a tuple whose third element is a list containing a non-terminated string -- so the entire structure is invalid)
i'm not sure what u mean with "the entire structure is invalid"... that's exactly what I got while parsing...
Your structure is correct. Dennis just didn't read all the matching
parens and brackets properly.
He certainly is -- *you* are misreading *him*. The nit he's picking is
the non-terminated string (quotation mark/apostrophe missing).
Nit-picking'ly,
Stargaming
On 26 Ott, 23:33, Stargaming <stargam...@gmail.comwrote:
He certainly is -- *you* are misreading *him*. The nit he's picking
is
the non-terminated string (quotation mark/apostrophe missing).
right, now i got it!
beside this, i'm trying to use the reduceXML function proposed by
Larry.. but I found out that sometimes pyrxp parses the newline too...
By now I guess it's not its fault, but it's becuase of the way the xml
file is written This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jeff Wagner |
last post by:
I've spent most of the day playing around with lists and tuples to get a really good grasp on what
you can do with them. I am still left with a question and that is, when should you choose a list or...
|
by: Thorsten Kampe |
last post by:
I found out that I am rarely using tuples and almost always lists
because of the more flexible usability of lists (methods, etc.)
To my knowledge, the only fundamental difference between tuples...
|
by: Darren Dale |
last post by:
Hello,
def test(data):
i = ? This is the line I have trouble with
if i==1: return data
else: return data
a,b,c,d = test()
|
by: Mike Meyer |
last post by:
It seems that the distinction between tuples and lists has slowly been
fading away. What we call "tuple unpacking" works fine with lists on
either side of the assignment, and iterators on the...
|
by: fff_afafaf |
last post by:
Do you know is it possible to put different kinds of tuples to one
container?
E.g. to a vector?
(The lengths of the tuples are different, and also the types in the
tuples are different..
-Is it...
|
by: rshepard |
last post by:
While working with lists of tuples is probably very common, none of my
five Python books or a Google search tell me how to refer to specific items
in each tuple. I find references to sorting a list...
|
by: rshepard |
last post by:
I'm a bit embarrassed to have to ask for help on this, but I'm not finding
the solution in the docs I have here.
Data are assembled for writing to a database table. A representative tuple
looks...
|
by: C.L. |
last post by:
I was looking for a function or method that would return the index to the first
matching element in a list. Coming from a C++ STL background, I thought it might
be called "find". My first stop was...
|
by: victor.herasme |
last post by:
Hi Everyone,
i have another question. What if i wanted to make n tuples, each with
a list of coordinates. For example :
coords = list()
for h in xrange(1,11,1):
for i in xrange(1, 5, 1) :...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
| |