Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #105111 > unrolled thread

from a module return a class

Started bykevind0718@gmail.com
First post2016-03-17 09:19 -0700
Last post2016-03-18 12:19 -0700
Articles 14 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  from a module return a class kevind0718@gmail.com - 2016-03-17 09:19 -0700
    Re: from a module return a class Laurent Pointal <laurent.pointal@free.fr> - 2016-03-17 18:16 +0100
    Re: from a module return a class John Gordon <gordon@panix.com> - 2016-03-17 17:21 +0000
      Re: from a module return a class Laurent Pointal <laurent.pointal@free.fr> - 2016-03-17 18:43 +0100
        Re: from a module return a class John Gordon <gordon@panix.com> - 2016-03-17 17:54 +0000
          Re: from a module return a class Laurent Pointal <laurent.pointal@free.fr> - 2016-03-17 19:24 +0100
            Re: from a module return a class Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-17 13:56 -0700
            Re: from a module return a class Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-17 13:59 -0700
              Re: from a module return a class kevind0718@gmail.com - 2016-03-18 05:40 -0700
      Re: from a module return a class kevind0718@gmail.com - 2016-03-18 05:34 -0700
    Re: from a module return a class kevind0718@gmail.com - 2016-03-18 05:32 -0700
      Re: from a module return a class John Gordon <gordon@panix.com> - 2016-03-18 15:08 +0000
        Re: from a module return a class John Gordon <gordon@panix.com> - 2016-03-18 16:16 +0000
          Re: from a module return a class kevind0718@gmail.com - 2016-03-18 12:19 -0700

#105111 — from a module return a class

Fromkevind0718@gmail.com
Date2016-03-17 09:19 -0700
Subjectfrom a module return a class
Message-ID<b4647f72-bf8a-4adb-ba1d-bd7d684ba350@googlegroups.com>
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


[toc] | [next] | [standalone]


#105121

FromLaurent Pointal <laurent.pointal@free.fr>
Date2016-03-17 18:16 +0100
Message-ID<56eae67c$0$3055$426a34cc@news.free.fr>
In reply to#105111
kevind0718@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

[toc] | [prev] | [next] | [standalone]


#105122

FromJohn Gordon <gordon@panix.com>
Date2016-03-17 17:21 +0000
Message-ID<ncep21$e9v$1@reader1.panix.com>
In reply to#105111
In <b4647f72-bf8a-4adb-ba1d-bd7d684ba350@googlegroups.com> kevind0718@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
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

[toc] | [prev] | [next] | [standalone]


#105127

FromLaurent Pointal <laurent.pointal@free.fr>
Date2016-03-17 18:43 +0100
Message-ID<56eaecc8$0$3658$426a74cc@news.free.fr>
In reply to#105122
John Gordon wrote:

> In <b4647f72-bf8a-4adb-ba1d-bd7d684ba350@googlegroups.com>
> kevind0718@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…

> 

[toc] | [prev] | [next] | [standalone]


#105131

FromJohn Gordon <gordon@panix.com>
Date2016-03-17 17:54 +0000
Message-ID<ncer09$rjq$1@reader1.panix.com>
In reply to#105127
In <56eaecc8$0$3658$426a74cc@news.free.fr> Laurent Pointal <laurent.pointal@free.fr> 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
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

[toc] | [prev] | [next] | [standalone]


#105135

FromLaurent Pointal <laurent.pointal@free.fr>
Date2016-03-17 19:24 +0100
Message-ID<56eaf640$0$19753$426a74cc@news.free.fr>
In reply to#105131
John Gordon wrote:

> In <56eaecc8$0$3658$426a74cc@news.free.fr> Laurent Pointal
> <laurent.pointal@free.fr> 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




[toc] | [prev] | [next] | [standalone]


#105147

FromRick Johnson <rantingrickjohnson@gmail.com>
Date2016-03-17 13:56 -0700
Message-ID<d7e37ce8-885c-4d1e-9ae5-6e633e0a2c85@googlegroups.com>
In reply to#105135
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

[toc] | [prev] | [next] | [standalone]


#105148

FromRick Johnson <rantingrickjohnson@gmail.com>
Date2016-03-17 13:59 -0700
Message-ID<515bee4d-c547-42fb-b932-322b1e4f6720@googlegroups.com>
In reply to#105135
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.

[toc] | [prev] | [next] | [standalone]


#105207

Fromkevind0718@gmail.com
Date2016-03-18 05:40 -0700
Message-ID<06f118be-ba28-415e-94ea-37af226bff6f@googlegroups.com>
In reply to#105148
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

[toc] | [prev] | [next] | [standalone]


#105205

Fromkevind0718@gmail.com
Date2016-03-18 05:34 -0700
Message-ID<690252c4-5975-4934-a2f8-85f678578b10@googlegroups.com>
In reply to#105122
On Thursday, March 17, 2016 at 1:21:16 PM UTC-4, John Gordon wrote:
> In <b4647f72-bf8a-4adb-ba1d-bd7d684ba350@googlegroups.com> kevind0718@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
> gordon@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

   
     
    







[toc] | [prev] | [next] | [standalone]


#105204

Fromkevind0718@gmail.com
Date2016-03-18 05:32 -0700
Message-ID<cc439011-f9b3-4837-ba3b-6703f99ae9be@googlegroups.com>
In reply to#105111
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

   
     
    







[toc] | [prev] | [next] | [standalone]


#105223

FromJohn Gordon <gordon@panix.com>
Date2016-03-18 15:08 +0000
Message-ID<nch5lm$gva$1@reader1.panix.com>
In reply to#105204
In <cc439011-f9b3-4837-ba3b-6703f99ae9be@googlegroups.com> kevind0718@gmail.com writes:

> As requested , full code for promptUser_PWord

<snip>

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
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

[toc] | [prev] | [next] | [standalone]


#105225

FromJohn Gordon <gordon@panix.com>
Date2016-03-18 16:16 +0000
Message-ID<nch9k3$qqn$1@reader1.panix.com>
In reply to#105223
In <mailman.332.1458315013.12893.python-list@python.org> Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> 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
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

[toc] | [prev] | [next] | [standalone]


#105236

Fromkevind0718@gmail.com
Date2016-03-18 12:19 -0700
Message-ID<0302a065-ba45-4eaa-ab76-d3d319219479@googlegroups.com>
In reply to#105225
On Friday, March 18, 2016 at 12:16:13 PM UTC-4, John Gordon wrote:
> In <mailman.332.1458315013.12893.python-list@python.org> Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> 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
> gordon@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 <module>
    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?

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web