与缩进错误混淆

时间:2014-03-17 13:05:21

标签: python error-reporting

你好我再次尝试使用这段代码,我正在写作。我得到了其他一切,我以前遇到过问题,但现在当我运行代码时,我得到一个缩进错误。附上我的代码和错误的图像,不断弹出任何帮助,以找出这个问题将不胜感激。

import csv, datetime

franchiseList = {}

with open('Franchise_Name_Scrub_List.csv', 'r') as ff:
fcf = csv.DictReader(ff)
for frow in fcf:
    franchiseList[frow['Misc Franchise Name']] = frow

newrow={'Last Sale Date': '', 'Last Sale Amount': '', 'First Name': '', 'Last Name': '', 'Email Address': '', 'Franchise': '', 'State': '', 'Postal/Zip Code': '', 'Last Web Order ID': '', 'Date Added': '', 'Email Source':'', 'osg_web_dir': ''}
new_field_names = newrow.keys()

with open('SOR935csv_(1).csv', 'r') as f1, open('FACTS_bronto_import_add.csv', 'wb') as f2:
cf1 = csv.DictReader(f1, fieldnames=('CustNo1', 'CustNo2', 'LastOrderDate', 'LastOrderAmount', 'FirstName', 'LastName', 'UserNo', 'EmailAddress', 'Franchise', 'PrevOrderDate', 'PrevOrderAmount', 'State', 'ZIP', 'Amt1', 'Amt2', 'Amt3', 'SalesPerson', 'WEBID'))
cf2 = csv.DictWriter(f2, new_field_names)
cf2.writeheader()
for row in cf1:
    nr = newrow
    nr['Last Sale Date'] = row['LastOrderDate'].strip()
    nr['Last Sale Amount'] = row['LastOrderAmount'].strip()
    nr['First Name'] = row['FirstName'].strip()
    nr['Last Name'] = row['LastName'].strip()
    nr['Email Address'] = row['EmailAddress'].strip().split(',',1)[0]

    fr_name = row['Franchise'].strip()
    if fr_name in franchiseList:
    nr['Franchise'] = franchiseList[fr_name]['FRANCHISE Name'].strip()
nr['Franchise'] = row['Franchise'].strip()
nr['State'] = row['State'].strip()
nr['Postal/Zip Code'] = row['ZIP'].strip()
nr['Last Web Order ID'] = row['WEBID'].strip()
nr['Date Added'] = datetime.date.today().strftime('%m/%d/%Y')
nr['osg_web_dir'] = row['SalesPerson'].strip()
nr['Email Source'] = 'FACTSauto'
print nr
cf2.writerow(nr)

import csv

newrow={'Last Sale Date': '', 'Last Sale Amount': '', 'First Name': '', 'Last Name': '', 'Email Address': '', 'Franchise': '', 'State': '', 'Postal/Zip Code': '', 'Last Web Order ID': '',  'osg_web_dir': ''}
new_field_names = newrow.keys()

with open('SOR935csv_(1).csv', 'r') as f3, open('FACTS_bronto_import_update.csv', 'wb') as f4:
cf3 = csv.DictReader(f3, fieldnames=('CustNo1', 'CustNo2', 'LastOrderDate', 'LastOrderAmount', 'FirstName', 'LastName', 'UserNo', 'EmailAddress', 'Franchise', 'PrevOrderDate', 'PrevOrderAmount', 'State', 'ZIP', 'Amt1', 'Amt2', 'Amt3', 'SalesPerson', 'WEBID'))
cf4 = csv.DictWriter(f4, new_field_names)
cf4.writeheader()
for row in cf3:
    nr = newrow
    nr['Last Sale Date'] = row['LastOrderDate'].strip()
    nr['Last Sale Amount'] = row['LastOrderAmount'].strip()
    nr['First Name'] = row['FirstName'].strip()
    nr['Last Name'] = row['LastName'].strip()
    nr['Email Address'] = row['EmailAddress'].strip().split(',',1)[0]
    nr['Franchise'] = row['Franchise'].strip()
    nr['State'] = row['State'].strip()
    nr['Postal/Zip Code'] = row['ZIP'].strip()
    nr['Last Web Order ID'] = row['WEBID'].strip()
    nr['osg_web_dir'] = row['SalesPerson'].strip()
    print nr
    cf4.writerow(nr)

enter image description here

修订

在几条线路上都有一个缩进问题,多亏了这里的某些人,这是一个简单的解决方案,我很复杂。

1 个答案:

答案 0 :(得分:1)

使用以下命令运行脚本:

print -tt scriptname.py

并修复报告的所有错误。

然后将编辑器配置为仅使用 空格进行缩进。