Python - Global name date is not defined [closed]

2024/11/17 4:49:42

I'm using this inside a Django view. I copied this exactly: http://www.pythonexamples.org/2010/12/23/how-to-get-todays-date-in-python/

That is:

import datetime
variable = datetime.date.today()

I also tried

from datetime import datetime
variable = datetime.date.today()

But then this error occurs:

'method_descriptor' object has no attribute 'today'
Answer

You asked about why this thing happens... so here goes my try and my first ever answer in stack overflow.

It seems like a scope/namespace issue to me.

Check today() 's scope. Is it accessible from where you refer to it?

Check also this guy: http://igotgenes.blogspot.gr/2009/01/class-attributes-and-scoping-in-python.html

And this: https://docs.python.org/2/tutorial/classes.html

in order to understand deeper the reason it might happened.

Sorry but can't help more, since I don't have your whole project at my disposal :(

Edit: Just a few typos.

https://en.xdnf.cn/q/120244.html

Related Q&A

Python update user input with tkinter button

Im just starting with python and im having a problem. Ive tried various solutions, but i cant update the field that says 19. When i click on plus, i want it to be 20, then 21,... and when i click - it …

Python Unique DF in loop [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 5…

TypeError: unsupported operand type(s) for +=: NoneType and str

I am new to Python and Im sure that Im doing something wrong - I would like to ask a user for three numbers and print their sum, heres my current code:for i in range(0, 3):total = Nonenum = input(Pleas…

multiply list of ndarrays by list

I want to multiply a list of numbers, by a ndarray, that is, each number in the list multiply by the first ndarray. This is the list: list1 = [840,845,897]This is the list of ndarray list = df[Example]…

Python skipping last element in while iterating a list using for loop [duplicate]

This question already has answers here:Strange result when removing item from a list while iterating over it in Python(12 answers)Closed 9 years ago.class Sample:def __init__(self):self.lst_report_foot…

can this code be shortened or improved? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.This question does not appear to be about programming within the scope defined in the help center.Cl…

Count Running and Stopped Ec2 Instances with AWS Lambda

How can I count number of running and stopped EC2 instances in a particular region using boto3 and an AWS Lambda function?

Python2.7: How to split a column into multiple column based on special strings like this?

Im a newbie for programming and python, so I would appreciate your advice!I have a dataframe like this.In info column, there are 7 different categories: activities, locations, groups, skills, sights, t…

python - return and print does not give same result

what Im trying to do is take the entered string separated by commas and change it to list then for each list as a key print the associated value.def main():myDict = {a:1, b:2, c:3, d:4, e:5....}u_input…

Creating a menuBar in a frame?

import Tkinter as tk from Tkinter import Label, StringVar, Entry, Button, Menu, Frame, Tk, Canvas import subprocess from Tkconstants import LEFT, CENTER,W, SUNKEN , X, Yclass SampleApp(tk.Tk):def __ini…