|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#16
|
||||
|
||||
|
Strike, quick and dirty nothing more
Grim |
|
#17
|
|||
|
|||
|
I wouldn't take offense to that, Grim
. I'm quit new to Python and I greatly appreciate any help. Thanks for taking the time to restructure my bot, I think it's alot better now . |
|
#18
|
|||
|
|||
|
Quote:
Good But only as long as it stays as "nothing more". I'm not afraid to lay the verbal smack down on using it for anything else. ![]() |
|
#19
|
|||
|
|||
|
One more quick question
: As you can see, I pass mapCommand a bunch of arguments. What I was wondering is if it's better to use 'self.' instead of passing arguments, in this context. I pass arguments to authManagement and chanManagement too, so they would use 'self.' too.Make that two : Grim, you mentioned a 'send' function to keep the methods from working with the underlying socket, but would you know a way to implement this considering I have quit a range of different calls to sock.send(). (i.e. MODE, KICK, BAN, NICK, and also a varying number of arguments.)Last edited by XxChris : February 9th, 2004 at 04:56 PM. |
|
#20
|
||||
|
||||
|
Thats a good one.
![]() In my view you got it right the first time: 1. You are encapsulating and keeping clean interfaces. 2. It's easier to document. (Try to describe the other way!) 3. In 6 months time you don't have remember how the self.xxx got there. 4. You're putting them in different modules, it will save file hopping. ![]() |
|
#21
|
||||
|
||||
|
Really you only have one call:
self.send(astring) and it is astring that has different contents dependent on the protocol requirements. So all I propose is you replace self.sock.send with self.send where: Code:
#in socketDriver
def send(self,data):
self.socket.send(data)
Not a big improvement in code, just a restructure that does isolation. It is allmost inevitable that the closer the code gets to the real world the less ideal it's structure becomes - it has to deal with human decisions that making tidy code difficult! However, in parseCommand you might consider adding a new function like: Code:
def transmitCommand(self,command,arg1,arg2,arg3='',arg4=''):
if command == 'PRIMSG':
self.send('%s %s : %s\n\r' % (command,arg1l, arg))
elif command in['MODE', 'KICK']:
self.sock.send('%s %s %s %s\n\r' % (command,arg1, arg2,arg3))
elif command =='QUIT':
self.send('QUIT : %s\n\r'% (command,arg1))
etc...
Then all self.sock.send(...) would be replaced with self.transmitCommand('COMMAND',arg1,arg2,arg3,ar4) But that is just extra code that puts off dealing with the protocol. The choice is yours Grim |
|
#22
|
|||
|
|||
|
Thanks alot Grim! ;D
|
|
#23
|
|||
|
|||
|
I'm back
![]() The OOP structure is all sorted now and everything is split into modules. It all seems to work, but I've implemented a function to reload modules so I can dynamicaly make changes without disconnecting. I added a print statement right under the class statement in one module to test if everything was reloading properly and tt seemed to work, but when I put the print in a function or edited anything in functions in general it doesn't seem to have an effect if I reload that module. Any ideas? ![]() Edit: This came to me shortly after I posted: Correct me if I'm wrong, but I am only changing the class when I do this, so all the functions in my instance remain the same and this is why I don't see any difference. If so, is there any way around this? ![]() Last edited by XxChris : February 10th, 2004 at 05:56 PM. |
|
#24
|
||||
|
||||
|
As far as i know the only way you're gonna get around with is to recreate all you're instances. Possibly do the inisalising inside a function to reduce code length.
Note: i dont clame to be infalable . Infact i may be wrong on this one.Quote:
I don't know if you know this but Python already has a reload() function built-in which you can use to... well, reload modules .Mark. Last edited by netytan : February 10th, 2004 at 07:17 PM. |
|
#25
|
||||
|
||||
|
Just a few thoughts and I have'nt used IRC but I guess the thing you need to preserve is the socket instance.
You could rewrite the __init__ function to optionally take a socket object if one exists already: Code:
def __init__(self,sock=None):
if sock:
self.sock = sock
else:
self.sock = socket....
It might be possible to do further OO by builiding a reload method in the class, this could return a new class object based on the reloaded module. There may be issues with namespace - time to experiment ![]() Code:
def reload(self):
reload("module")
temp = parseCommand(self.sock)
#now stuff to make temp look like self
return temp
So in the main module you could step through your Bots: Code:
for x in range(len(mybots_list)):
mybots_list[x] = mybots_list[x].reload()
Grim |
|
#26
|
|||
|
|||
|
Thanks again guys.
![]() Grim, I'll experiment a bit with this when I get the time, and i'll get back to you when I can. It looks promising ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Module Questions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|