views:

284

answers:

3

Hi, I just wondered, how to hide special

__.*__

methods in python*? Especially I am using an interactive python interpreter with tab-completion, and I would like to display only the methods my modules expose ...

thanks,

/ myyn /

*(at least from the user, who uses a python shell)


it looks like this now:

h[2] >>> Q.
Q.ALL(                       Q.__delattr__(               Q.__getattribute__(                
Q.__package__                Q.__sizeof__(                Q.find_values(                         
Q.json
Q.DEFAULT_CONDITION(         Q.__dict__                   Q.__hash__(                  
Q.__reduce__(                Q.__str__(                   Q.get_loops_total_platform(  
Q.jsonlib
Q.SUCCESSFUL(                Q.__doc__                    Q.__init__(                  
Q.__reduce_ex__(             Q.__subclasshook__(          Q.get_platforms(             
Q.memoize(
Q.__all__                    Q.__file__                   Q.__name__                     
Q.__repr__(                  Q.cached_open(               Q.get_snippets(              
Q.__class__(                 Q.__format__(                Q.__new__(                      
Q.__setattr__(               Q.find_results(              Q.get_subjects(              
h[2] >>> Q.

and I wish it looked like:

h[2] >>> Q.
Q.ALL(                       Q.find_values(               Q.json
Q.DEFAULT_CONDITION(         Q.get_loops_total_platform(  
Q.jsonlib                    Q.SUCCESSFUL(                Q.get_platforms(             
Q.memoize(                   Q.cached_open(               Q.get_snippets(              
Q.find_results(              Q.get_subjects(              
h[2] >>> Q.
+3  A: 

I think you should look for a way to get that particular environment/interpreter to stop displaying the "private" methods when you press TAB. I don't think there is a way to "hide" methods from Python itself, that would be very weird.

unwind
thanks; i tried to use the rlcompleter Complete(namespace=mynsdict) and it should work ..
The MYYN
+1  A: 

I would take a look into ipython. Maybe your are able to hook ipythons interactive shell without an subprocess into your app and apply the private method filtering from there.

optixx
+1  A: 

Well, you could create a subclass of rlcompleter.Completer, override the methods in question, and install that into readline.

import rlcompleter
import readline
class MyCompleter(rlcompleter.Completer):
    def global_matches(self, text):
        ....
    def attr_matches(self, text):
        ....

import readline
readline.set_completer(MyCompleter().complete)

These code snippets allow case-insensitive tab completion:

http://www.nabble.com/Re%3A-Tab-completion-question-p22905952.html

theller