4
\$\begingroup\$

I'm new to Python and I just wrote my first program with OOP. The program works just fine and gives me what I want. Is the code clear? Can you review the style or anything else?

import numpy as np
import time, os, sys
import datetime as dt

class TemplateGenerator(object):
"""This is a general class to generate all of the templates"""

def excelWrtGE(self,*typos):
    for typo in typos:
        self.excelWriteGE.write(typo)
    return


def create_KeywordsGE(self,list):
    list1=list.split("/")
    for x in list1:
        list1=[list1.strip()for list1 in list1]
    print list1
    keyword1="Patrone, Toner aufladen "+str(list1[0])
    keyword2="Patronen, CMYK, Set of, Ein" 
    keyword3="Set, of, Schwarz, Cyan, Magenta, Gelb, Photoblack"
    keyword4="Remanufactured ink, Druckerpatronen Ersatz "
    keyword5=str(list1[0])
    print keyword5
    i=1
    while len(keyword5)<50:
        keyword5_old=keyword5
        if i>=len(list1): break
        if len(list1)==1: break
        keyword5=keyword5+", "+str(list1[i])
        if len(keyword5)>50:
            keyword5=keyword5_old
            break
        i=i+1
    keywords=keyword1+"\t"+keyword2+"\t"+keyword3+"\t"+keyword4+"\t"+keyword5 + "\t"
    return keywords

def keyFeaturesGE(self,feat,inkNumber):
    list1=feat.split(",")
    for x in list1:
        list1=[list1.strip()for list1 in list1]
    if inkNumber==5:
        feat1="Lieferumfang: : 1 Schwarz, 1 Cyan, 1 Magenta, 1 Gelb , 1 Photoblack"
    if inkNumber==4:
        feat1="Lieferumfang: : 1 Schwarz, 1 Cyan, 1 Magenta, 1 Gelb "
    if inkNumber==1:
        feat1="Lieferumfang: : 1 Cyan "
    if inkNumber==2:
        feat1="Lieferumfang: : 1 Magenta "
    if inkNumber==3:
        feat1="Lieferumfang: : 1 Gelb "
    if inkNumber==0:
        feat1="Lieferumfang: : 1 Schwarz "
    if inkNumber==242:
        feat1="Lieferumfang: : 4 Schwarz, 2 Cyan, 2 Magenta, 2 Gelb "
    if inkNumber==54:
        feat1="Lieferumfang: : 5 Schwarz, 5 Cyan, 5 Magenta, 5 Gelb "
    if inkNumber==11:
        feat1="Lieferumfang: : 1 Photoblack"
    if inkNumber==25:
        feat1="Lieferumfang: : 2 Schwarz, 2 Cyan, 2 Magenta, 2 Gelb, 2 Photoblack "
    if inkNumber==45:
        feat1="Lieferumfang: : 4 Schwarz, 4 Cyan, 4 Magenta, 4 Gelb, 4 Photoblack "
    if inkNumber==24:
        feat1="Lieferumfang: : 2 Schwarz, 2 Cyan, 2 Magenta, 2 Gelb "

    feat2="100% Kompatibel"
    feat3="Bis zu 80% Druckkosten sparen - Premium Qualit\xE4t" 
    feat4="Geeignet f\xFCr Folgende Drucker: "+str(list1[0])
    feat5="Inhalt der Druckerpatronen ca. bei 5% Deckung (DIN A4)"
    print feat1
    i=1
    while len(feat4)<500:
        feat4_old=feat4
        if i>=len(list1): break
        if len(list1)==1: break
        feat4=feat4+", "+str(list1[i])
        if len(feat4)>500:
            feat4=feat4_old
            break
        i=i+1
    ListOfFeatures=feat1+"\t"+ feat2+"\t"+feat3+"\t"+feat4 + "\t" +feat5+"\t"
    return ListOfFeatures

