Re: from a module return a class

2016-03-20 Thread kevind0718
On Thursday, March 17, 2016 at 12:19:39 PM UTC-4, kevin...@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 ?
> 
> Many thanks for your attention to this matter.
> 
> KD



As requested , full code for promptUser_PWord

import base64
import os

import _winreg
import winerror

from cryptography.fernet import Fernet
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from Tkinter import *

from unamepword import Unamepword

def butContinue():
global dbUser 
global pWord
global pwKey 
dbUser = entryName.get()
pWord  = entryPWord.get()
root1.quit()


dbUser = ""
pWord  = ""
root1 = Tk()
##root1.geometry("500x250")


lblTop = Label(root1, text=  'Please enter Database User Name & Password   ', 
font="Helvetica 14").grid(row=0, column=0, columnspan=3 , pady=5)
lblDB =Label(root1,text= 'User Name').grid(row=2, column=0 )
lblPWord = Label(root1, text= 'Password').grid(row=3,column=0)

entryName = Entry(root1)
entryName.grid(row=2, column=1, pady=5)

entryPWord = Entry(root1)
entryPWord.grid(row=3, column=1, pady = 5)

butGo  =  Button(root1, text="   Continue "  , command=butContinue 
).grid(row=5, column=1, sticky=W, pady=10)

root1.mainloop()

print "After the MainLoop"
print  dbUser
print  pWord


if dbUser is None or pWord is None  or  dbUser.strip() == ""   or  
pWord.strip() ==  ""  :
print "** ** ** ** ** ** ** ** ** **  ** **  ** ** ** ** ** ** ** ** ** **  
** **"
print "**  Missing a value CANNOT continue  ** ** ** "
print "**  Bye "
##  sys.exit()

user_pword =  Unamepword(dbUser, pWord)

return user_pword

   
 









-- 
https://mail.python.org/mailman/listinfo/python-list


from a module return a class

2016-03-20 Thread kevind0718
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 ?

Many thanks for your attention to this matter.

KD



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: from a module return a class

2016-03-19 Thread Laurent Pointal
John Gordon wrote:

> In 
> kevind0...@gmail.com writes:
> 
>> ##  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
> 
> Show us the complete definition of promptUser_PWord().

AFAIU It looks to be the module…

> 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: from a module return a class

2016-03-19 Thread kevind0718
On Thursday, March 17, 2016 at 1:21:16 PM UTC-4, John Gordon wrote:
> In  
> kevind0...@gmail.com writes:
> 
> > ##  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
> 
> Show us the complete definition of promptUser_PWord().
> 
> -- 
> John Gordon   A is for Amy, who fell down the stairs
> gor...@panix.com  B is for Basil, assaulted by bears
> -- Edward Gorey, "The Gashlycrumb Tinies"

As requested code for promptUser_PWord


import base64
import os

import _winreg
import winerror

from cryptography.fernet import Fernet
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from Tkinter import *

from unamepword import Unamepword

def butContinue():
global dbUser 
global pWord
global pwKey 
dbUser = entryName.get()
pWord  = entryPWord.get()
root1.quit()


dbUser = ""
pWord  = ""
root1 = Tk()
##root1.geometry("500x250")


lblTop = Label(root1, text=  'Please enter Database User Name & Password   ', 
font="Helvetica 14").grid(row=0, column=0, columnspan=3 , pady=5)
lblDB =Label(root1,text= 'User Name').grid(row=2, column=0 )
lblPWord = Label(root1, text= 'Password').grid(row=3,column=0)

entryName = Entry(root1)
entryName.grid(row=2, column=1, pady=5)

entryPWord = Entry(root1)
entryPWord.grid(row=3, column=1, pady = 5)

butGo  =  Button(root1, text="   Continue "  , command=butContinue 
).grid(row=5, column=1, sticky=W, pady=10)

root1.mainloop()

print "After the MainLoop"
print  dbUser
print  pWord


if dbUser is None or pWord is None  or  dbUser.strip() == ""   or  
pWord.strip() ==  ""  :
print "** ** ** ** ** ** ** ** ** **  ** **  ** ** ** ** ** ** ** ** ** **  
** **"
print "**  Missing a value CANNOT continue  ** ** ** "
print "**  Bye "
##  sys.exit()

user_pword =  Unamepword(dbUser, pWord)

return user_pword

   
 









-- 
https://mail.python.org/mailman/listinfo/python-list


Re: from a module return a class

2016-03-19 Thread John Gordon
In <56eaecc8$0$3658$426a7...@news.free.fr> Laurent Pointal 
 writes:

> >> user_pword = promptUser_PWord()
> > 
> > Show us the complete definition of promptUser_PWord().

> AFAIU It looks to be the module…

If it were a module, it wouldn't be callable.  It has to be a function
or a class.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: from a module return a class

2016-03-19 Thread Rick Johnson
On Thursday, March 17, 2016 at 1:24:10 PM UTC-5, Laurent Pointal wrote:
> So the error: SyntaxError: 'return' outside function

My suspicion is the the OP misunderstands how modules work. He is assuming that 
he can return a value from them. But without the source, who knows??? I think 
John has the same suspicion as me.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: from a module return a class

2016-03-19 Thread kevind0718
On Friday, March 18, 2016 at 12:16:13 PM UTC-4, John Gordon wrote:
> In  Wolfgang Maier 
>  writes:
> 
> > > So promptUser_PWord is a module?  Well, I'm confused.  You gave us this
> > > bit of code:
> > >
> > >  user_pword = promptUser_PWord()
> > >
> > > But that can't work if promptUser_PWord is a module; modules aren't
> > > callable.  promptUser_PWord() has to be a function or a class.
> > >
> 
> > Yes, but I guess the OP's program will run into the SyntaxError when 
> > trying to import the module, i.e., before it ever encounters the 
> > TypeError: 'module' object is not callable.
> 
> Good point; I hadn't thought of that.
> 
> -- 
> John Gordon   A is for Amy, who fell down the stairs
> gor...@panix.com  B is for Basil, assaulted by bears
> -- Edward Gorey, "The Gashlycrumb Tinies"

true I get the following:  
  File "H:\dev\eclipse\workspace\genXls\src\genXls\genXlswPrompt.py", line 11, 
in 
import promptUser_PWord
  File "H:\dev\eclipse\workspace\genXls\src\genXls\promptUser_PWord.py", line 58
return user_pword
SyntaxError: 'return' outside function

so what I get from the various postings is promptUser_PWord must be
converted to a class.  True?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: from a module return a class

2016-03-19 Thread Laurent Pointal
kevind0...@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

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: from a module return a class

2016-03-19 Thread Rick Johnson
On Thursday, March 17, 2016 at 1:24:10 PM UTC-5, Laurent Pointal wrote:
> So the error: SyntaxError: 'return' outside function

>>> return
SyntaxError: 'return' outside function
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: from a module return a class

2016-03-19 Thread Wolfgang Maier

On 18.03.2016 16:08, John Gordon wrote:

In  kevind0...@gmail.com 
writes:


As requested , full code for promptUser_PWord




So promptUser_PWord is a module?  Well, I'm confused.  You gave us this
bit of code:

 user_pword = promptUser_PWord()

But that can't work if promptUser_PWord is a module; modules aren't
callable.  promptUser_PWord() has to be a function or a class.



Yes, but I guess the OP's program will run into the SyntaxError when 
trying to import the module, i.e., before it ever encounters the 
TypeError: 'module' object is not callable.


--
https://mail.python.org/mailman/listinfo/python-list


Re: from a module return a class

2016-03-19 Thread John Gordon
In  kevind0...@gmail.com 
writes:

> ##  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

Show us the complete definition of promptUser_PWord().

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: from a module return a class

2016-03-18 Thread John Gordon
In  kevind0...@gmail.com 
writes:

> As requested , full code for promptUser_PWord



So promptUser_PWord is a module?  Well, I'm confused.  You gave us this
bit of code:

user_pword = promptUser_PWord()   

But that can't work if promptUser_PWord is a module; modules aren't
callable.  promptUser_PWord() has to be a function or a class.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: from a module return a class

2016-03-18 Thread Laurent Pointal
John Gordon wrote:

> In <56eaecc8$0$3658$426a7...@news.free.fr> Laurent Pointal
>  writes:
> 
>> >> user_pword = promptUser_PWord()
>> > 
>> > Show us the complete definition of promptUser_PWord().
> 
>> AFAIU It looks to be the module…
> 
> If it were a module, it wouldn't be callable.  It has to be a function
> or a class.

So the error: SyntaxError: 'return' outside function





-- 
https://mail.python.org/mailman/listinfo/python-list


Re: from a module return a class

2016-03-18 Thread Wolfgang Maier

On 3/18/2016 20:19, kevind0...@gmail.com wrote:


so what I get from the various postings is promptUser_PWord must be
converted to a class.  True?



A simple function would also do. Just make sure that the return is 
inside a callable block.


--
https://mail.python.org/mailman/listinfo/python-list


Re: from a module return a class

2016-03-18 Thread John Gordon
In  Wolfgang Maier 
 writes:

> > So promptUser_PWord is a module?  Well, I'm confused.  You gave us this
> > bit of code:
> >
> >  user_pword = promptUser_PWord()
> >
> > But that can't work if promptUser_PWord is a module; modules aren't
> > callable.  promptUser_PWord() has to be a function or a class.
> >

> Yes, but I guess the OP's program will run into the SyntaxError when 
> trying to import the module, i.e., before it ever encounters the 
> TypeError: 'module' object is not callable.

Good point; I hadn't thought of that.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: from a module return a class

2016-03-18 Thread kevind0718
On Thursday, March 17, 2016 at 4:59:32 PM UTC-4, Rick Johnson wrote:
> On Thursday, March 17, 2016 at 1:24:10 PM UTC-5, Laurent Pointal wrote:
> > So the error: SyntaxError: 'return' outside function
> 
> My suspicion is the the OP misunderstands how modules work. He is assuming 
> that he can return a value from them. But without the source, who knows??? I 
> think John has the same suspicion as me.

yep OP is not sure how the pieces go together.
source code for promptUser_PWord has been posted.

thanks for your attention to this matter.

KD
-- 
https://mail.python.org/mailman/listinfo/python-list