python - If, else statement output -


for in range(len(npa)):     filename = '/lca_rcdist.php?npa1=503&nxx1=745&npa2=503&nxx2=' + npa[i]     reply = urllib.request.urlopen(servername + filename)      if reply.status != 200:         print('error sending request', reply.status, reply.reason)     else:         data = reply.readlines()         reply.close()         line in data[:showlines]:             cline = line.decode('utf-8')             if '"ofrom">n<' in cline:                 print('nxx ,' + npa[i])  

the following output nxx,269nxx,298nxx,300nxx , on, there way add if , else statement output not contain comma , nxx in front of first entry? example: 269nxx, 298nxx? i'm new , still strugling if , else statements on scripts these. ifo on how change output using if, else statemnet appriciated.

create list , use str.join():

result = [] # new in range(len(npa)):     ... # blah, blah, same example, until             if '"ofrom">n<' in cline:                 result.append(npa[i])  # changed print (','.join(result))  #new 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -