nameerror

Why do I get this NameError in a generator within a Python class definition?

。_饼干妹妹 提交于 2019-12-08 15:07:33
问题 In Python 3.5.0 this code: a = (1,2) class Foo(object): b = (3,4) c = tuple((i,j) for j in b for i in a) d = tuple((i,j) for i in a for j in b) produces: Traceback (most recent call last): File "genexprtest.py", line 2, in <module> class Foo(object): File "genexprtest.py", line 5, in Foo d = tuple((i,j) for i in a for j in b) File "genexprtest.py", line 5, in <genexpr> d = tuple((i,j) for i in a for j in b) NameError: name 'b' is not defined Why do I get this error? And why do I not get this

Importing/running classes in Python causes NameError

房东的猫 提交于 2019-12-08 10:52:24
问题 I have a python program and I'm trying to import other python classes and I am getting a NameError: Traceback (most recent call last): File "run.py", line 3, in <module> f = wow('fgd') NameError: name 'wow' is not defined This is in file called new.py : class wow(object): def __init__(self, start): self.start = start def go(self): print "test test test" f = raw_input("> ") if f == "test": print "!!" return c.vov() else: print "nope" return f.go() class joj(object): def __init__(self, start):

python pdb lambda function global name error

不打扰是莪最后的温柔 提交于 2019-12-07 02:27:26
问题 I was testing a fix using pdb.set_trace() to make sure it worked the way I expected before implementing it and kept getting a weird error. (Pdb) test = [1,2,3,4,4,3,2,1] (Pdb) max(range(len(test)),key=lambda i: test[i]) *** NameError: global name 'test' is not defined So I moved to my localmachine to make sure I could reproduce as simply as possible before asking for help. In ipython I get the exact same behavior. In [1]: test = [1,2,3,4,4,3,2,1] In [2]: max(range(len(test)),key=lambda i:

calling class from an external module causes NameError, in IDLE it works fine

落爺英雄遲暮 提交于 2019-12-06 07:57:31
i have the following code in a module called code_database.py class Entry(): def enter_data(self): self.title = input('enter a title: ') print('enter the code, press ctrl-d to end: ') self.code = sys.stdin.readlines() self.tags = input('enter tags: ') def save_data(self): with open('entry.pickle2', 'ab') as f: pickle.dump(self, f) in idle the class-defined methods work fine: >>> import code_database >>> entry = code_database.Entry() >>> entry.enter_data() enter a title: a enter the code, press ctrl-d to end: benter tags: c >>> entry.title 'a' >>> entry.code ['b'] >>> entry.tags 'c' >>> however

ActiveAdmin - uninitialized constant AdminUser

狂风中的少年 提交于 2019-12-05 07:16:58
I'm getting an error while trying to run my app, having recently installed ActiveAdmin. It was working fine, but, after idling for a while, suddenly it isn't! In my gem file: gem 'activeadmin' In my routes: devise_for :admin_users, ActiveAdmin::Devise.config ActiveAdmin.routes(self) And in my admin_user.rb ActiveAdmin.register AdminUser do index do column :email column :current_sign_in_at column :last_sign_in_at column :sign_in_count default_actions end etc.... The error when trying to run: NameError: uninitialized constant AdminUser ~/Desktop/Sites/Fleetnation/app/admin/admin_user.rb:1:in `

python pdb lambda function global name error

旧城冷巷雨未停 提交于 2019-12-05 07:03:15
I was testing a fix using pdb.set_trace() to make sure it worked the way I expected before implementing it and kept getting a weird error. (Pdb) test = [1,2,3,4,4,3,2,1] (Pdb) max(range(len(test)),key=lambda i: test[i]) *** NameError: global name 'test' is not defined So I moved to my localmachine to make sure I could reproduce as simply as possible before asking for help. In ipython I get the exact same behavior. In [1]: test = [1,2,3,4,4,3,2,1] In [2]: max(range(len(test)),key=lambda i: test[i]) Out[2]: 3 In [3]: import pdb; pdb.set_trace() --Call-- > /Users/tristanmatthews/anaconda/lib

NameError: name 'KEYDOWN' is not defined

六眼飞鱼酱① 提交于 2019-12-04 15:39:40
I am new to programming with PyGame and I've made this code: import sys, pygame pygame.init() size = width, height = 800, 600 speed = [2, 2] black = 1, 1, 1 screen = pygame.display.set_mode(size) ball = pygame.image.load("ball.bmp") ballrect = ball.get_rect() player1 = pygame.image.load("player1.png") player1rect = player1.get_rect() mod_x = mod_y = 0 while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() elif event.type == KEYDOWN: if event.key == K_W: movex = 2 if event.key == K_S: movex = -2 ballrect = ballrect.move(speed) if ballrect.left < 0 or ballrect.right >

My variable is defined but python is saying it isn't?

喜夏-厌秋 提交于 2019-12-04 06:56:34
问题 I keep getting an error telling me that the name hourly_pay is not defined, but I have it defined inside the main function. I'm a beginner as I've just started class but to me it looks like it should be working: commission_pay_amount = .05 income_taxes = .25 Pay_per_hour = 7.50 def main(): display_message() hourly_pay = float(input('Please enter amount of hours worked: ')) commission_pay = hourly_pay * commission_pay_amount gross_pay = hourly_pay + commission_pay witholding_amount = gross_pay

Python: ' ' is not defined

大憨熊 提交于 2019-12-04 05:51:27
问题 Here is my code: # This program makes the robot calculate the average amount of light in a simulated room from myro import * init("simulator") from random import* def pressC(): """ Wait for "c" to be entered from the keyboard in the Python shell """ entry = " " while(entry != "c"): entry = raw_input("Press c to continue. ") print("Thank you. ") print def randomPosition(): """ This gets the robot to drive to a random position """ result = randint(1, 2) if(result == 1): forward(random(), random

Python NameError from contents of a variable

江枫思渺然 提交于 2019-12-04 05:25:30
问题 I've been making a mod for the Raspberry Pi version of Minecraft and I'm getting a very frustrating error every time I enter one of the commands in my program. Here's my code: import minecraft.minecraft as minecraft import minecraft.block as block import time mc = minecraft.Minecraft.create(); print('newBlock - Change ID of block to spawn') print('blockType - Change subID of block to spawn') print('pos1') print('pos2') print('fill - fill specified area') print('clear - clear specified area')