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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:57:11+00:00 2026-05-25T05:57:11+00:00

I have two files, both are in the same project (part of a web

  • 0

I have two files, both are in the same project (part of a web scraping framework). File1 processes items that are generated by File2. In File2 I have a function that prints out some basic stats about the processes (counts of how many items have been generated, etc). I have counts in File1 that I would like to print with the stats from File1 but am unsure of how to do that. Take a look at the example code.

FILE 1:

class Class1(object):
    def __init__(self):
        self.stats = counter("name") #This is the instance that I'd like to use in File2
        self.stats.count = 10

class counter:
    def __init__(self, name):
        self.name = name
        self.count = 0
    def __string__(self):
        message = self.name + self.count
        return message

FILE 2: (this is what I’d like to do)

from project import file1 # this import returns no error

def stats():
    print file1.Class1.stats # This is where I'm trying to get the instance created in Class1 of File2.
    #print file1.Class1.stats.count # Furthermore, it would be nice if this worked too.

ERROR:

exceptions.AttributeError: type object 'Class1' has no attribute 'stats'

I know that both files are running, thus so does the ‘stats’ instance of the ‘counter’ class, because of other methods being printed out when running the project (this is just a stripped down example. What am I doing wrong here? Is this possible to do?

  • 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-05-25T05:57:11+00:00Added an answer on May 25, 2026 at 5:57 am

    This is not working because you never instantiate Class1.

    __init__ is called when the Class1 is instantiated so Class1.stats is set.

    You have 2 options here.

    1. instantiate Class1 in file 2 somehow.
    2. declare a static method in Class1 that returns the count property.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two large framework libraries, whose header files are included in my project.
I have two frameworks in my Xcode project that both define a class with
I've got two git project repos that have two or three files in common.
I have two DLL files that have the same namespace but they have different
I have two files which both contain a list of words. Is there an
I have two files, A is a subset of B. Both A and B
I have two string variables which are both file paths. The code that worked
I have a project with two Info.plist files (one for each target). In the
I have a project with two targets, let's say appA and appB . Both
I work with two branches of the same project. Both of them were created

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.