Re: Python, passing objects?

2019-08-25 Thread AudioGames . net Forum — Developers room : nyanchan via Audiogames-reflector


  


Re: Python, passing objects?

Primitives are value-passed and objects are reference-passed. You need to explicitly call copy function in order to duplicate an object. So, as for your question, no.

URL: https://forum.audiogames.net/post/457597/#p457597




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Python, passing objects?

2019-08-24 Thread AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector


  


Re: Python, passing objects?

That depends on if your passing a reference to an existing class instance, which would have little or no overhead because its no different than passing an array, dictionary, or other variable. If your creating and passing classes every cycle, it depends on the classes size and complexity. Generally its not much of an issue, but thats what benchmarking is for.

URL: https://forum.audiogames.net/post/457533/#p457533




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Python, passing objects?

2019-08-24 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: Python, passing objects?

I am not sure you understand my question. What issues, if any, will I have if I start passing around classes to the functions at a constant rate.

URL: https://forum.audiogames.net/post/457526/#p457526




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Python, passing objects?

2019-08-24 Thread AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector


  


Re: Python, passing objects?

The given example only covers initialization, which only happens once when the object is created. In the case of an update loop that requires an object every loop, it depends on how you wetup the update function to handle the data, or lack thereof, thats sent to it. For example:class example(object):
 def update(self,data):
 if data != None:
 print(data)In this example, you can pass update either a data object or None, but you always have to pass it something. But another way to handle it is to set the local variables default like so:class example(object):
 def update(self,data=""
 if data != None:
 print(data)What this does is make it so if you pass example a variable, such as "example(thing)", then "thing" will overwrite the local data variable in update so it becomes "thing". now if you don't pass it anything, such as "example()", then the local data variable in update will default to None automatically.

URL: https://forum.audiogames.net/post/457520/#p457520




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Python, passing objects?

2019-08-24 Thread AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector


  


Re: Python, passing objects?

The given example only covers initialization, which only happens once when the object is created. In the case of an update loop that requires an object every loop, it depends on how you setup the update function to handle the data, or lack thereof, thats sent to it. For example:class example(object):
 def update(self,data):
 if data != None:
 print(data)In this example, you can pass update either a data object or None, but you always have to pass it something. But another way to handle it is to set the local variables default like so:class example(object):
 def update(self,data=""
 if data != None:
 print(data)What this does is make it so if you pass example a variable, such as "example(thing)", then "thing" will overwrite the local data variable in update so it becomes "thing". Now if you don't pass it anything, such as "example()", then the local data variable in update will default to None automatically.

URL: https://forum.audiogames.net/post/457520/#p457520




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Python, passing objects?

2019-08-24 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Python, passing objects?

So, I have just discovered a wonderful feature of passing objects to methods in python. This would potentially save me some import statements. Trouble is, I don't really know what happens under the hood and how it all impacts performance.consider this:#we'll call this module cls
class Cls:
 def __init__(self):
  self.x = 2
#this is the module that would use cls in it's constructor
#I don't want to inherit, since the two modules may not be alike
#We'll call this cls_user
class Cls_user:
 def __init__(self, creator):
  self.creation = creator()
#This is our main module
import cls, cls_user
d = cls_user.Cls_user(cls.Cls)
#Other stuff goes hereWhat impact, if any, would this code have if, say, we require an object to be given for every update method in our loop. Why should I avoid using this and just stick with the good old import statement.

URL: https://forum.audiogames.net/post/457510/#p457510




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector