我的代码如下。
我收到unexpected indent
等错误
如何修复这些错误?
def RSD_Function(devNum,file,devProperties):
for i in range(0,devNum):
JsonDump={};
JsonDump["address"]=devProperties[i][14]
.
.
JsonDump["destination"]=devProperties[i][11]
.
.
ConfigDump[i]= JsonDump;
JsonDump ={}
print("sim.devices[",i,"].devTrafficChar.address = ",devProperties[i][14],file=file)
.
.
print("sim.devices[",i,"].trafficModel.destination = ",devProperties[i][11],file=file)
.
.
if __name__ == "__main__":
for num in NumberofDevice:
DirName = "Config_"+str(DeploymentChar[2])+"_"+str(num)
TotalSenDev = math.ceil(num*DeploymentChar[2])
TotalMainDev = math.ceil(num * ((1-DeploymentChar[2])/2))
TotalRecDev = math.ceil(num * ((1-DeploymentChar[2])/2))
devProperties = num * [None]
DT = ['BLE_DEV_CONNECTED_SUPPLY'] * int(num * DeploymentChar[0]+1) + ['BLE_DEV_BATTRERY_RECHARGEABLE'] * int(num * DeploymentChar[1]+1) +['BLE_DEV_BATTRERY_NON_RECHARGEABLE'] * int(num * DeploymentChar[2]+1)
random.shuffle(DT)
for dep in range(0,NumberofDeploy):
SensorLoc = numpy.random.uniform(0,30,size=(TotalSenDev,2))
MainLoc = numpy.random.uniform(0,30,size=(TotalMainDev,2))
RecLoc = numpy.random.uniform(0,30,size=(TotalRecDev,2))
print("////////////////////")
print(SensorLoc)
print("////////////////////")
print(MainLoc)
print("////////////////////")
print(RecLoc)
AddressAssignment = [i for i in range(num)]
random.shuffle(AddressAssignment)
for i in range(0,num):
if (i < TotalSenDev):
devProperties[i]=["Random",
SensorLoc[i][0], #X-Pos
SensorLoc[i][1], #Y-Pos
random.randint(1, rangeZ), #Z-Pos
random.randint(rangeTxRx, rangeTxRx), #RxTx-Range
ComputeClass[random.randint(0, 2)], #Compute Class
MemoryClass[random.randint(0, 2)], #Memory Class
'BLE_DEV_BATTRERY_NON_RECHARGEABLE', #Energy Source
random.randint(50, 99), #Battery Percentage
random.randint(50, 99), #Battery Size
ValidFreq[random.randint(0,3)], #Period of Packet Tx
AddressAssignment[TotalSenDev + i % (num - TotalSenDev)], #Peer Address
random.randint(1, num-1)*1000, #No of Packets to be Tx
7, #Delay for the first packet
AddressAssignment[i]];
devProperties[i][5] = ComputeClass[random.randint(0, 1)] if devProperties[i][7] == "BLE_DEV_BATTRERY_NON_RECHARGEABLE" else ComputeClass[random.randint(0, 2)]
devProperties[i][6] = MemoryClass[random.randint(0, 1)] if devProperties[i][7] == "BLE_DEV_BATTRERY_NON_RECHARGEABLE" else MemoryClass[random.randint(0, 2)]
devProperties[i][8] = 99 if devProperties[i][7] == "BLE_DEV_BATTRERY_NON_RECHARGEABLE" else random.randint(50, 99)
devProperties[i][9] = BatterySize[ 0 if devProperties[i][7] == "BLE_DEV_BATTRERY_NON_RECHARGEABLE" else 1]
devProperties[i][13] = 7
elif ........................
........................................................
for traf in range(0,NumberofTrafficModel):
if not os.path.exists(DirName):
os.makedirs(DirName)
AddressAssignment = [i for i in range(num)]
random.shuffle(AddressAssignment)
devProperties[i][11]=AddressAssignment[TotalSenDev + i % (num - TotalSenDev)]
此处我想仅针对每个流量模型的数量更改目的地
fileName =DirName+"\\"+str(num)+"_Deployment_"+str(dep)+"_Traf_"+str(traf)+".rsd"
file = open(fileName,'w+')
print("sim.depId = ",dep,file=file)
RSD_Function(num,file,devProperties)
fileJSON=open(DirName+"\\"+str(num)+"_Deployment_"+str(dep)+"_Traf_"+str(traf)+".json",'w+')
json.dump(ConfigDump,fileJSON,sort_keys=True, indent=4, separators=(',', ': '))
fileJSON.close()
file.close()