python运行结果不是想要的

我做了一个.py文件,代码如下

from mod import*
import os,shutil
yinhao=['"',"'"]
def main(self,line,file):
    if os.path.exists('./var'):
        pass
    else:
        os.makedirs('./var')
    if ':' in self:
        name,code=self.split(':',1)
        if name == '打印' or '输出':
            if '+' in code:
                str1=''
                for i in code.split('+'):
                    global yinhao
                    has_str=False
                    if i[0] == '(' and i[-1] == ')':
                        if i[1] != i[-2] and i[1] in yinhao and i[-2] in yinhao:
                            errors.main('001',line,'语法错误:引号样式不同。',file)
                        elif i[1] == i[-2] and i[1] in yinhao and i[-2] in yinhao:
                            str1+=i[2:]
                            str1=list(str1)
                            del str1[-1]
                            del str1[-2]
                            str1=''.join(str1)
                            has_str=True
                        else:
                            try:
                                a=i[1:]
                                a=list(a)
                                del a[-1]
                                a=''.join(a)
                                float(a)
                            except:
                                errors.main('001',line,'语法错误:字符串请加上引号。',file)
                            else:
                                if has_str == True:
                                    errors.main('003',line,'类型错误:打印内容类型混合。',file)
                                else:
                                    str1+=float(a)
                    elif i[0] == '[' and i[-1] == ']':
                        if ',' in i:
                            a=i[1:]
                            a=list(a)
                            del a[-1]
                            a=''.join(a)
                            a=','.split(a)
                            for j in a:
                                try:
                                    f=open('./var/'+file+'//'+j+'.txt','r',encoding='UTF-8')
                                except:
                                    f.close()
                                    errors.main('002',line,'数值错误:没有定义该变量。',file)
                                else:
                                    str1+=f.read()
                                    f.close()
                print(str1)



    if ':' not in self and '=' in self:
        var,value=self.split('=',1)
        os.makedirs('./var/'+file,exist_ok=True)
        f=open('./var/'+file+'//'+var+'.txt','w',encoding='UTF-8')
        f.write(value)
    elif self == '@_end_':
        shutil.rmtree('./var/'+file)

用别的文件调用后,输入输出结果如下:

img

可是这并不是我想要的结果,感觉莫名其妙,找了半天也不知道哪里错了,第一次输入我想让他打印字符串as和a(放在同一行),但他却给了我一个a和两个引号,请问这怎么才能解决?

已解决,原因是23,24两行,既然前面已经删除str1的索引值-1的字符,则原来索引值为-2的字符就变成了-1,所以这两行可以改成:

del str1[-1]
del str1[-1]

或:

del str1[-2:]

这是可能因为您在输入字符串时,没有将字符串放在引号中,所以程序将字符串中的每个字符都当作单独的变量来处理。要解决这个问题,您需要将字符串放在引号中,例如:"as"+"a",这样程序就能正确的处理字符串了。