def ManProNum(self,num):
    list1=num.split("/")
    for x in list1:
        list1=[list1.strip()for list1 in list1]
    ProdNum=str(list1[0])
    i=1
    while len(ProdNum)<40:
        ProdNum_old=ProdNum
        if i>=len(list1): break
        if len(list1)==1: break
        ProdNum=ProdNum+", "+str(list1[i])
        if len(ProdNum)>40:
            ProdNum=ProdNum_old
            break
        i=i+1
    ProdNum=ProdNum+"\t"
    return ProdNum

def pictureLink(self,amount):
    if amount==1:
        linkW="dfghj"
    elif amount==2:
        linkW="fgh"
    elif amount==4:
        linkW="hj"
    elif amount==5:
        linkW="lk"
    elif amount==6:
        linkW="erty"
    return str(linkW)

    # GERMANY STARTS HERE-----------------

def GenerateGETemplatesFor6(self,ElementsOfPrinter):

    FourSetSalePrice=round((float(ElementsOfPrinter[5])+2.5)*1.26*1.2*1.4*1.2,2)

    descr="Industriell wiederaufgearbeitete und gepr\xFCfte Druckerpatronen in Premium qualit\xE4t 100% Kompatible, keine Original Geeignet f\xFCr folgende Ger\xE4te: "+ElementsOfPrinter[0]+ ". Hinweis: Die auf unseren Shop aufgef\xFChrten Markennamen und Original Zubeh\xF6rbezeichnungen sind eingetragene Warenzeichen Ihrer jeweiligen Hersteller und dienen nur als Anwenderhilfe f\xFCr die Zubeh\xF6ridentifikation.\t" 

    title0="4 Druckerpatronen kompatibel f\xFCr "+ElementsOfPrinter[1]+" - "+ElementsOfPrinter[2]+" - " +ElementsOfPrinter[3]+" - "+ElementsOfPrinter[4]+" Set mit Chip\t" +str(FourSetSalePrice)+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],4) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"

    self.excelWrtGE(title0)

def GenerateGETemplatesFor7(self,ElementsOfPrinter):

    FiveSetSalePrice=round((float(ElementsOfPrinter[6])+2.5)*1.26*1.2*1.4*1.2,2)

    descr="Industriell wiederaufgearbeitete und gepr\xFCfte Druckerpatrone in Premium qualit\xE4t 100% Kompatible, keine Original Geeignet f\xFCr folgende Ger\xE4te: "+ElementsOfPrinter[0]+ ". Hinweis: Die auf unseren Shop aufgef\xFChrten Markennamen und Original Zubeh\xF6rbezeichnungen sind eingetragene Warenzeichen Ihrer jeweiligen Hersteller und dienen nur als Anwenderhilfe f\xFCr die Zubeh\xF6ridentifikation.\t" 

    title0="5 Druckerpatronen kompatibel f\xFCr "+ElementsOfPrinter[1]+" - "+ElementsOfPrinter[2]+" - " +ElementsOfPrinter[3]+" - "+ElementsOfPrinter[4]+" - "+ElementsOfPrinter[5]+" Set mit Chip\t" +str(round(FiveSetSalePrice,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],5) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"

    self.excelWrtGE(title0)

