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 8659837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:06:13+00:00 2026-06-12T16:06:13+00:00

Basically I have a file txt.txt item1, item2 In the code I want to

  • 0

Basically I have a file txt.txt

item1, item2

In the code I want to make an object

Object(item1, item2)

And I don’t know how to get item1 and item2 from the file the way I need. I tried to use a file = open("txt.txt").read() string and split it somehow, but failed. Tried putting it in a list and resulted in having [ and other stuff in item1 and item2 strings.

  • 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-12T16:06:14+00:00Added an answer on June 12, 2026 at 4:06 pm

    this answer creates a list of objects, the objects are made by iterating over each line in the file and splitting each line into both items, and then using them to construct the object.

    objects = [] #the object list
    with open("path/to/file") as reader: #opens the file
        for line in reader: #iterates the lines
            objects.append(Object(*line.strip().split(", "))) #appends the objects to the list
    

    a bit more detail about the last line, it can be opened up like this:

    parts = line.strip.split(", ") #each item in the line
    obj = Object(parts[0], parts[1]) #like doing Objects(item1, item2) from the line.
    objects.append(obj) #add the object to the list
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a revision.txt file in my SVN project. Basically I want that this
I basically have a program that filters records from one excel file to another
I have an external js file that is basically a js object. I am
So I have this code right, and it basically reads an XML file and
Basically, I have a file 'blah.txt'. That files gets parsed by a 'compiler' and
I have the following file dic.txt: {'a':0, 'b':0, 'c':0, 'd':0} I want to read
So basically, I have something like this - Input file with 2 integers. Code,
I have a config file that I want to basically edit the uncommented lines,
Do files opened like file(foo.txt) have any info about file modification time? Basically I
Basically I have converted a tab delimited txt file into a list containing 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.