Python Module Source

For the discussion of Perl, Python, Ruby, and PHP and other interpreted languages.

Python Module Source

Post by eoae on Sun Feb 07, 2010 8:23 pm
([msg=34634]see Python Module Source[/msg])

I'm looking for Python's scripts for its modules. Particularly string.find() and string.count().
Where can I find it? Is the script in the Python folder? I'm using Python 2.5, in Windows.

Purpose is, I want write a program that counts the number of matches in the given string. similar to string.count(), using string.find() to match. I've been cracking my head over it, and can't seem to find a solution, so i want to look at their code to learn something. Any enlightenment is appreciated. :)
"The hardest thing in the world to understand is the income tax." - Albert Einstein
"Government is an association of men who do violence to the rest of us." - Leo Tolstoy
User avatar
eoae
New User
New User
 
Posts: 26
Joined: Fri Jun 13, 2008 6:02 am
Blog: View Blog (0)


Re: Python Module Source

Post by shaqywacky on Sun Feb 07, 2010 8:50 pm
([msg=34635]see Re: Python Module Source[/msg])

For me its C:/python<ver>/Lib/string.py
shaqywacky
Experienced User
Experienced User
 
Posts: 85
Joined: Thu Jul 03, 2008 2:26 pm
Blog: View Blog (0)


Re: Python Module Source

Post by faazshift on Sun Feb 07, 2010 10:03 pm
([msg=34636]see Re: Python Module Source[/msg])

At least for me, /usr/lib64/python2.6/string.py doesn't contain the actual logic for finding a string. Anyway, I just took a few minutes and threw together a working function to find all occurrences of a string and append them to a list. Its really quite simple. You just have to loop (while with counters, not for) through each letter, do some comparisons, and add to the list when you find the whole string. It only took 15 code lines to achieve.
faazshift
Contributor
Contributor
 
Posts: 522
Joined: Wed Jun 03, 2009 3:55 pm
Location: Riverton, Utah
Blog: View Blog (0)


Re: Python Module Source

Post by eoae on Tue Feb 16, 2010 6:41 am
([msg=35165]see Re: Python Module Source[/msg])

hey thanks for your replies.

@shaqywacky: I can't find any scripts in string.py, only a function call. I think the function is already integrated into the binary. I'm just guessing, I have no idea.

@faazshift: That's what I'm trying to do. Except that my while loop with counter doesn't end/stuck at zero. Something is wrong with the counter, that's why I want to compare my codes to Python's so that I can see where I gone wrong. :(
"The hardest thing in the world to understand is the income tax." - Albert Einstein
"Government is an association of men who do violence to the rest of us." - Leo Tolstoy
User avatar
eoae
New User
New User
 
Posts: 26
Joined: Fri Jun 13, 2008 6:02 am
Blog: View Blog (0)


Re: Python Module Source

Post by Defience on Tue Feb 16, 2010 10:31 am
([msg=35167]see Re: Python Module Source[/msg])

Do you want to post your current code for users to look over and maybe make some suggestions on it?
User avatar
Defience
Addict
Addict
 
Posts: 1279
Joined: Thu Jun 12, 2008 3:16 pm
Blog: View Blog (0)



Return to Interpreted Languages

Who is online

Users browsing this forum: No registered users and 0 guests