def GenerateGETemplatesFor9(self,ElementsOfPrinter):

    FourSETBuyingPrice=sum(map(float,ElementsOfPrinter[5::]))
    FourSetSalePrice=round((FourSETBuyingPrice+2.5)*1.26*1.2*1.4*1.2,2)

    descr="Industriell wiederaufgearbeitete und gepr\xFCfte Druckerpatrone in Premium qualit\xE4t 100% Kompatible, keine Original Geeignet f\xFCr folgende Ger\xE4te: "+ElementsOfPrinter[0]+ ". Hinweis: Die auf unseren Shop aufgef\xFChrten Markennamen und Original Zubeh\xF6rbezeichnungen sind eingetragene Warenzeichen Ihrer jeweiligen Hersteller und dienen nur als Anwenderhilfe f\xFCr die Zubeh\xF6ridentifikation.\t" 

    title0="4 Druckerpatronen kompatibel f\xFCr "+ElementsOfPrinter[2]+" - "+ElementsOfPrinter[3]+" - " +ElementsOfPrinter[4]+" - "+ElementsOfPrinter[5]+"  Set mit Chip\t" +str(round(FourSetSalePrice-1,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],4) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title1="Druckerpatrone kompatibel f\xFCr "+ElementsOfPrinter[2]+" Schwarz mit Chip\t" +str(round((float(ElementsOfPrinter[5])+2.5)*1.26*1.2*1.4*1.2,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],0) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title2="Druckerpatrone kompatibel f\xFCr "+ElementsOfPrinter[3]+" Cyan mit Chip\t" +str(round((float(ElementsOfPrinter[6])+2.5)*1.26*1.2*1.4*1.2,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],1) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title3="Druckerpatrone kompatibel f\xFCr "+ElementsOfPrinter[4]+" Magenta mit Chip\t" +str(round((float(ElementsOfPrinter[7])+2.5)*1.26*1.2*1.4*1.2,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],2) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title4="Druckerpatrone kompatibel f\xFCr "+ElementsOfPrinter[5]+" Gelb mit Chip\t" +str(round((float(ElementsOfPrinter[8])+2.5)*1.26*1.2*1.4*1.2,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],3) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title5="4 Druckerpatronen mit CHIP kompatibel f\xFCr "+ElementsOfPrinter[1]+" - "+ElementsOfPrinter[2]+" - " +ElementsOfPrinter[3]+" - "+ElementsOfPrinter[4] +" Multipack SET f\xFCr" +ElementsOfPrinter[0] +" mit Chip\t"  +str(round(FourSetSalePrice,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],4) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title6="XXL PREMIUM Druckerpatronen kompatibel f\xFCr "+ElementsOfPrinter[1]+", "+ElementsOfPrinter[2]+", "+ElementsOfPrinter[3]+", "+ElementsOfPrinter[4]+" SET "+ElementsOfPrinter[0]+"\t"  +str(round(FourSetSalePrice,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],4) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title7="20 Patronen MIT CHIP kompatibel zu "+ ElementsOfPrinter[1]+" - "+ElementsOfPrinter[2]+" - " +ElementsOfPrinter[3]+" - "+ElementsOfPrinter[4]+"\t"  +str(round((FourSETBuyingPrice*5+2.5)*1.26*1.2*1.4*1.2-5,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],54) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title8="10 Premium Druckerpatronen kompatibel f\xFCr "+ElementsOfPrinter[1]+" - "+ElementsOfPrinter[2]+" - " +ElementsOfPrinter[3]+" - "+ElementsOfPrinter[4]+"f\xFCr"+ElementsOfPrinter[0] +"2 SET + 2 BLACK\t"  +str(round(((FourSETBuyingPrice*2+2*float(ElementsOfPrinter[5]))+2.5)*1.26*1.2*1.4*1.2-2,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],242) +self.create_KeywordsGE(ElementsOfPrinter[0]) +self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title9="XXL PREMIUM Druckerpatronen kompatibel f\xFCr "+ElementsOfPrinter[1]+ "f\xFCr "+ElementsOfPrinter[2]+" Schwarz\t" +str(round((float(ElementsOfPrinter[5])+2.5)*1.26*1.2*1.4*1.2,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],0) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title10="XXL PREMIUM Druckerpatronen kompatibel f\xFCr "+ElementsOfPrinter[2]+ "f\xFCr "+ElementsOfPrinter[3]+" Cyan\t" +str(round((float(ElementsOfPrinter[6])+2.5)*1.26*1.2*1.4*1.2,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],1) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title11="XXL PREMIUM Druckerpatronen kompatibel f\xFCr "+ElementsOfPrinter[3]+ "f\xFCr "+ElementsOfPrinter[4]+" Magenta\t" +str(round((float(ElementsOfPrinter[7])+2.5)*1.26*1.2*1.4*1.2,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],2) +self.create_KeywordsGE(ElementsOfPrinter[0]) +self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title12="XXL PREMIUM Druckerpatronen kompatibel f\xFCr "+ElementsOfPrinter[4]+ "f\xFCr "+ElementsOfPrinter[5]+" Gelb\t"+str(round((float(ElementsOfPrinter[8])+2.5)*1.26*1.2*1.4*1.2,2))+"\t" +self.keyFeaturesGE(ElementsOfPrinter[0],3) +self.create_KeywordsGE(ElementsOfPrinter[0]) +self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"

    self.excelWrtGE(title0,title1,title2,title3,title4,title5,title6,title7,title8,title9,title10,title11,title12)

def GenerateGETemplatesFor11(self,ElementsOfPrinter):
    # print ElementsOfPrinter[5], ElementsOfPrinter[10]
    FiveSETBuyingPrice=sum(map(float,ElementsOfPrinter[6::]))
    FourSETBuyingPrice=sum(map(float,ElementsOfPrinter[7::]))

    FourSetSalePrice=(FourSETBuyingPrice+2.5)*1.26*1.2*1.4*1.2
    FiveSetSalePrice=round((FiveSETBuyingPrice+2.5)*1.26*1.2*1.4*1.2)

    descr="Industriell wiederaufgearbeitete und gepr\xFCfte Druckerpatrone in Premium qualit\xE4t 100% Kompatible, keine Original Geeignet f\xFCr folgende Ger\xE4te: "+ElementsOfPrinter[0]+ ". Hinweis: Die auf unseren Shop aufgef\xFChrten Markennamen und Original Zubeh\xF6rbezeichnungen sind eingetragene Warenzeichen Ihrer jeweiligen Hersteller und dienen nur als Anwenderhilfe f\xFCr die Zubeh\xF6ridentifikation.\t" 

    title0="4 Druckerpatronen kompatibel f\xFCr "+ElementsOfPrinter[1]+" - "+ElementsOfPrinter[2]+" - " +ElementsOfPrinter[3]+" - "+ElementsOfPrinter[4]+"  Set mit Chip\t" +str(round(FourSetSalePrice,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],4) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title1="Druckerpatrone kompatibel f\xFCr "+ElementsOfPrinter[1]+" Photoblack mit Chip\t" +str(round((float(ElementsOfPrinter[6])+2.5)*1.26*1.2*1.4*1.2,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],11) +self.create_KeywordsGE(ElementsOfPrinter[0]) +self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title2="Druckerpatrone kompatibel f\xFCr "+ElementsOfPrinter[2]+" Schwarz mit Chip\t" +str(round((float(ElementsOfPrinter[7])+2.5)*1.26*1.2*1.4*1.2,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],1) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title3="Druckerpatrone kompatibel f\xFCr "+ElementsOfPrinter[3]+" Cyan mit Chip\t" +str(round((float(ElementsOfPrinter[8])+2.5)*1.26*1.2*1.4*1.2,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],1) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title4="Druckerpatrone kompatibel f\xFCr "+ElementsOfPrinter[4]+" Magenta mit Chip\t" +str(round((float(ElementsOfPrinter[9])+2.5)*1.26*1.2*1.4*1.2,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[2],2) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title5="Druckerpatrone kompatibel f\xFCr "+ElementsOfPrinter[5]+" Gelb mit Chip\t" +str(round((float(ElementsOfPrinter[10])+2.5)*1.26*1.2*1.4*1.2,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],3) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title6="5 Druckerpatronen mit CHIP kompatibel f\xFCr "+ElementsOfPrinter[1]+" - "+ElementsOfPrinter[2]+" - " +ElementsOfPrinter[3]+" - "+ElementsOfPrinter[4] +" - "+ElementsOfPrinter[5]+" Multipack SET f\xFCr " +ElementsOfPrinter[0] +" mit Chip\t"  +str(FiveSetSalePrice)+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],5) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title7="XXL PREMIUM Druckerpatronen kompatibel f\xFCr "+ElementsOfPrinter[1]+", "+ElementsOfPrinter[2]+", "+ElementsOfPrinter[3]+", "+ElementsOfPrinter[4]+","+ElementsOfPrinter[5]+" SET "+ElementsOfPrinter[0]+"\t"  +str(round(FiveSetSalePrice,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],5) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title8="20 Patronen MIT CHIP kompatibel zu "+ ElementsOfPrinter[1]+" - "+ElementsOfPrinter[2]+" - " +ElementsOfPrinter[3]+" - "+ElementsOfPrinter[4]+" - "+ElementsOfPrinter[5]+"\t"  +str(round((FiveSETBuyingPrice*4+2.5)*1.26*1.2*1.4*1.2-4,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],45) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title9="10 Premium Druckerpatronen kompatibel f\xFCr "+ElementsOfPrinter[1]+" - "+ElementsOfPrinter[2]+" - " +ElementsOfPrinter[3]+" - "+ElementsOfPrinter[4]+" - "+ElementsOfPrinter[5]+" f\xFCr"+ElementsOfPrinter[0] +"2 SET\t"  +str(round((FiveSETBuyingPrice*2+2.5)*1.26*1.2*1.4*1.2-2,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],25) +self.create_KeywordsGE(ElementsOfPrinter[0]) +self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title10="XXL PREMIUM Druckerpatronen kompatibel f\xFCr "+ElementsOfPrinter[1]+ "f\xFCr "+ElementsOfPrinter[0]+" Photoblack\t"+str(round((float(ElementsOfPrinter[6])+2.5)*1.26*1.2*1.4*1.2,2))+"\t" +self.keyFeaturesGE(ElementsOfPrinter[0],11) +self.create_KeywordsGE(ElementsOfPrinter[0]) +self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title11="XXL PREMIUM Druckerpatronen kompatibel f\xFCr "+ElementsOfPrinter[2]+ "f\xFCr "+ElementsOfPrinter[0]+" Schwarz\t" +str(round((float(ElementsOfPrinter[7])+2.5)*1.26*1.2*1.4*1.2,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],0) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title12="XXL PREMIUM Druckerpatronen kompatibel f\xFCr "+ElementsOfPrinter[3]+ "f\xFCr "+ElementsOfPrinter[0]+" Cyan\t" +str(round((float(ElementsOfPrinter[8])+2.5)*1.26*1.2*1.4*1.2,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],1) +self.create_KeywordsGE(ElementsOfPrinter[0])+self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title13="XXL PREMIUM Druckerpatronen kompatibel f\xFCr "+ElementsOfPrinter[4]+ "f\xFCr "+ElementsOfPrinter[0]+" Magenta\t" +str(round((float(ElementsOfPrinter[9])+2.5)*1.26*1.2*1.4*1.2,2))+"\t"+self.keyFeaturesGE(ElementsOfPrinter[0],2) +self.create_KeywordsGE(ElementsOfPrinter[0]) +self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"
    title14="XXL PREMIUM Druckerpatronen kompatibel f\xFCr "+ElementsOfPrinter[5]+ "f\xFCr "+ElementsOfPrinter[0]+" Gelb\t"+str(round((float(ElementsOfPrinter[10])+2.5)*1.26*1.2*1.4*1.2,2))+"\t" +self.keyFeaturesGE(ElementsOfPrinter[0],3) +self.create_KeywordsGE(ElementsOfPrinter[0]) +self.ManProNum(ElementsOfPrinter[0])+descr+self.pictureLink(1)+"\n"

    self.excelWrtGE(title0,title1,title2,title3,title4,title5,title6,title7,title8,title9,title10,title11,title12,title13,title14)


