Return variables from modules ??

Duncan Booth duncan at NOSPAMrcp.co.uk
Thu Oct 23 03:34:22 EDT 2003


Rigga <Rigga at noemail.com> wrote in news:pZxlb.10028$xv5.9058 at news-
binary.blueyonder.co.uk:

> What am I doing wrong?

You are assigning to the local variable 'reply' inside the function chkpth. 
This is not the same as the variable 'reply' in 'myfunction'.

You seem to be keen on the idea of reusing variable names, as I see you 
also have a local variable 'chkpth' inside the function 'chkpth'. Python is 
a free programming language, you don't actually get charged for each new 
variable you use, so be generous and use some different names.

You also seem to have a slight indentation problem so it looks like chkpth 
(the function, not the variable) is never going to get called.

Try something like this:

import sys
import os

def myfunction():
      # assignment to outer reply variable removed from here.
      FilePath = raw_input("Enter path to files: ")

      def chkpth(FilePath):
            if os.path.exists(FilePath):
                  # File location exists
                  AccFlag = os.access(FilePath,os.R_OK |
                  os.X_OK | os.W_OK)

                  if (AccFlag):
                        #  Cool you have FULL access to
                        #  the location
                        chkpth = "OK"
                        reply = 'stop'
                  else:
                        # You do not have access
                        chkpth = "DENIED"
                        reply = 'repeat'

            else:
                  # No files found exiting...
                  chkpth = "NOT FOUND"
                  reply = 'repeat'

            # Returning the reply and the chkpth variable
            return reply, chkpth


        # Pick up the results so we can use them       
        reply, result = chkpth(FilePath)     # used to show me chkpth 
result
        print result
        print reply     # always prints repeat no matter what!
        return reply

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list