python 2.6.6 "phantom" whitespaces -


basically, i'm opening files , removing whitespaces every line in file. code snippet:

for filepath in filelist:         if filepath.endswith(".shader"):             shaderfile = open(filepath,"r").readlines()             line in shaderfile:                 line = left(line, line.find("\n"))+"\n"                 line = line.replace(" ","")                 if line.find("common/")>-1:                     print(line.replace("\n","\\n")) 

as per request, removed less important code.

there 2 weird things going on:

1) lines end "\n\n"

2) i'm getting output:

textures/common/lightgrid\n textures/common/mirror1  \n textures/common/mirror2  \n maptextures/common/invisible.tga  \n textures/common/watercaulk  \n textures/common/clipnokick  \n textures/common/invisible\n 

3) when pasted output here, looked like:

textures/common/lightgrid\n textures/common/mirror1\n textures/common/mirror2\n maptextures/common/invisible.tga\n textures/common/watercaulk\n textures/common/clipnokick\n textures/common/invisible\n 

i have no idea what's going on. bug print()? sorry bad formatting, it's not fault, it's stackoverflow's.

from stringio import stringio  = stringio("""textures/common/lightgrid textures/common/mirror1  textures/common/mirror2  maptextures/common/invisible.tga  textures/common/watercaulk  textures/common/clipnokick  textures/common/invisible""")   def clean_lines(fileobj):     line in fileobj:         if line:             line = line.strip()             if line:                 yield "%s\n" % line   print [line line in clean_lines(a)] 

i used stringio emulate file replace whatever fileobj is.


Comments