This creates a dictionary from two lists, and redirects the input output stream to a file.
Write a file with in python.
Date Created:Friday December 29th, 2006 03:41 AM
Date Modified:Wednesday July 30th, 2008 11:49 PM
import os
import sys
newfile= raw_input('Enter File Name:') + '.txt'
names = []
ideas = []
content = {}
while 1:
name = raw_input('Enter Name:')
if name == 'exit': break
if name in names:
print " Already a Name !"
continue
idea = raw_input('Enter Idea:')
print 'Hello', name, "\n", idea
names.append(name)
ideas.append(idea)
for (n,i) in zip(names,ideas):
content[n]=i
print os.path.abspath(newfile)
temp = sys.stdout
sys.stdout = open(newfile,'a')
print content
sys.stdout = temp
Downloads:
Download: redirect.py 654 B
Please login or Click Here to register for downloads
Redirect input output stream by Dan Lynch
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Based on a work at www.3daet.com
Permissions beyond the scope of this license may be available at http://www.3daet.com
