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:
  #1  
Old December 12th, 2004, 08:33 PM
Yegg`'s Avatar
Yegg` Yegg` is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Dec 2004
Location: Meriden, Connecticut
Posts: 1,731 Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 4 h 5 m 27 sec
Reputation Power: 83
Send a message via AIM to Yegg`
Specific Item(s) in a List

Does anyone know how to select a specific item(s) in a list. Here's what I need it for.
Code:
        if msg == tr+"ban" and user == mt:
            print "Processing command..."
            if msg[5:6] == "*" and msg[-1] == "*":
                if msg[6:-1] == mt:
                    pass
                if ho == "yes":
                    for msg[6:-1] in userlist:
                        q.append(ban+userlist+wildmsg)
                elif ho == "no":
                    q.append(noops)
            else:
                if msg[5:224] == mt:
                    pass
                if ho == "yes":
                    q.append(ban+msg[5:224])
                elif ho == "no":
                    q.append(noops)
                else:
                    continue

The part that I need help with is the for msg[6:-1] in userlist: part. I want it so that when a user types something like, !ban *h*, the bot (my program) will attempt to ban all users in the channel (userlist) who's accounts contained "h". Remember, not just one account that contains that, but ALL of them. Can anyone help me with this?

Reply With Quote
  #2  
Old December 12th, 2004, 10:05 PM
ktpr ktpr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 17 ktpr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 47 sec
Reputation Power: 0
Look up pythons' "re" module. You'll be interested in re.search and using compiled objects for speed. Search the net for examples of use.

Reply With Quote
  #3  
Old December 13th, 2004, 03:31 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 11 m 13 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
If you just want to look for usernames which contain a substring then you can use the in keyword; or the find() or index() methods if you were so inclined. Here's an example anyway:

Code:
>>> usernames = ['netytan', 'Yegg', 'someone', 'tan']
>>>
>>> for username in usernames:
...     if 'e' in username:
...         print username
...
netytan
Yegg
someone
>>> for username in usernames:
...     if 'tan' in username:
...         print username
...
netytan
tan
>>> for username in usernames:
...     if 'one' in username:
...         print username
...
someone
>>> for username in usernames:
...     if 'Y' in username:
...         print username
...
Yegg
>>>


As you can see matches are case-sensitive, but you can get around this by using the lower() method to create a copy of each username/search-string that contains only lowercase letters. Sure you get the idea .

Hope this helps,

Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #4  
Old December 13th, 2004, 05:04 PM
Yegg`'s Avatar
Yegg` Yegg` is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Dec 2004
Location: Meriden, Connecticut
Posts: 1,731 Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 4 h 5 m 27 sec
Reputation Power: 83
Send a message via AIM to Yegg`
That code won't work how I want it to. If I did, if 'Y' in username:, the bot would try finding 'Y' in the username who sent the message. I want the program to check through a list and see which items are like the string. The one's that are alike, it will ban them. For example,

Code:
if message == "!ban *G*":
     for message[6:-1] in userlist:
          print item


item will get Replaced with whateve the proper code is. I only need to know how to find the items that contain that string in them. And then after the program finds all of the items, it does something.
Update:
I think your code is what I need, I just read it wrong. Let me try and see how it works out.
Another Update:
Yep, the code works just fine.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Specific Item(s) in a List


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT