Error in Chain of Function calls

G

Girish Sahani

Hi,

There is a code in my main function which is something like:

while prunedFinal != []:
prunedNew = genColocations(prunedK) ***
tableInstancesNew = genTableInstances(prunedNew,tableInstancesK)
tiCountDict = tiCount(tableInstancesNew)
tiDict = findPI(tableInstancesNew)
prunedFinal = pruneTI(tiDict,pi)
rulesDict = genRules(prunedFinal)
cpDict = findCP(rulesDict)
prunedRulesList = pruneCP(cpDict,cp)
prunedK = prunedFinal
tableInstancesK = tableInstancesNew
else:
return prunedRulesList

prunedK and tableInstancesK are defined in the main function. Before the
main function, i have defined the other functions such as
genColocations,genTableInstances,etc. Output of genColocations is to be
given to the next function genTableInstances,output of this function to
tiCount and findPI, and so on.
However i am getting an error at the line marked with ***.

Also,i am getting a ValueError in the code below:

for s in prunedNew:
substrings = [s[:i]+s[i+1:] for i in range(len(s))]
for string in substrings:
if string not in prunedK:
prunedNew.remove(s)
continue
continue

The error is:
prunedNew.remove(s)
ValueError: list.remove(x): x not in list

Could anyone enlighten me as to why i'm getting these two errors??

Thanks a lot,
girish
 
B

bruno at modulix

Girish said:
Hi,

There is a code in my main function which is something like:

while prunedFinal != []:
prunedNew = genColocations(prunedK) ***
tableInstancesNew = genTableInstances(prunedNew,tableInstancesK)
tiCountDict = tiCount(tableInstancesNew)
tiDict = findPI(tableInstancesNew)
prunedFinal = pruneTI(tiDict,pi)
rulesDict = genRules(prunedFinal)
cpDict = findCP(rulesDict)
prunedRulesList = pruneCP(cpDict,cp)
prunedK = prunedFinal
tableInstancesK = tableInstancesNew
else:
return prunedRulesList

prunedK and tableInstancesK are defined in the main function.

defined as what ? functions, strings, lists, classes, ... ?
Before the
main function, i have defined the other functions such as
genColocations,genTableInstances,etc. Output of genColocations is to be
given to the next function genTableInstances,output of this function to
tiCount and findPI, and so on.
However i am getting an error at the line marked with ***.

Which error ? How do you hope us to be of any help here if you don't *at
least* provide the full traceback ? FWIW, the canonical way to do things
is to:
- provide minimal *runnable* code exposing the problem
- explain what you hoped to get
- explain what you got instead (including full traceback)

As a matter of fact, it's often the case that one solves the problem
when working on the first point !-)

(snip)
 
G

Girish Sahani

Girish said:
Hi,

There is a code in my main function which is something like:

while prunedFinal != []:
prunedNew = genColocations(prunedK) ***
tableInstancesNew =
genTableInstances(prunedNew,tableInstancesK)
tiCountDict = tiCount(tableInstancesNew)
tiDict = findPI(tableInstancesNew)
prunedFinal = pruneTI(tiDict,pi)
rulesDict = genRules(prunedFinal)
cpDict = findCP(rulesDict)
prunedRulesList = pruneCP(cpDict,cp)
prunedK = prunedFinal
tableInstancesK = tableInstancesNew
else:
return prunedRulesList

prunedK and tableInstancesK are defined in the main function.

defined as what ? functions, strings, lists, classes, ... ?
PrunedK is a list that contains 2 length strings and tableInstancesK is a
dictionary,its keys are 2 length strings and values are lists of lists
Which error ? How do you hope us to be of any help here if you don't *at
least* provide the full traceback ? FWIW, the canonical way to do things
is to:
- provide minimal *runnable* code exposing the problem
- explain what you hoped to get
- explain what you got instead (including full traceback)

As a matter of fact, it's often the case that one solves the problem
when working on the first point !-)

(snip)
Ohh...I was thinking that posting the whole code would not be a good idea.
The error i get above is:
line 266, in colocationMiner
prunedNew = genColocations(prunedK)

Anyways, i've attached the file colocations.py. The expected output is a
List of rules (prunedRulesList).These rules are themselves lists.e.g
['ab','c'] denotes the rule ab=>c.
Please do have a look if you have time :).
 
B

Boris Borcic

Girish said:
Also,i am getting a ValueError in the code below:

for s in prunedNew:
substrings = [s[:i]+s[i+1:] for i in range(len(s))]
for string in substrings:
if string not in prunedK:
prunedNew.remove(s)
continue
continue

The error is:
prunedNew.remove(s)
ValueError: list.remove(x): x not in list

Could anyone enlighten me as to why i'm getting these two errors??

Why don't you use sets instead of lists ? It would make your life much easier.

Specifically here, the problem seems to be that for some s there is more than
one substring of it that fails to be in prunedK, so that the failing line is
called more than once for a single s.

The simplest modification is to replace your first 'continue' by a 'break' (and
remove the second 'continue' which serves no purpose).
 
B

Boris Borcic

Girish said:
Ohh...I was thinking that posting the whole code would not be a good idea.

And what changed your mind ? Please note the word "minimal" in bruno's sentence
about submitting your code. And also the request for explanations.
The error i get above is:
line 266, in colocationMiner
prunedNew = genColocations(prunedK)

OTOH, bruno asked for the full traceback, that's not it - that's not "the error"
in any constructive sense, neither its type nor its real location.
 
B

bruno at modulix

Girish said:
(snip)


Ohh...I was thinking that posting the whole code would not be a good idea.

It's *not* a good idea - unless the code is *very* short and has no
dependencies on anything else than the stdlib. Please re-read
*carefully* the first point :

- provide minimal *runnable* code exposing the problem

and notice the use of the word "minimal". I *never* suggested that you
post the *whole* code.
The error i get above is:
line 266, in colocationMiner
prunedNew = genColocations(prunedK)

This is *not* the error. It's a line number (which is totally useless if
you don't have the corresponding file). Please re-read what I wrote
about posting *the full traceback*. Tracebacks are not here to be
beautiful on your screen, there here to give you as much possible
informations about what went wrong.
Anyways, i've attached the file colocations.py.

Don't attach files. Reduce your code to the *minimal* *runnable* code
snippet reproducing the problem.

(snip a few hundred lines of code I won't certainly take time to read
unless I'm being paid for fixing 'em)
 
G

Girish Sahani

Thanks for the help boris....i'll try using sets instead of lists
But i dont understand the point below...full traceback means what :-?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,299
Messages
2,571,545
Members
48,297
Latest member
MarcoStinn

Latest Threads

Top