Taking input from user and then naming a .txt and a .csv file based on what they say

csv, file, python

Solution

almost there, but your statement should be

`with open("%s.csv" %query, 'rb') as input_file`

and

`with open("%s.txt" %query, 'wb') as output_file`

`query` just holds the value i.e. filename, you need to add it's extensions before opening the file

Problem

So I am trying to make something where a user is prompted to enter a keyword and then my program will take that input and return tweets including that using twitter api. I also want it to be able to name a file after what they input. Lets say they enter "iphone", I would like it to make a iphone.txt and iphone.csv file. Here is what I have so far but it doesn't seem to be working. By the way, the 'newFile' line should be a .txt file and the 'with open(query, 'rb') as input_file' should also be a .txt. The other is a .csv ``` try: query = sys.argv[1] except IndexError: query = raw_input("Choose a keyword to find the last 100 tweets about: ") newFile = open(query, 'w').write(txt.encode('utf8')) with open(query, 'rb') as input_file: reader = csv.reader(input_file, delimiter='\n', quoting = csv.QUOTE_NONE) with open(query, 'wb') as output_file: writer = csv.writer(output_file) for row in reader: writer.writerow(row) ```

Original source