Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #16  
Old February 9th, 2004, 08:56 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
Strike, quick and dirty nothing more

Grim

Reply With Quote
  #17  
Old February 9th, 2004, 02:53 PM
XxChris XxChris is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 217 XxChris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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 .

Reply With Quote
  #18  
Old February 9th, 2004, 04:07 PM
Strike Strike is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Houston, TX
Posts: 383 Strike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 7
Send a message via ICQ to Strike Send a message via AIM to Strike Send a message via Yahoo to Strike
Quote:
Originally posted by Grim Archon
Strike, quick and dirty nothing more

Grim

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.
__________________
Debian - because life's too short for worrying.
Best. (Python.) IRC bot. ever.

Reply With Quote
  #19  
Old February 9th, 2004, 04:33 PM
XxChris XxChris is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 217 XxChris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #20  
Old February 9th, 2004, 05:06 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
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.


Reply With Quote
  #21  
Old February 9th, 2004, 06:07 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
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

Reply With Quote
  #22  
Old February 10th, 2004, 02:17 PM
XxChris XxChris is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 217 XxChris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks alot Grim! ;D

Reply With Quote
  #23  
Old February 10th, 2004, 05:53 PM
XxChris XxChris is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 217 XxChris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #24  
Old February 10th, 2004, 07:14 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 2 m 16 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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've implemented a function to reload modules so I can dynamicaly make changes without disconnecting


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.
__________________
programming language development: www.netytan.com Hula


Last edited by netytan : February 10th, 2004 at 07:17 PM.

Reply With Quote
  #25  
Old February 11th, 2004, 03:10 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
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

Reply With Quote
  #26  
Old February 11th, 2004, 02:19 PM
XxChris XxChris is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 217 XxChris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Module Questions


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 



<