Return variables from modules ??

Rigga Rigga at noemail.com
Tue Oct 21 16:55:40 EDT 2003


Hi,

I am new to Python and am currentky just playing with some simple functions however 
I can not work out how to return a variable back from a module, probably easier if you see the code.. 
what I want it to do is to repeat the while loop until it is no longer equal to 'repeat', 
code is below, go easy on me!:
===========================================================================
import sys
import os
# Check that the folder is accessible and writeable
reply = 'repeat'
while reply == 'repeat' :
        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'
                
                return chkpth

        print chkpth(FilePath)     # used to show me chkpth result
        print reply     # always prints repeat no matter what!
sys.exit()

==============================================================================

I have tried setting reply as a global variable but to no avail, I assume that I need to pass the variable 
back from the chkpth module but I do not know how to, any help appreciated.

Regards

Rig




More information about the Python-list mailing list