nameerror

python NameError: global name '__file__' is not defined

試著忘記壹切 提交于 2019-11-26 18:58:34
问题 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):

Python3 NameError: name 'method' is not defined for defined @staticmethod

自古美人都是妖i 提交于 2019-11-26 17:20:37
问题 I am trying to write a simple recursive function in python3. As I am learning OO Java, I also want to write Python code involving objects. Here's my code below. I prompt the user to enter a number and the screen should display every integer smaller until 5. class Recursion: @staticmethod def recursive(x): if (x>5): print (x) recursive(x - 1) def main(self): x = int(input('Enter a number for recursive addition: ')) recursive(x) However, when I run it on a terminal, it says: "NameError: name

Python function NameError [duplicate]

爱⌒轻易说出口 提交于 2019-11-26 14:56:19
问题 This question already has an answer here : Why am I getting a NameError when I try to call my function? (1 answer) Closed 8 months ago . 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 回答1: Put your

Why am I getting a NameError when I try to call my function?

百般思念 提交于 2019-11-26 14:49:14
问题 This is my code: import os if os.path.exists(r'C:\Genisis_AI'): print("Main File path exists! Continuing with startup") else: createDirs() def createDirs(): os.makedirs(r'C:\Genisis_AI\memories') When I execute this, it throws an error: File "foo.py", line 6, in <module> createDirs() NameError: name 'createDirs' is not defined I made sure it's not a typo and I didn't misspell the function's name, so why am I getting a NameError? 回答1: You can't call a function unless you've already defined it.

Python NameError: name is not defined

烈酒焚心 提交于 2019-11-26 13:19:18
I have a python script and I am receiving the following error: Traceback (most recent call last): File "C:\Users\Tim\Desktop\pop-erp\test.py", line 1, in <module> s = Something() NameError: name 'Something' is not defined Here is the code that causes the problem: s = Something() s.out() class Something: def out(): print("it works") This is being run with Python 3.3.0 under Windows 7 x86-64. Why can't the Something class be found? Define the class before you use it: class Something: def out(self): print("it works") s = Something() s.out() You need to pass self as the first argument to all

Confusion with the assignment operation inside a falsy `if` block [duplicate]

佐手、 提交于 2019-11-26 11:54:46
This question already has an answer here: I don't understand ruby local scope 5 answers I was playing with the assignment operation within if blocks, and discovered the below result, which surprised me: C:\>irb --simple-prompt if false x = 10 end #=> nil p x nil x.object_id #=> 4 #=> nil p y NameError: undefined local variable or method `y' for main:Object from (irb):5 from C:/Ruby193/bin/irb:12:in `<main>' In the above code you can see that the x local variable has been created even though it was only assigned to in the falsy if block. I tried to to see the content of x with p x which forced

NameError: global name &#39;unicode&#39; is not defined - in Python 3

你说的曾经没有我的故事 提交于 2019-11-26 06:19:19
问题 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

Confusion with the assignment operation inside a falsy `if` block [duplicate]

只谈情不闲聊 提交于 2019-11-26 02:38:40
问题 This question already has an answer here: I don't understand ruby local scope 5 answers I was playing with the assignment operation within if blocks, and discovered the below result, which surprised me: C:\\>irb --simple-prompt if false x = 10 end #=> nil p x nil x.object_id #=> 4 #=> nil p y NameError: undefined local variable or method `y\' for main:Object from (irb):5 from C:/Ruby193/bin/irb:12:in `<main>\' In the above code you can see that the x local variable has been created even

input() error - NameError: name &#39;…&#39; is not defined

坚强是说给别人听的谎言 提交于 2019-11-26 01:17:30
问题 I am getting an error when I try to run this simple python script: input_variable = input (\"Enter your name: \") print (\"your name is\" + input_variable) Lets say I type in \"dude\", the error I am getting is: line 1, in <module> input_variable = input (\"Enter your name: \") File \"<string>\", line 1, in <module> NameError: name \'dude\' is not defined I am running Mac OS X 10.9.1 and I am using the Python Launcher app that came with the install of python 3.3 to run the script. Edit: I