head first python print_lol module error - python-3.x

i am following head first python book using python3 version.
My directory in which i have my nester folder in
C:\Users\Nimmi\AppData\Local\Programs\Python\Python36\Lib\site-packages\nester as in my image
When i import module nester no error occurs on IDLE:
>>import nester
i have following codde written in my nester.py:
def print_lol(the_list,level):
for each_item in the_list:
if isinstance(each_item, list):
print_lol(each_item)
else:
for tab_stop in range(level):
print("\t", end ='')
print(each_item)
when i try to call nester.print_lol() function, it gives me error saying:
Traceback (most recent call last):
File "", line 1, in
nester.print_lol(casu)
AttributeError: module 'nester' has no attribute 'print_lol'
where casu = ['holy day', 'life meaning']
Please tell how to resolve this error

Related

What does "TypeError: 'NoneType' object is not subscriptable" mean?

I am writing a snake game using Pygame in Python3. However, I keep getting this TypeError, not only do I have no idea what it means I have no idea how to fix it
I haven't really attempted anything as I have no idea what it is or how to fix it. This is the code:
def draw(self, surface, eyes=False):
dis = self.w // self.rows
i = self.pos[0]
j = self.pos[1]
The error message I keep getting is:
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "snake.py", line 179, in <module>
main()
File "snake.py", line 175, in main
redrawWindow(win)
File "snake.py", line 127, in redrawWindow
snack.draw(surface)
File "snake.py", line 25, in draw
i = self.pos[0]
TypeError: 'NoneType' object is not subscriptable
This occurs when you try to index through a Nonetype object, e.g.,
>>> x = None
>>> x[0]
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
x[0]
TypeError: 'NoneType' object is not subscriptable
To properly solve your problem, please post the full code or where you set the initial value of self.pos. It seems that you're setting this variable to None.
This appears to be an excerpt from the python tutorial by Tech With Tim: https://techwithtim.net/tutorials/game-development-with-python/snake-pygame/tutorial-1/
It is actually caused by a misplaced return inside of the randomSnack while loop.
Full code here: https://pastebin.com/embed_js/jB6k06hG
If the return is inside the while loop (at line 162 in the pastebin) you get this error. I was following the same tutorial and got this error too.
# When you call (line 145)
snack.draw(surface)
# you are referencing the snack that was created with (line 193)
snack = cube(randomSnack(rows, s), color=(0,255,0))
# The randomSnack function returns an x and y (line 162)
return (x,y)
# that gets passed into the cube object's "start" parameter (line 12)
def __init__(self,start,dirnx=1,dirny=0,color=(255,0,0)):

python pyttsx3 error -- _pickle.UnpicklingError: invalid load key, '\x00'

i am trying to convert text to speech using pyttsx3 in python. but iam getting the error -- _pickle.UnpicklingError: invalid load key, '\x00'.
it worked once. later it didn't
my code
import pyttsx3
engine = pyttsx3.init()
engine.say("I will speak this text")
engine.runAndWait()
error i am receiving is --
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\pyttsx3__init__.py",
line 20, in init
eng = _activeEngines[driverName]
File "C:\ProgramData\Anaconda3\lib\weakref.py", line 137, in
getitem
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
...
File "C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\gencache.py", line 113, in _LoadDicts
version = p.load()
_pickle.UnpicklingError: invalid load key, '\x00'.
python version is 3.7.3 |
pyttsx3 version is 2.71|
pywin32 version is 224
please help
I had this problem as well and fixed it by deleting gen_py in my temp directory.
You can find this folder here:
C:\Users\USERNAME\AppData\Local\Temp\gen_py

I am trying to get the user input in python

This is my code but I am getting an error while compiling in python.
Code
print ("Enter the height :")
feet = int(input("feet:"))
Error
Enter the height :
Traceback (most recent call last):
File "main.py", line 2, in <module>
feet = int(raw_input("feet:"))
NameError: name 'raw_input' is not defined
raw_input is no longer a part of python 3.x
You can use
feet = int(input("Enter height in feet: "))
print(feet)

%s error when trying to put a variable into a string python

Trying to build a "launcher" type thing for youtube-dl(program that lets you download youtube videos), and getting an error. I understand what the error means but it makes no sense as I am(I think) doing exactly what python wants.
This is my code:
import os
import sys
x = input('Enter link for youtube Video you would like to download: ')
ytdp = open('C:\\Games\\ytdp.bat', 'w')
ytdp.write('cd C:\\Users\Jake\Music')
ytdp.write('\n')
ytdp.write('youtube-dl %s')% (x)
ytdp.close()
os.startfile('C:\\Games\ytdp.bat')
sys.exit()
This is the error I get when running the code
Traceback (most recent call last):
File "C:\Users\Jake\Desktop\Youtube video downloader.py", line 8, in <module>
ytdp.write('youtube-dl %s')% (xx)
TypeError: unsupported operand type(s) for %: 'int' and 'str'
ytdp.write('youtube-dl %s')% (xx)
Should be
ytdp.write('youtube-dl %s'% (xx))
Here is some more info on it

googlefinance python3 error

Hi guys I'm using python3 and install googlefinace module(https://pypi.python.org/pypi/googlefinance) and the example says it's works
>>> from googlefinance import getQuotes
>>> import json
>>> print json.dumps(getQuotes('AAPL'), indent=2)
but I type this code using my terminal access python3
>>> from googlefinance import getQuotes
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/googlefinance/__init__.py", line 55
print "url: ", url
^
SyntaxError: Missing parentheses in call to 'print'
so what's the problem please help me
In python3 print syntax contains parenthesis. There for it is giving you syntax error. Use correct print syntax. print (url)

Resources