Return variables from modules ??
Rigga
Rigga at noemail.com
Wed Oct 22 12:09:54 EDT 2003
I have tried the code you supplied however it still does not return the
reply as expected, I have even tried the following code but I just cant get
it to return a variable from a module:
My module: we will call it filechk.py
********************************************************************
import sys
import os
def myfunction():
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!
return reply
********************************************************************
Main program: we will call it testme.py
********************************************************************
import filechk
result = filechk.myfunction()
print result
********************************************************************
results when ran:
---------------------------------------------------
root at mybox:> python testme.py
root at mybox:> Enter Path to files: /root/
root at mybox:> None
What I expected to happen in the example above for it to return OK (and if
I queried the reply variable for it to return 'stop)
What am I doing wrong?
More information about the Python-list
mailing list