from a module return a class

Laurent Pointal laurent.pointal at free.fr
Thu Mar 17 13:16:44 EDT 2016


kevind0718 at gmail.com wrote:

> Hello:
> 
> Working with python 2.7.
> 
> I have a module promptUser_PWord  that will prompt a user for their user
> name and pword.  Works fine stand alone.
> I also have a module, genXLS that does a bunch of processing it has worked
> fine for months.  And a class Unamepword define as follows: class
> Unamepword:
>     ## 
>     ## class to hold user name and pWord for Database
>     uName = None
>     pWord = None
>     def __init__(self, uStr, pStr):
>         self.uName = uStr
>         self.pWord = pStr
> 
> There are scenarios where running genXLS requires the user to be prompted
> for their user name and password.
> 
> The final line of promptUser_PWord are:
>     user_pword =  Unamepword(dbUser, pWord)
>     return user_pword
> 
> 
> And in genXLS I have
>     ##  prompt the user for a User name a& pWord
>     user_pword = promptUser_PWord()
> 
> I get the error
>   File "H:\dev\eclipse\workspace\genXls\src\genXls\promptUser_PWord.py",
>   line 58
>     return user_pword
> SyntaxError: 'return' outside function
> 
> 
> Here is my complete newbee question:
>    How do I stich these pieces together so the user will be prompted and
>    the values (contained in the class Unamepword) will be passed back to
>    genXLS ?

Just… define a function (SyntaxError: 'return' outside function).


> The final line of promptUser_PWord become:

user_pword =  Unamepword(dbUser, pWord)
def get_user_pword():
     return user_pword

and call get_user_pword() from within genXLS:

user_pword = promptUser_PWord.get_user_pword()

A+
Laurent
> 
> Many thanks for your attention to this matter.
> 
> KD




More information about the Python-list mailing list