Answers for "AttributeError: module 'datetime' has no attribute 'date'"

0

type object 'datetime.datetime' has no attribute 'timedelta'

# Use either
import datetime
datetime.datetime.timedelta()
# or
from datetime import datetime
datetime.timedelta()
# But do not use (as you currently are):
from datetime import datetime
datetime.datetime.timedelta()
Posted by: Guest on April-19-2021
-1

AttributeError: module 'datetime' has no attribute 'timestamp'

import hashlib
import datetime
import timestamp

class Block:
    def __init__(self, previous_block_hash, data, timestamp):
        self.previous_block_hash = previous_block_hash
        self.data = data
        self.timestamp = timestamp
        self.hash = self.get_hash()

    @staticmethod   
    def create_genesis_block():
        return Block("0", "0", datetime.timestamp.now())

    def get_hash(self):
        header_bin = (str(self.previous_block_hash) +
                      str(self.data) +
                      str(self.timestamp)).encode()

        inner_hash = hashlib.sha256(header_bin).hexdigest().encode()
        outer_hash = hashlib.sha256(inner_hash).hexdigest()
        return outer_hash
Posted by: Guest on April-04-2021

Code answers related to "AttributeError: module 'datetime' has no attribute 'date'"

Python Answers by Framework

Browse Popular Code Answers by Language