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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:54:19+00:00 2026-06-14T11:54:19+00:00

I need to extract data from external source. I build a base clas with

  • 0

I need to extract data from external source. I build a base clas with some structure. I need objects with type of myBase class but with a name which automatically describes how many times I iterate over the source. I build a class which stores this number and with a call method which returns the object I need. I can’t find a way to have a string as the name for the object but automatically differ every time I build new object.
I simplified the code for this example:

class myBase:
    def __init__(self):
        iteratedValue = None

class myIterator:
    def __init__(self):
        self.k = 0
    def __call__(self, s):
        self.k += 1
        self.name = 'myData' + str(self.k)
        # create an object named myData1, myData2 ...
        self.name = myBase() 
        self.name.iteratedValue = s 
        print '%s name is %s for k = %i' % (self.name, self.name.iteratedValue, self.k)

        # return object named myData1 type of myBase
        return self.name

def DataExtraction():
    # function to extract data form external source
    data = myIterator()
    data('Alice') 
    data('Ben') 

DataExtraction()

My output is:

<__main__.myBase instance at 0x7f261b6dc6c8> name is Alice for k = 1
<__main__.myBase instance at 0x7f261b6dc6c8> name is Ben for k = 2

I need to return an object with a specific name and I expect an output:

myData1 name is Alice for k = 1
myData2 name is Ben for k = 2

The original problem is much more complicated. I have external data and every time they come I want to extract some values from this data. Every time I am doing this I need an object to work with it but I need this object with different names because on the end I store them in dict for another methods. In other words I work with data and store my results in the object myData1 when the original data change I work with it again and store the results in myData2 etc. After all I need all myData objects and do statistics on them to see how the change. I do not have access to original data any more. I need automatic name convention for myData and the best if it will express iterator.

How can I have a string in place of self.name as the name for an object?

  • 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-14T11:54:21+00:00Added an answer on June 14, 2026 at 11:54 am

    You’re already doing it with self.name = 'myData' + str(self.k). The problem is that you immediately overwrite it with self.name = myBase(). I’m not sure what you’re trying to do with that myBase(), but you probably want to separate it from the name. self.name can be either a string or a myBase object, but it can’t be both.

    Perhaps you can do:

        self.name = 'myData' + str(self.k)
        self.base= myBase() 
        self.base.iteratedValue = s 
        print '%s name is %s for k = %i' % (self.name, self.baseiteratedValue, self.k)
    

    This way you can have both the name and the “base”, as separate attributes self.name and self.base.

    Alternatively, you can give the myBase class a __str__ method. This will affect what shows up when you use print on a myBase object. However, to do that you’ll have to pass in the desired name when you instantiate myBase, something like:

    class myBase(object):
        def __init__(self, name, iteratedValue):
            self.name = name
            iteratedValue = iteratedValue
        def __str__(self):
            return self.name
    
    class myIterator(object):
        def __init__(self):
            self.k = 0
        def __call__(self, s):
            self.k += 1
            name = 'myData' + str(self.k)
            self.name = myBase(name, s) 
            print '%s name is %s for k = %i' % (self.name, self.name.iteratedValue, self.k)
    
            # return object named myData1 type of myBase
            return self.name
    

    I’m not sure which of these ways (or perhaps some other way) is what you’re looking for. What’s puzzling is that you are making the “name” of the object be a myBase instance. I’m not sure what you’re intending the “name” of your object to represent, but I wouldn’t usually expect an object’s name to be some other object.

    Incidentally, it looks like you’re using Python 2, in which case you should define your class with class someClass(object). Including the object makes your classes new-style classes, which is basically what you always want.

    Edit: If what you’re trying to do is actually create a variable called myData1 based on the string, so you can do myData('Alice') and then somehow magically have the variable myData1 refer to that object, the answer is “Don’t do that.” If you want to create a bunch of objects and access them in a structured way by numbers or other labels, use a list or a dictionary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to extract data from a structure and put it into a list,
I need to extract data from a source that presents it in one of
I need to extract some data from a CSV file. The CSV is a
I need to extract data from a DB2 table, run some processing on each
i need to extract data from this array of objects { data: [ {
I have two databases with equivalent structure and I need to extract data from
I need to extract some static data from PHP files in ruby. I've looked
I need to extract some data from a 1 GB XML file into <key,value>
I've got the following three strings that I need to extract some data from
I need to extract data from HTML-files. The files in question are, most likely,

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.