L
L
LoLwytN2020-06-17 18:22:20
Python
LoLwytN, 2020-06-17 18:22:20

Why is the array not visible in the method?

I created a class, defined the postsMas array in it and created the save() method below. Further in this method, I wanted to refer to the array, but for some reason unknown to me, the postsMas array is not visible in the save() method. Although I define an array above the method. Please explain why?

Here is the code:

class Post():
title = '1'
pubDate = '2'
time = '3'

postsMas = [
    [title, pubDate, time]
]

SAVES_FILE = 'saves.dat'

def save(self):
    SAVES_FILE = 'saves.dat'
    with open(SAVES_FILE, 'ab') as file:
        pickle.dump(postsMas, file)


Error: NameError: name 'postsMas' is not defined

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-06-17
@LoLwytN

self.postsMas

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question