Good day everyone!
I have a question regarding attribute errors since I can't find a solution and I have been trying to fix this for the past few hours.
First I defined a function called nesterNEW:
import sys
def print_lol(the_list, indent=False, level = 0, fh=sys.stdout):
for each_item in the_list:
if isinstance(each_item, list):
print_lol(each_item, indent, level+1, fh)
else:
if indent:
for tab_stop in range(level):
print("\t", end = '', file=fh)
print(each_item, file=fh)
I built the distribution and placed the distribution in the same folder as the following code:
man = []
other = []
import nesterNEW
try:
data = open('sketch.txt')
for each_line in data:
try:
(role, line_spoken) = each_line.split(':', 1)
line_spoken = line_spoken.strip()
if role =='Man':
man.append(line_spoken)
elif role == 'Other Man':
other.append(line_spoken)
except ValueError:
pass
data.close()
except IOError:
print('file is missing')
print(man)
print(other)
try:
with open('man_data.txt', 'w') as man_file:
nesterNEW.print_lol(man, file=man_file)
with open('other_data.txt', 'w') as other_file:
nesterNEW.print_lol(other, file=other_file)
except IOError as err:
print('File Error: ' + str(err))
It keeps giving me this error message: AttributeError: module 'nesterNEW' has no attribute 'print_lol'
I have tried the following solution, but to no avail. I tried to import the submodules, with import nesterNEW.print_lol
, but that didn't work.
Another possible solution I found is here. If you look at answer number 2, it says that the file name must be changed, if import nesterNEW.print_lol
isn't working. So I tried check the directory with nesterNEW.__file__
, but it threw another attribute error at me.
I have the feeling that I'm misinterpreting the solutions that are given on the linked sites.
This is my first time posting on here, so I hope I managed to use the right formatting. :)