Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #2562 > unrolled thread
| Started by | Mustafa Cayci <acayci@yahoo.com> |
|---|---|
| First post | 2011-04-04 05:14 -0700 |
| Last post | 2011-04-04 16:24 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
Newbie -> NameError: getopt Mustafa Cayci <acayci@yahoo.com> - 2011-04-04 05:14 -0700
Re: Newbie -> NameError: getopt "R. Tyler Croy" <tyler@linux.com> - 2011-04-04 16:24 +0000
| From | Mustafa Cayci <acayci@yahoo.com> |
|---|---|
| Date | 2011-04-04 05:14 -0700 |
| Subject | Newbie -> NameError: getopt |
| Message-ID | <mailman.1.1301919295.9059.python-list@python.org> |
Hello,
I followed several postings in Google and came up with the beginning of the
following code:
During the execution, I am getting
Problem invoking WLST - Traceback (innermost last):
File "/home/oracle/wlsuserconfigfiles/./Health_Check_Servers.py", line 80, in
?
File "/home/oracle/wlsuserconfigfiles/./Health_Check_Servers.py", line 22, in
main
NameError: getopt
I thought I was importing the "getopt" as shown below.
Thanks for you help in advance,
Mustafa
#Conditionally import wlstModule only when script is executed with jython
if __name__ == '__main__':
from wlstModule import *#@UnusedWildImport
import sys
import os
from java.lang import System
import getopt
serverName = ''
portNumber = ''
ucf = ''
ukf = ''
adminURL = ''
protocolName = ''
portNumber = ''
def main(argv):
try:
opts, args = getopt.getopt(sys.argv[1:], "s:p:t:u:k:")
except getopt.GetoptError, err:
print str(err)
usage()
sys.exit(2)
...
[toc] | [next] | [standalone]
| From | "R. Tyler Croy" <tyler@linux.com> |
|---|---|
| Date | 2011-04-04 16:24 +0000 |
| Message-ID | <4d99f0c8$0$22174$742ec2ed@news.sonic.net> |
| In reply to | #2562 |
On Mon, 04 Apr 2011 05:14:46 -0700, Mustafa Cayci wrote:
> Hello,
>
> I followed several postings in Google and came up with the beginning of
> the following code:
> During the execution, I am getting
>
> Problem invoking WLST - Traceback (innermost last):
> File "/home/oracle/wlsuserconfigfiles/./Health_Check_Servers.py", line
> 80, in
> ?
> File "/home/oracle/wlsuserconfigfiles/./Health_Check_Servers.py", line
> 22, in
> main
> NameError: getopt
>
> I thought I was importing the "getopt" as shown below.
Try bringing your imports up out of the "if __name__" block. Where you are
referencing getopt (the main() function), the getopt module hasn't yet
been imported.
You can do something like this:
import getopt
def main():
# ...
--
- R. Tyler Croy
--------------------------------------
Code: http://github.com/rtyler
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web