I'm having big troubles coding a program, I decided to make the program on different files, having one class on each file and now it gives me the following error
File "principal.py", line 5, in <module>
import plotting.plot
File "/home/bojack/Dropbox/Maquina/obtencion/plotting/plot.py", line 1, in <module>
import matplotlib.pyplot as plt
File "/usr/lib/pymodules/python2.7/matplotlib/__init__.py", line 123, in <module>
import pyparsing
File "/usr/local/lib/python2.7/dist-packages/pyparsing-2.0.3-py2.7.egg/pyparsing.py", line 160, in <module>
alphas = string.ascii_lowercase + string.ascii_uppercase
AttributeError: 'module' object has no attribute 'ascii_lowercase'
The files were on a dir as follows
MyDir>>principal.py plot.py dxf.py linea.py string.py
If I run the plot.py file on a different directory, it works perfectly, it just doesn't work on that directory, so I rearrenged the plot.py file on a subdirectory , adding an init.py blank file also to the subdirectory as stated on Python Modules Contents And now I'm out of ideas.
here is the code of my scripts
dxf.py
#!/usr/bin/env python
class Lectura(object):
"""docstring for Lectura"""
def __init__(self, archive):
self.archive=archive
self.usuario=getpass.getuser()
def Pdf2Dxf(self):
os.system("pstoedit -f 'dxf:-polyaslines -mm' /home/%s/Downloads/%s.pdf /home/%s/Dropbox/Maquina/dxfs/%s.dxf"%(self.usuario,self.archive,self.usuario,self.archive))
print "pstoedit -f 'dxf:-polyaslines -mm' /home/%s/Downloads/%s.pdf /home/%s/Dropbox/Maquina/dxfs/%s.dxf"%(self.usuario,self.archive,self.usuario,self.archive)
def ai2dxf(self):
os.system("pstoedit -f 'dxf:-polyaslines -mm' /home/%s/Downloads/%s.ai '/home/%s/Dropbox/Maquina/dxfs/%s.dxf'"%(self.usuario,self.archive,self.usuario,self.archive));
def getDxf(self):
#La variable archive sera pedida en el programa principal
archivo='/home/%s/Dropbox/Maquina/dxfs/%s.dxf' %(self.usuario,self.archive)
dxf1 = dxfgrabber.readfile(archivo)
return dxf1
linea.py
class Lineas(object):
"""docstring for Dibujo"""
def __init__(self,dxf):
self.dxf=dxf
global start
global end
def grabLinea(self):
start=[]
end=[]
for linea in self.dxf.entities:
start.append(linea.start)
end.append(linea.end)
return (start,end)
def vector(self,startC,endC):
matrizX=[[0 for x in range(2)] for x in startC]
matrizY=[[0 for x in range(2)] for x in startC]
vector=[[0 for x in range(2)] for x in startC]
longi=len(matrizX)
for x in range(longi):
matrizX[x][0]=startC[x][0]
matrizX[x][1]=endC[x][0]
matrizY[x][0]=startC[x][1]
matrizY[x][1]=endC[x][1]
vector[x][0]=matrizX[x][1]-matrizX[x][0]
vector[x][1]=matrizY[x][1]-matrizY[x][0]
return vector
#!/usr/bin/env python
class String(object):
"""docstring for String"""
def __init__(self):
pass
def separar(self,matriz):
matrizC = [[0 for x in range(3)] for x in matriz]
i=0
j=0
for n in matriz:
n2=str(n)
split=n2.split(',')
for x in range(3):
matrizC[i][x]=split[x]
i+=1
return matrizC
def cortar(self,matriz):
matrizC = [[0 for x in range(3)] for x in matriz]
i=0
for linea in matriz:
for coordenada in range(3):
if coordenada==0:
corte=linea[0].strip()
matrizC[i][coordenada]=float(corte[1:])
if coordenada==1:
corte=linea[1].strip()
matrizC[i][coordenada]=float(matriz[i][coordenada])
if coordenada==2:
corte=linea[2].rstrip()
matrizC[i][coordenada]=0
i+=1
return matrizC
enter code here
import matplotlib.pyplot as plt
import numpy as np
class Graph(object):
"""docstring for Lectura"""
def __init__(self, start):
self.start=start
def plot(self,start):
start=np.array(start)
longi=len(start)
start=[]
for i in range(longi):
j=0
start.append([start[i][j],end[i][j]])
maxx=np.max(start)
minn=np.min(start)
soa =np.array(start)
X,Y = zip(*soa)
fig = plt.figure()
ax = fig.add_subplot(111)
print len(X)
for i in range(len(X)-1):
x_points = (X[i],X[i+1])
y_points = (Y[i],Y[i+1])
p = ax.plot(x_points, y_points, 'b')
ax.set_xlabel('x-points')
ax.set_ylabel('y-points')
ax.set_title('Simple XY point plot')
fig.show()
def pltshow(self):
plt.show()
#!/usr/bin/env python
import dxf
import string
import linea
import plotting.plot
import matplotlib.pyplot
import numpy
import dxfgrabber
import getpass
import os
class Principal(object):
"""docstring for Principal"""
def programa(self):
archivo=input('ingresa nombre del archivo : \n>>')
#instaciamos objetos
objdxf=dxf.Lectura(archivo)
stringg=string.String()
objdxf.Pdf2Dxf()
linea1=objdxf.getDxf()
lineas=linea.Lineas(linea1)
start,end=lineas.grabLinea()
startS=stringg.separar(start)
endS=stringg.separar(end)
startC=stringg.cortar(startS)
endC=stringg.cortar(endS)
plt=plot.Graph(startC,endC)
a=Principal()
a.programa()
it seems you have a string.py file in your folder so the import string will in fact import your string.py because since it has the same name of a built-in module, that gonna replace it. So I recommend to change the name of your file like classes.py and rather use from classes import String
Also you make a class for your main program, it's not the way to make an entry point in Python.
That's better :
#!/usr/bin/env python
import dxf
import string
from classes import String
import linea
import plotting.plot
import matplotlib.pyplot
import numpy
import dxfgrabber
import getpass
import os
def main():
archivo=input('ingresa nombre del archivo : \n>>')
#instaciamos objetos
objdxf=dxf.Lectura(archivo)
stringg=String()
objdxf.Pdf2Dxf()
linea1=objdxf.getDxf()
lineas=linea.Lineas(linea1)
start,end=lineas.grabLinea()
startS=stringg.separar(start)
endS=stringg.separar(end)
startC=stringg.cortar(startS)
endC=stringg.cortar(endS)
plt=plot.Graph(startC,endC)
if __name__ == '__main__':
main()
Note also that you should only import when needed, for example you use import string in your main code but you don't use it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With