nameerror

Problem using OpenStruct with ERB

萝らか妹 提交于 2019-11-29 03:31:16
EDIT: forgot to include my environment info... Win7x64, RubyInstaller Ruby v1.9.1-p378 EDIT 2: just updated to v1.9.1, patch 429, and still getting this same error. Edit 3: running this same code in Ruby v1.8.7, patch 249, works fine. so it's v1.9.1 that broke it, apparently. I'm new to using ERB and the samples i could find are... ummm... less than helpful... having played around with ERB for about an hour, I got some basic examples working (finally), but I have no idea why this doesn't work... require 'ostruct' require 'erb' data = {:bar => "bar"} vars = OpenStruct.new(data) template = "foo

python NameError: name 'xxx' is not defined

六月ゝ 毕业季﹏ 提交于 2019-11-28 14:52:46
puzzle = [[' 1', ' 2', ' 3', ' 4'], [' 5', ' 6', ' 7', ' 8'],[ ' 9', '10', '11', '12'], ['13', '14', '15', ' X']] def find_pos(alist, item): for i in alist: for j in range(4): if i[j] == item: row = alist.index(i) col = j find_pos(puzzle,' X') a = row print(a) I think I defined the name row by running the function find_pos , if not, how to fix it to get row Do not put any print in the find_pos function Just return the values from the function: puzzle = [[' 1', ' 2', ' 3', ' 4'], [' 5', ' 6', ' 7', ' 8'],[ ' 9', '10', '11', '12'], ['13', '14', '15', ' X']] def find_pos(alist, item): for i in

NameError: name 'python' is not defined [closed]

老子叫甜甜 提交于 2019-11-27 22:30:16
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Am encountering this error in Windows Command line,done a wide search but could not get a perfect answer.Please find the error below and help in solving. python Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'python' is not defined >>> Thanks in Advance, 回答1: It looks like

Problem using OpenStruct with ERB

谁都会走 提交于 2019-11-27 17:37:18
问题 EDIT: forgot to include my environment info... Win7x64, RubyInstaller Ruby v1.9.1-p378 EDIT 2: just updated to v1.9.1, patch 429, and still getting this same error. Edit 3: running this same code in Ruby v1.8.7, patch 249, works fine. so it's v1.9.1 that broke it, apparently. I'm new to using ERB and the samples i could find are... ummm... less than helpful... having played around with ERB for about an hour, I got some basic examples working (finally), but I have no idea why this doesn't work

python NameError: global name '__file__' is not defined

空扰寡人 提交于 2019-11-27 17:28:50
When I run this code in python 2.7, I get this error: Traceback (most recent call last): File "C:\Python26\Lib\site-packages\pyutilib.subprocess-3.5.4\setup.py", line 30, in <module> long_description = read('README.txt'), File "C:\Python26\Lib\site-packages\pyutilib.subprocess-3.5.4\setup.py", line 19, in read return open(os.path.join(os.path.dirname(__file__), *rnames)).read() NameError: global name '__file__' is not defined code is: import os from setuptools import setup def read(*rnames): return open(os.path.join(os.path.dirname(__file__), *rnames)).read() setup(name="pyutilib.subprocess",

Python function NameError [duplicate]

夙愿已清 提交于 2019-11-27 09:53:26
This question already has an answer here: Why am I getting a NameError when I try to call my function? 1 answer I am using python 3.4.1. I keep getting this error, (NameError: name 'calcHullSpeed' is not defined) What am I doing wrong? import math LWL = float(input("Enter the length of the boat: ")) maxHullSpeed = calcHullSpeed(LWL) print("The hull speed is: " + str(round(maxHullSpeed,2))) def calcHullSpeed(LWL): maxHS = 1.34*math.sqrt(LWL) return maxHS Put your function first: def calcHullSpeed(LWL): maxHS = 1.34*math.sqrt(LWL) return maxHS LWL = float(input("Enter the length of the boat: "))

python NameError: name 'xxx' is not defined

走远了吗. 提交于 2019-11-27 09:07:34
问题 puzzle = [[' 1', ' 2', ' 3', ' 4'], [' 5', ' 6', ' 7', ' 8'],[ ' 9', '10', '11', '12'], ['13', '14', '15', ' X']] def find_pos(alist, item): for i in alist: for j in range(4): if i[j] == item: row = alist.index(i) col = j find_pos(puzzle,' X') a = row print(a) I think I defined the name row by running the function find_pos , if not, how to fix it to get row Do not put any print in the find_pos function 回答1: Just return the values from the function: puzzle = [[' 1', ' 2', ' 3', ' 4'], [' 5', '

NameError: name 'self' is not defined

孤人 提交于 2019-11-27 06:17:00
Why such structure class A: def __init__(self, a): self.a = a def p(self, b=self.a): print b gives an error NameError: name 'self' is not defined ? Default argument values are evaluated at function define-time, but self is an argument only available at function call time. Thus arguments in the argument list cannot refer each other. It's a common pattern to default an argument to None and add a test for that in code: def p(self, b=None): if b is None: b = self.a print b For cases where you also wish to have the option of setting 'b' to None: def p(self, **kwargs): b = kwargs.get('b', self.a)

python: NameError:global name '…‘ is not defined [duplicate]

三世轮回 提交于 2019-11-27 01:14:27
问题 This question already has an answer here: Python: NameError: global name 'foobar' is not defined [duplicate] 1 answer in my code, I have: class A: def a(): ...... def b(): a() ...... b() Then the compiler will say "NameError: global name a() is not defined." If I pull all the stuffs out of the class A, it would be no problem, but how can I define the method in class A? Thank you very much. 回答1: You need to call self.a() to invoke a from b . a is not a global function, it is a method on the

NameError: global name 'unicode' is not defined - in Python 3

让人想犯罪 __ 提交于 2019-11-26 19:39:32
I am trying to use a Python package called bidi. In a module in this package (algorithm.py) there are some lines that give me error, although it is part of the package. Here are the lines: # utf-8 ? we need unicode if isinstance(unicode_or_str, unicode): text = unicode_or_str decoded = False else: text = unicode_or_str.decode(encoding) decoded = True and here is the error message: Traceback (most recent call last): File "<pyshell#25>", line 1, in <module> bidi_text = get_display(reshaped_text) File "C:\Python33\lib\site-packages\python_bidi-0.3.4-py3.3.egg\bidi\algorithm.py", line 602, in get