Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9006123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:19:44+00:00 2026-06-16T01:19:44+00:00

Sorry if the title is confusing. What I want to do is have a

  • 0

Sorry if the title is confusing. What I want to do is have a text file (keywords.txt) read and then split into a list. So basically lets say the file contained “iphone, keys, wallet, pen, folder”, I would want the list to be [iphone, keys, wallet, pen, folder].

Is there any way to set one variable to work for each element. Say the variable is query. Is there anyway for query to be each of the elements so it can go through the program and work for each element. Below is the code I have, it obviously doesnt work but that is what I want to happen if possible.

The reason I want to do it for each is because eventually the script will write a new text file for each of the elements and name it based on what the element is and the only way I know how to do that is by having one variable.

data = [line.strip() for line in open('keywords.txt', 'r')]

try:
    query = sys.argv[1]
except IndexError:
    query = item in data 

Here is the rest of the code that I will be performing. It will take what is in the list that is created and create a new textfile and a csv file.

newFile = open("%s.txt" %query, 'w').write(txt.encode('utf8'))

with open("%s.txt" %query, 'rb') as input_file:
    reader = csv.reader(input_file, delimiter='\n', quoting = csv.QUOTE_NONE)

    with open("%s.csv" %query, 'wb') as output_file:
        writer = csv.writer(output_file)

        for row in reader:
            writer.writerow(row)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:19:45+00:00Added an answer on June 16, 2026 at 1:19 am

    Turn the query value taken from the command line into a list instead, then loop over the query list:

    try:
        query = [sys.argv[1]]
    except IndexError:
        query = data
    
    for q in query:
        # do something with q
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if the title is confusing. I can import a CSV file into R,
Sorry for the confusing title, but it basically says it all. Here's the structures
Sorry the title may not be very clear. Basically I have a wrapper for
I am sorry for the confusing title, I'm not sure how to put into
Sorry if the title is confusing. Basically what I am trying to do is
Sorry for the title may seem confusing. i have 2 element. with no relation
Sorry if the title is confusing. I have several string expressions in an array
Hello everybody and sorry for the rather confusing question-title. I have a Hibernate Class
Sorry if the title is confusing. I have set up a virtual host on
sorry, I realize my title is confusing. Please let me explain. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.