def __init__(self):
    super(TemplateGenerator, self).__init__()
    # self.arg = arg
    now=dt.datetime.now()
    cur_time=time.mktime(now.timetuple())
    path='/Users/dfghj/Desktop/listings/THM/'+str(cur_time)
    print str(cur_time)
    os.mkdir(path)
    excelRead=open('/Users/dfghj/Desktop/listings/dataGA.txt','r')
    self.excelWriteGE=open(path +'/Them.GE.Sets.txt','w')
    header="Titles\t"+"Price equal to title:\t"+"Key Features1\t"+"Key Features2\t"+"Key Features3\t"+"Key Features4\t"+"Key Feature5\t"+"keyword1\t"+"keyword2\t"+"keyword3\t"+"keyword4\t"+"keyword5\t"+"Manufacturer Part Number\t"+"Description\t"+"Picture Link\n"
    self.excelWrtGE(header)
    data=np.genfromtxt(excelRead, delimiter="\n", dtype=None)   
    for line in data:
        titles=line.split("+")
        # print title, len(title)
        if len(titles)==11:
            self.GenerateGETemplatesFor11(titles)
        elif len(titles)==9:
            self.GenerateGETemplatesFor9(titles)
        elif len(titles)==7:
            self.GenerateGETemplatesFor7(titles)
        elif len(titles)==6:
            self.GenerateGETemplatesFor6(titles)
        else:
            print "Check your names in file once again!!!"
    excelRead.close()
    self.excelWriteGE.close()
    self.excelWriteSP.close()

 if __name__=='__main__':
     TemplateGenerator()   
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Hi, welcome to Code Review! Check python.org/dev/peps/pep-0008 for advice on how naming, formatting etc. is usually done with python. Probably a good place to start. \$\endgroup\$
    – Nihathrael
    Nov 27, 2014 at 11:41
  • \$\begingroup\$ You have a huge amount of code duplication - look into dictionaries and for loops. \$\endgroup\$
    – jonrsharpe
    Nov 27, 2014 at 11:52
  • \$\begingroup\$ I know how to use for function, but where do you want me to use it? \$\endgroup\$
    – ipsissimus
    Nov 27, 2014 at 15:25

