# logger.py
def log(*args, **kwargs):
from .util import dict_format
if kwargs:
print("LOG: %s, %s" % (str(args), dict_format(kwargs))
else:
print("LOG: %s" % str(args))
#—————–
# util.py
from logger import log
def my_func1(bla):
log("calling my_func1")
def my_func2(bla, **kwargs):
log("calling my_func1", **kwargs)
def dict_format(d):
# now here, we can't call "log" with kwargs or we get an infinite loop
return str(d)
from miniboa import TelnetClient
from miniboa.telnet import TelnetClient
If you listen in on the ichat channel on IMC, you may know that I've been working on an IMC client with Python in addition to a MUD built in Python using the Miniboa telnet library. Progress has been good on both of these projects, and as of tonight I've integrated the IMC client into my MUD and ran some successful tests!
After all of this I've come across a few realizations. First, I've been teaching myself the Python language using these as my pet projects to try different things out. The biggest problem I've encountered is circular import problems, which is symptomatic of a bad design. Unfortunately coming from a C# background where everything kind of "plugged together" through meta-data I was not prepared for tackling module design properly. After a bit of hacking here and there to get around these issues I believe it is time to redesign my codebase. My question is this: Does anyone know of good on-line material covering idioms and/or best practices in regards to the Python programming language? Especially in regards to organizing modules and bigger multi-file projects.
Thanks!