Python 语句迭代中未出现换行符

Python 语句迭代中未出现换行符,python,Python,follow从一个表单中获取多个文件输入,并以串行方法写入它们。当每个文件成功打印到页面时,它会打印,但每个循环之间不会出现换行?解决这个问题的最佳方法是什么?我以为print语句会默认添加换行符 #!/usr/bin/python import cgi, os import shutil import cgitb; cgitb.enable() # for troubleshooting form = cgi.FieldStorage() print """\ Content-Type:

follow从一个表单中获取多个文件输入,并以串行方法写入它们。当每个文件成功打印到页面时,它会打印,但每个循环之间不会出现换行?解决这个问题的最佳方法是什么?我以为
print
语句会默认添加换行符

#!/usr/bin/python
import cgi, os
import shutil
import cgitb; cgitb.enable()  # for troubleshooting

form = cgi.FieldStorage()

print """\
Content-Type: text/html\n
<html><body>
"""

if 'file' in form:
   filefield = form['file']
   if not isinstance(filefield, list):
      filefield = [filefield]

   for fileitem in filefield:
       if fileitem.filename:
          fn = os.path.basename(fileitem.filename)
          # save file
          with open('/var/www/rsreese.com/files/' + fn, 'wb') as f:
              shutil.copyfileobj(fileitem.file, f)
          # line breaks are not occuring between interations
          print 'File "' + fn + '" was uploaded successfully \n'
          message = 'All files uploaded'
else:
   message = 'No file was uploaded'

print """\
<p>%s</p>
</body></html>
""" % (message)
#/usr/bin/python
导入cgi,操作系统
进口舒蒂尔
进口cgib;cgib.enable()#用于故障排除
form=cgi.FieldStorage()
打印“”\
内容类型:text/html\n
"""
如果表格中有“文件”:
filefield=form['file']
如果不是isinstance(文件字段,列表):
filefield=[filefield]
对于filefield中的fileitem:
如果为fileitem.filename:
fn=os.path.basename(fileitem.filename)
#保存文件
以open('/var/www/rsreese.com/files/'+fn,'wb')作为f:
copyfileobj(fileitem.file,f)
#在交互之间不发生换行
已成功上载打印文件“+fn+”\n
消息='已上载的所有文件'
其他:
消息='未上载任何文件'
打印“”\
%

“”“%(消息)
Python可以很好地打印换行符,但浏览器不会显示这些换行符


使用

标记,或者将整个输出包装在
/
标记中。

Python可以很好地打印换行符,但浏览器不会显示这些换行符


使用

标记,或者将整个输出包装在
标记中。

在html中,您需要
换行。换行符只添加空格。在html中,换行符需要
。换行符只添加一个空格。