Return variables from modules ??
Rigga
Rigga at noemail.com
Fri Oct 24 14:26:51 EDT 2003
Duncan Booth wrote:
> 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
>
er yeah well spotted!! I did get a bit confused didnt I lol. THanks for
clearing it up for me it all maks sense now.
Cheers
RiGGa
More information about the Python-list
mailing list