Reading from another file- not a text one

Hi I was wounding if it is possible to read a file and load its information and how to go about doing it? I set up 2 files for testing, testhome and home. It gives me a error about AttributeError: World instance has no attribute ‘homeworld’.

def homeworld (self):
	f = open("networking/Users/Mradr.txt","r")
	lineList = f.readlines()
	print repr(lineList[2])
	print repr(lineList[3])
	self.speedread = int(lineList[4].strip())
	self.speed = self.speedread
	self.loaded = lineList[3].strip() = lineList[2].strip()
	#Load the first environment model town.egg 
	self.environ = loader.loadModel(
	#waterpiller = loader.loadModel("towns/water")
	#watershader = Shader.load("shaders/water.sha")
#(1,2,3) 1:leftright,2:forwardbackwords,3:updown

import direct.directbase.DirectStart  #Initialize Panda and create a window
from direct.task.Task import Task     #Task run
import random, sys, os, math          #libs for random, math
from direct.gui.OnscreenText import OnscreenText
import home
from pandac.PandaModules import Fog
from pandac.PandaModules import Shader
from pandac.PandaModules import Point3,Vec4
from pandac.PandaModules import NodePath
from pandac.PandaModules import CollisionTraverser,CollisionNode
from pandac.PandaModules import CollisionHandlerQueue,CollisionRay
from direct.showbase.DirectObject import DirectObject

class World(DirectObject):
    def __init__(self):
	#Some texts
	self.infoText = OnscreenText(text = 'Home Town', pos = (0, .9), scale = 0.07, mayChange=1, fg = (255, 255, 255, 1))



	self.keyMap = {"left":0, "right":0, "forward":0, "back":0, "warp":0}

        #Accept the control keys for movement
	self.accept("escape", sys.exit) 
	self.accept("arrow_left", self.setKey, ["left",1]) 
	self.accept("arrow_right", self.setKey, ["right",1])
	self.accept("arrow_up", self.setKey, ["forward",1])
	self.accept("arrow_down", self.setKey, ["back",1])
	self.accept("arrow_left-up", self.setKey, ["left",0]) 
	self.accept("arrow_right-up", self.setKey, ["right",0]) 
	self.accept("arrow_up-up", self.setKey, ["forward",0])
	self.accept("arrow_down-up", self.setKey, ["back",0])
	self.accept("k", self.setKey, ["warp",1])  	
	self.accept("k_up", self.setKey, ["warp",0])


	# Game state variables 
        self.prevtime = 0

	#disable camera

    #Records the state of the arrow keys 
    def setKey(self, key, value): 
        self.keyMap[key] = value

    def move(self, task):
        elapsed = task.time - self.prevtime

        camright =
        if (self.keyMap["left"]!=0): + elapsed*250)
        if (self.keyMap["right"]!=0): - elapsed*250)
        if (self.keyMap["forward"]!=0): + camright*(elapsed * self.speed))
        if (self.keyMap["back"]!=0):
   - camright*(elapsed * self.speed))
	if (self.keyMap["warp"]!=0):

        #store camrea pos
        startpos =

        self.prevtime = task.time 
        return Task.cont


I’m really not sure i understand your use case.
In Home file, you have created an unbound method (ie it’s is not attached to any class or class instance).

In TestHome, you don’t really import it.
Nowhere you tell python to attach the homeworld method to the World class or class instance…

So yes it’s normal that WOrld doesn’t know about your homeworld method…

Maybe trying to calll “home.homeworld” may work.
In this case , be sure to pass World as the first argument.

If your use case is to be able to add methods and properties to an existing class at load time or runtime, then i would recommend to google for python decorators, they are exactly this…

Some example from Allegra (a network lib using the decorator pattern everywhere)

def meter_recv (dispatcher, when):
        "decorate a stream transport with an input meter"
	dispatcher.ac_in_meter = 0
	dispatcher.ac_in_when = when
	metered_recv = dispatcher.recv
	def recv (buffer_size):
		data = metered_recv (buffer_size)
	        dispatcher.ac_in_meter += len (data)
		dispatcher.ac_in_when = time.time ()
	        return data
	dispatcher.recv = recv



Thanks i’ll take a look at it. This should help me keep things in line for my game so like one world can be loaded with its spical things and another can be loaded with its.