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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:06:05+00:00 2026-05-15T22:06:05+00:00

I’m currently trying to write a multiple-file Python (2.6.5) game using PyGame. The problem

  • 0

I’m currently trying to write a multiple-file Python (2.6.5) game using PyGame. The problem is that one of the files, “pyconsole.py”, needs to be able to call methods on instances of other objects imported by the primary file, “main.py”. The problem is that I have a list in the main file to hold instances of all of the game objects (player’s ship, enemy ships, stations, etc.), yet I can’t seem to be able to call methods from that list within “pyconsole.py” despite the fact that I’m doing a from pyconsole import * in “main.py” before the main loop starts. Is this simply not possible, and should I instead use M4 to combine every file into 1 single file and then bytecode-compile and test/distribute that?

Example:

bash$ cat test.py
#!/usr/bin/python

import math, distancefrom00
foo = 5

class BarClass:
    def __init__(self):
        self.baz = 10
    def get(self):
        print "The BAZ is ", self.baz
    def switch(self)
        self.baz = 15
        self.get()

bar = BarClass()

def main():
    bar.switch()
    print distancefrom00.calculate([2, 4])

if __name__ == '__main__': main()

bash$ cat distancefrom00.py
#!/usr/bin/python

import math
import test

def calculate(otherpoint):
    return str(math.hypot(otherpoint[0], otherpoint[1]))+" (foo = "+str(test.foo)+"; "+test.bar.get()+")"

bash$ python test.py
The BAZ is  15
The BAZ is  10
Traceback (most recent call last):
  File "test.py", line 24, in <module>
    if __name__ == '__main__': main()
  File "test.py", line 22, in main
    print distancefrom00.calculate([2, 4])
  File "/home/archie/Development/Python/Import Test/distancefrom00.py", line 8, in calculate
    return str(math.hypot(otherpoint[0], otherpoint[1]))+" (foo = "+str(test.foo)+"; "+test.bar.get()+")"
TypeError: cannot concatenate 'str' and 'NoneType' objects

If my somewhat limited understanding of Python names, classes, and all that stuff is correct here, the NoneType means that the name test.bar.get() – and thus, test.bar – is not assigned to anything.

  • 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-15T22:06:06+00:00Added an answer on May 15, 2026 at 10:06 pm

    The problem is that one of the files,
    “pyconsole.py”, needs to be able to
    call methods on instances of other
    objects imported by the primary file,
    “main.py”.

    This just sounds like the dependencies are wrong. Generally nothing should be calling ‘backwards’ up to the main file. That main.py should be the glue that holds everything else together, and nothing should depend on it. Technically the dependencies should form a directed acyclic graph. As soon as you find a cycle in your dependency graph, move out the common aspects into a new file to break the cycle.

    So, move the things in ‘main.py’ that are used by ‘pyconsole.py’ out into a new file. Then have ‘main.py’ and ‘pyconsole.py’ import that new file.

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

Sidebar

Ask A Question

Stats

  • Questions 460k
  • Answers 460k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes - different operators with the same precedence are left-associative;… May 15, 2026 at 11:52 pm
  • Editorial Team
    Editorial Team added an answer Aggregated buckets. We pick a bucket size that's comfortably less… May 15, 2026 at 11:52 pm
  • Editorial Team
    Editorial Team added an answer A RegularExpressionValidator doesnt validate empty text by design. You need… May 15, 2026 at 11:52 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.