Mar-05-2017, 06:08 PM
Hi,
Could you help me out a bit?
I don't understand why I cant call a function inside a class.
Here is the code I wrote so far:
Thy Pycharm says: NameError: name 'countfiles' is not defined
Could you help me out a bit?
I don't understand why I cant call a function inside a class.
Here is the code I wrote so far:
import os
import glob
import time
folder = '.'
class Sc:
def __init__(self, name):
self.name = name
def printmessage(self):
print('*' * 5 + ' WATCHDOG ' + '*' * 5)
def getlastwav(self):
''' returns last wav file in the folder '''
newest = max(glob.iglob('*.[Ww][Aa][Wv]'), key=os.path.getctime)
return newest
def countfiles(self):
''' returns how many files in the folder '''
file_count = len([name for name in os.listdir(folder) if os.path.isfile(name)])
return file_count
def checkfornewwav(self):
before = countfiles() # this function cannot be called inside the class.
print(before)
s1 = Sc('first')
s1.checkfornewwav()Why isn't that function is available inside the class?Thy Pycharm says: NameError: name 'countfiles' is not defined
