python code d-linked list. however i am getting this error- 'insert_at_begining() missing 1 required positional argument: 'data' here's my code - data-structures

please Resolve the issue i have no idea why I am getting error
class Node:
def __init__(self,perv=None,data=None,Next=None):
self.perv=perv
self.data=data
self.Next=Next
class dll:
def __init__(self):
self.head=None
def insert_at_begining(self,data):
node=Node(None,data,self.head)
self.head=node
def insert_at_end(self,data):
itr=self.head
while itr.next:
itr=itr.Next
node=Node(itr,data,None)
itr.Next=node
def printlist(self):
llstr=''
itr=self.head
while itr:
llstr +=str(itr.data)+'-->'
itr=itr.Next
print(llstr)
Please resolve my problem for linked list . why my code is not working i have not idea

Related

Can you extend Playwright Page() Python sync?

I'm testing out Playwright (Python) and there are a bunch of additional methods that I want to attach to the Page(). I tried inheriting the class but keep getting _init__() missing 1 required positional argument: 'impl_obj' What is this impl_obj and what is the best way to extend methods to their Page()
from playwright.sync_api import Page
class CustomPage(Page):
def __init__(self) -> None:
super().__init__()
def test(self):
print('test')
page = CustomPage()
TypeError: __init__() missing 1 required positional argument: 'impl_obj'

Wrong Number of Arguments in Initialize (given 0, expected 1)

