Le 18/11/2012 12:16, faia a �crit :
> Hello Aaron,
>
> I tried both your suggestions but it stil doesn't work.
>
> I even simplified the code and the data to look for the problem. But
> still, I get the attributeerror: 'str' object has no attribute 'atoms'
That's because you only work with strings. To use sympy functions, you
need to convert your strings to sympy objects at some point.
>
> Any idea?
I'll comment your script in-line.
>
> I would appreciate any help.
>
> An�lia
>
> -----------------------------------------------------------------------------------------------------------------------------------------------------
>
> import sympy
> from sympy.core import Symbol
> from sympy.logic.inference import satisfiable
> import re
>
> a = Symbol('a')
> b = Symbol('b')
> c = sympy.Symbol('c')
> d = sympy.Symbol('d')
> e = sympy.Symbol('e')
> f = sympy.Symbol('f')
> g = sympy.Symbol('g')
> h = sympy.Symbol('h')
> i = sympy.Symbol('i')
> j = sympy.Symbol('j')
> k = sympy.Symbol('k')
You don't use these Python variables, so I think that you don't need these.
>
> # open file
> file=open ("b.txt","r")
(not related to sympy): it's better to open files in a with block, that
way they always get closed automatically at the end of the block.
> for line in file:
> myrules.append([str(n) for n in line.strip().split('\t')])
Here would be a good place to convert the strings into sympy objects.
It could look like this (NB: the with statement replaces both the
file=open(...) and file.close() lines):
myrules = []
with open("b.txt", "r") as file:
for line in file:
myrules.append([sympify(n) for n in line.strip().split('\t')])
>
> for pair in myrules:
> try:
> x,y = pair[0],pair[1]
> print(y)
> print(satisfiable(y))
> except IndexError:
> print("A line in the file doesn't have enough entries.")
With the above change, this should now work.