Changing the private variables content

Piet van Oostrum piet at cs.uu.nl
Wed Jul 22 19:34:34 EDT 2009


>>>>> Ryniek90 <ryniek90 at gmail.com> (R) wrote:

>R> It looks like private variable have specific naure, that prevent from
>R> traditional editing them.
>R> Still searching for some tuts about private methods and variables.

Why do you stubbornly keep saying that, while you have been told that it
is not the case. Instead you would do better debugging your own case
instead of making false claims. Sprinkle a few print statements in your
code to see what is happening.

Here are a few thing for you to look at:

       #using private method '_search_for_module' with 'self.' prefix
       #to search for prefered module
       self._search_for_module(_chosen_module, _user_search_path)

You call it with 2 parameters: _chosen_module, _user_search_path
Look at the definition:

   def _search_for_module(self, *args):

It has *args to pick up the arguments, but they are not used in the
body. Instead you use self._user_search_path and self._chosen_module.
The latter one is always '', never changed to anything else. So it is
not surprising that the module is not found.
 
In print_module you have the same kind of confusion.

Do you think that magically self._chosen_module gets the value of
_chosen_module? Is that you idea of `private variables'?

Or do you think that *args does magical things?

       """Private method which walks through default Python
       installation directories, and search for prefered module."""
           #walking thru all directories available in path _user_search_path'
       for root, dirs, files in os.walk(self._user_search_path):
           for f in files:
               #if found file 'f' is THAT module,
               #full path to THAT file is assigned to variable
               print "Trying %s" % f
               if f == ("%s.py" % self._chosen_module):
                   self._this_module = os.path.join(root, f)


-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org



More information about the Python-list mailing list