I am following along with a tutorial at:
http://neurogami.com/content/neurogami-10_minutes_to_your_first_Ruby_app/#sidebar4
I have checked and rechecked the code, and I do not understand why ruby is not reading my variable app_map as a valid argument.
I have searched online for similar questions, and they exist, yet I can not understand why this variable is not working. I also am not exactly sure what initialize means, as I am an absolute beginner with Ruby. Any insight would be greatly appreciated.
#!/usr/bin/env ruby
class Launcher
def initialize (app_map)
#app_map = app_map
end
#execute the given file using the associate app
def run file_name
application = select_app file_name
system "#{application} #{file_name}"
end
#given a file, lookup the matching application
def select_app file_name
ftype = file_type file_name
#app_map[ ftype ]
end
#return the part of the file name string after the last '.'
def file_type file_name
File.extname( file_name ).gsub( /^\./, '' ).downcase
end
end
launcher = Launcher.new
end
I am not sure what this code is supposed to run, but I have multiple error messages.
tinyapp.rb:8:in `initialize': wrong number of arguments (given 0, expected 1) (ArgumentError)
from tinyapp.rb:30:in `new'
from tinyapp.rb:30:in `<main>'
In this line, you are instantiating a Launcher:
launcher = Launcher.new
That will call the initialize method on it. That method expects an argument:
def initialize (app_map)
#app_map = app_map
end
In order to resolve the error, you will need to pass in a parameter for the app_map argument. I don't know what it's supposed to actually be here, but that'll look something like this:
launcher = Launcher.new(the_app_map)

TypeError while using positional argument in decorators

I am getting following error while performing a simple decorator code
"decorator_func() missing 1 required positional argument: 'original_func'"
Appreciate if someone points at the issue, thanks.
Here is the code:
def decorator_func(original_func):
def wrapper_func(*args, **kwargs):
return original_func(*args, **kwargs)
return wrapper_func()
#decorator_func() #also tried without calling i.e. #decorater_func
def displayInfo_func(name, age):
print('Display Info func ran with arguments ({}, {})'.format(name))
displayInfo_func
Thanks in advance.
The problem is while returning wrapper function you are calling it and that too without any arguments.
def decorator_func(original_func):
def wrapper_func(*args, **kwargs):
return original_func(*args, **kwargs)
return wrapper_func #instead of wrapper_func()
#decorator_func() #also tried without calling i.e. #decorater_func
def displayInfo_func(name, age):
print('Display Info func ran with arguments ({}, {})'.format(name))

Writing a Logstash GEM gives an error: undefined local variable or method

Trying to build a gem to use it for Logstash as a filter. I'm using classes and methods from a .jar file.
The following is my Jruby code so far:
# encoding: utf-8
require "logstash/filters/base"
require "logstash/namespace"
require 'java'
require 'Processing.jar'
java_import 'process.Process'
class LogStash::Filters::Process < LogStash::Filters::Base
config_name "process"
StringPath = "/path/to/file/"
ML = JavaUtilities.get_proxy_class('processing.Processing')
#ML = ML.new(StringPath)
public
def register
end
public
def filter(event)
event["result"] = #ML.Process("any string.")
filter_matched(event)
end
end
However, it gave me the following error:
←[31mException in filterworker, the pipeline stopped processing new events, plea
se check your filter configuration and restart Logstash. {"exception"=>#<NoMetho
dError: undefined method 'Process' for nil:NilClass>, "backtrace"=>[
"/path/to/logstash-2.0.0/vendor/local_gems
/dda91dc0/logstash-filter-Process-0.5.0/lib/logstash/filters/processing.rb:54:in 'filter'", "/path/to/log
stash-2.0.0/vendor/bundle/jruby/1.9/gems/logstash-core-2.0.0-java/lib/logstash/f
ilters/base.rb:152:in 'multi_filter'", "org/jruby/RubyArray.java:1613:in 'each'"
, "/path/to/logstash-2.0.0/vendor/bundle/j
ruby/1.9/gems/logstash-core-2.0.0-java/lib/logstash/filters/base.rb:149:in 'mult
i_filter'", "(eval):233:in 'filter_func'", "/path/to/logstash-2.0.0/vendor/bundle/jruby/1.9/gems/logstash-core-2.0.0-java/
lib/logstash/pipeline.rb:219:in 'filterworker'", "path/to/log/logstash-2.0.0/vendor/bundle/jruby/1.9/gems/logstash-core-2.0.0
-java/lib/logstash/pipeline.rb:154:in 'start_filters'"], :level=>:error}←[0m
NoMethodError: undefined method 'Process' for nil:NilClass
filter at /path/to/logstash-2.0.0
/vendor/local_gems/dda91dc0/logstash-filter-Process-0.5.0/lib/logstash
/filters/Process.rb:54
multi_filter at /path/to/logstash-2.0.0
/vendor/bundle/jruby/1.9/gems/logstash-core-2.0.0-java/lib/logstash/filters/base
.rb:152
each at org/jruby/RubyArray.java:1613
multi_filter at /path/to/logstash-2.0.0
/vendor/bundle/jruby/1.9/gems/logstash-core-2.0.0-java/lib/logstash/filters/base
.rb:149
filter_func at (eval):233
filterworker at /path/to/logstash-2.0.0
/vendor/bundle/jruby/1.9/gems/logstash-core-2.0.0-java/lib/logstash/pipeline.rb:
219
start_filters at /path/to/logstash-2.0.0
/vendor/bundle/jruby/1.9/gems/logstash-core-2.0.0-java/lib/logstash/pipeline.rb:
154
I tried the following:
.
.
.
public
def filter(event)
StringPath = "/path/to/file/"
ML = JavaUtilities.get_proxy_class('processing.Processing')
#ML = ML.new(StringPath)
event["result"] = #ML.Process("any string.")
filter_matched(event)
end
end
But it gave me the error:
SyntaxError: dynamic constant assignment error.
I tried this in a normal jruby file and everything worked with me. Using Logstash's filter however is what seems to be giving me an issue here.
It seems you are struggling with local and instance variables in Ruby. Please see this blog post for more information.
When you call event["result"] = ML.Process(event["text"]) ruby tries to find a local variable named ML which doesn't exist. Therefore you get undefined local variable or method ML.Process(event["text"]). So, messing around with your variables might solve your problem.
#ML is an instance variable and is available in all methods calling it using #ML or self.ML. Please try this:
public
def filter(event)
event["result"] = #ML.Process(event["text"])
filter_matched(event)
end
Things I stumbled upon:
Where do MLVectorPath and MLStopWordPath come from?
What is StringPath? It is assigned but never used.
Do you have a field text? Otherwise change event["text"] into event["message"].
However, I know neither your Java code nor your logstash configuration so these things may be okay. Please let me know if this helps.

Ruby Koans class or module required

I am getting the following error in Ruby Koans:
AboutHashes#test_accessing_hashes_with_fetch has damaged your karma.
The Master says:
You have not yet reached enlightenment.
I sense frustration. Do not be afraid to ask for help.
The answers you seek...
class or module required
Please meditate on the following code:
/home/s/Downloads/github/rubykoans/about_hashes.rb:26:in `test_accessing_hashes_with_fetch'
The line in question is part of the following method:
def test_accessing_hashes_with_fetch
hash = { :one => "uno" }
assert_equal "uno", hash.fetch(:one)
assert_raise(nil) do
hash.fetch(:doesnt_exist)
end
As you can see, it is asking for a class or module, so I am confused as this is not an error I've encountered before in the Koans.
The problem is on these lines:
assert_raise(nil) do
hash.fetch(:doesnt_exist)
end
The assert_raise test macro expects as its argument a class of Exception. You provided nil.
To skip to the answer, calling fetch on a hash with a key that doesn't exist in the hash will raise a KeyError Exception. So the test should have this:
assert_raise(KeyError) do
hash.fetch(:doesnt_exist)
end

Resources