Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 months ago.
Improve this question
Trying to build a Trie branch. I have looked at my indentation and there are no spaces, just tabs for that. I have also looked at other answers which either aren't reproducible or have no effect. What am I doing wrong? I expect the following outcome:
*
trie.py
class Trie:
def __int__(self):
self.root = '*'
main.py
import trie_test
if __name__ == '__main__':
trie = trie_test.Trie()
print(f'trie root: {trie.root}')
Error
line 13, in <module>
print(f'trie root: {trie.root}')
AttributeError: 'Trie' object has no attribute 'root'
def __int__ should be def __init__.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 months ago.
Improve this question
I am trying to create a class object to reverse the given list.
Example: Input = [1,2] and the expected output will be [2,1]
This is my code:
class ListNode(object):
def __init__(self, nums):
self.nums = nums
def tryout (self):
self.nums.reverse()
print(self.nums)
p = ListNode([1,2])
p.tryout
However when I ran my code on Leetcode, it kept giving me the error below
NameError: global name 'Solution' is not defined
ret = Solution().reverseList(param_1)
Line 33 in _driver (Solution.py)
_driver()
Line 43 in <module> (Solution.py)
Can I check if there's any issue with my code? i tried to run on Jupyter and the codes work but it didnt work when i submit to Leetcode
Sounds like Leetcode is expecting your class name to be Solution and your method name to be reverseList
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 12 months ago.
Improve this question
class Acc:
id=121
def _init_(self,id):
self.id=id;
acc=Acc(111)
print(Acc.id)
When I try to run this code , the code runs fine and gives 121 as output when I directly call the data member 'id' using class name Acc and remove the object creation line from the code but the code gives error "TypeError: Acc() takes no arguments" when I include the second last line i.e. the object creation line in my code.
You need to use double underscores when creating constructor method:
...
def __init__(self, id):
...
In your question code you just created a method _init_.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm upgrading code to the latest version of Django Version: 3.1.2
from django.template import Variable, Library
register = Library()
def striplinebreaks(value, arg):
"""
Removes all values of arg from the given string.
"""
safe = isinstance(value, SafeData)
value = value.replace('\n', u'').replace('\r', u'').replace('\t', u'')
if safe and arg != ';':
return mark_safe(value)
return value
register('striplinebreaks')
getting this error
File "/home/sam/code/kpsga/lamusoftware/generic/templatetags/striplinebreaks.py", line 18, in <module>
register(striplinebreaks)
TypeError: 'Library' object is not callable
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
enter code here
class Movie() :
def __init__(self, movie_title, move_storyline , trailer_youtube):
self.title = movie_title
self.storyline = move_storyline
self.poster_image_url = poster_image_url
self.trailer_youtube_url = trailer_youtube
whats the erorr here !
You write self.poster_image_url = poster_image_url but you seem to have forgotten to include poster_image_url in your parameters to __init__. Add it and the number of arguments and parameters will match correctly.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I had an indented block error on line 4:
from SimPy.Simulation import *
from random import uniform
class Car(Process):
def init(self,id):
Process.init(self)
self.id=id
def carDriving(self,driveTime):
...
What might be causing it?
You have to indent classes and functions:
from SimPy.Simulation import *
from random import uniform
class Car(Process):
def __init__(self, id):
Process.init(self)
self.id = id
def carDriving(self, driveTime):
# do something here
pass