我正在用Python 2.7编写一个简单的程序,使用pycURL库将文件内容提交给pastebin。 这里的程序代码:关于Python中文件格式的新手问题
#!/usr/bin/env python2
import pycurl, os
def send(file):
print "Sending file to pastebin...."
curl = pycurl.Curl()
curl.setopt(pycurl.URL, "http://pastebin.com/api_public.php")
curl.setopt(pycurl.POST, True)
curl.setopt(pycurl.POSTFIELDS, "paste_code=%s" % file)
curl.setopt(pycurl.NOPROGRESS, True)
curl.perform()
def main():
content = raw_input("Provide the FULL path to the file: ")
open = file(content, 'r')
send(open.readlines())
return 0
main()
输出引擎收录看起来像标准的Python列表:['string\n', 'line of text\n', ...]
等
有什么办法,所以它看起来更好,它实际上是人类可读的,我可以格式化?另外,如果有人能告诉我如何在POSTFIELDS
中使用多个数据输入,我会非常高兴。 Pastebin API使用paste_code
作为其主要数据输入,但它可以使用诸如paste_name
之类的可选事项来设置上传的名称或paste_private
将其设置为私有。
我建议让`POSTFIELDS`问题作为一个单独的问题。 – marcog 2011-01-08 13:35:12