The 'input_sheet.py' module placed in site-packages:
def write_to_file(file_name, content):
file = open(file_name, 'w')
file.write(content)
file.close()
def main():
file_name = 'output.txt'
content = 'This is the output text.'
return file_name, content
if __name__ == '__main__':
file_name, content = main()
write_to_file(file_name, content)
The code for default.py
def import_module_test():
# import module
import input_sheet
# execute function main() to get output
file_name, content = input_sheet.main()
# call download function
do_download(file_name, content)
# testing output from the imported module
##return dict(file_name=file_name, content=content)
def do_download(filename, content):
# import module and initialize handle content
import cStringIO
download_content = cStringIO.StringIO()
# Trial text content for download
download_content.write('Test content for download.')
# The actual content for download
##download_content.write(content)
# set response headers and initiate download dialog box
response.headers['Content-Disposition'] = 'attachment; filename=' + filename
response.headers['Content-Type'] = 'text/csv'
return download_content.getvalue()
Note:
The content returned by the imported module shows up fine.
The funny thing is the filename of the download file is rendered correctly.
Why isn't the content?
Even if I hardcode the value of the download_content, the output.txt file
shows 'None'