1 Answer 1

2
\$\begingroup\$

I could make out some parts that could be improved.

  1. Good that you have used docstring for the class. You could do the same for the methods. In general, the code could have more comments where things are not obvious. Right now there are hardly any comments.
  2. Python programmers prefer functions_named_like_this() rather than functionsNamedLikeThis().
  3. __init__() should preferably be at the start of the class. Those who read the code will want to know how it is initialized before looking at other things.
  4. Is this really necessary: super(TemplateGenerator, self).__init__() ? I don't know the answer but I believe the base class __init__ method either does nothing useful or is invoked by default.
  5. A better way to open/close files is using the with statement. That way, you never need to worry about files you have forgotten to close.
  6. header="Titles\t"+"Price equal to title:\t"+"Key Features1\t"+"Key Features2\t"+"Key Features3\t"+"Key Features4\t"+"Key Feature5\t"+"keyword1\t"+"keyword2\t"+"keyword3\t"+"keyword4\t"+"keyword5\t"+"Manufacturer Part Number\t"+"Description\t"+"Picture Link\n": this is definitely not Pythonic. Use instead a list and then call '\t'.join() on that list.
  7. (x+2.5)*1.26*1.2*1.4*1.2: since this is used in many places, put it into a method.
  8. ElementsOfPrinter[]: this is really cryptic since it's hard to remember the semantics of each position. It would be better to extract them into named variables. Example: x,y,z = position, assuming position is a list of 3 items.
  9. list1=[list1.strip()for list1 in list1]: nothing wrong here but it is better for readability to use different variable names.
  10. test0, test1, ...: can be converted to a list instead. Also, Python allows you to have multiline strings. No need to type them out in long lines.
  11. if inkNumber==4: : convert to elif.
\$\endgroup\$
2
  • \$\begingroup\$ Thanks a lot, I really appreciate that, will try to bring some parts of code according to some rules, thanks again \$\endgroup\$
    – ipsissimus
    Nov 27, 2014 at 15:24
  • \$\begingroup\$ ElementsOfPrinter[] I do remember the order of all variables, but since data which is read from file can be different, I wanted to send all variables to their methods[GenerateGETemplatesFor6] (according to element amount) and then work with elements inside, isn't that bette? \$\endgroup\$
    – ipsissimus
    Nov 27, 2014 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.