Fixed some bugs in write_tmpfile.
This commit is contained in:
parent
6cd76a205d
commit
44553732ca
|
@ -1,3 +1,6 @@
|
||||||
|
import os
|
||||||
|
import tempfile
|
||||||
|
|
||||||
def make_result_dict(cursor, row):
|
def make_result_dict(cursor, row):
|
||||||
d = {}
|
d = {}
|
||||||
for i in xrange(len(row)):
|
for i in xrange(len(row)):
|
||||||
|
@ -82,9 +85,9 @@ def run_editor(filename):
|
||||||
else:
|
else:
|
||||||
exit("Error: %s: File does not exist!" % filename)
|
exit("Error: %s: File does not exist!" % filename)
|
||||||
|
|
||||||
def write_tmpfile(pfix='', content=''):
|
def write_tmpfile(pfix, content, encoding='utf8'):
|
||||||
file = tempfile.NamedTemporaryFile(prefix=pfix+'-', dir='/tmp', delete=False)
|
file = tempfile.NamedTemporaryFile(prefix=pfix+'-', dir='/tmp', delete=False)
|
||||||
file.write(content.encode(file_encoding))
|
file.write(content.encode(encoding))
|
||||||
name = file.name
|
name = file.name
|
||||||
file.close()
|
file.close()
|
||||||
return name
|
return name
|
||||||
|
|
Reference in New Issue