Error: Attempt to index local '' (a nil value)
I have an error in line 136 while running this lua code - it is an extension for a personal finance management tool.
ibkr.lua:136: attempt to index local 'summary' (a nil value)
It seems like nil is already assigned to
local if statementContent == nil then
What can I do to fix this?
Code snippet:
do you know?
how many words do you know
See also questions close to this topic
-
In Mongo, If a document I'm saving "Prateek" then I don't want on the next create operation even the "prateek" or "praTEEK", etc is saved
//** If I'm adding a new document with the name: "India", then I don't want that the DB allow another name with the name: "INDIA", "india", "indIA", etc. I'm new and learning, help would be great!!**
// Controller
var Dinosaur = require('../models/dinosaurs'); //addDino module.exports.addDino = (req, res) => { var name = req.body.name; var type = req.body.type; var height = req.body.height; var weight = req.body.weight; var Period = req.body.Period; req.checkBody('name', 'Name is required').notEmpty(); var errors = req.validationErrors(); if (errors) return res.status(400).send({ message: 'Name is Required' }); else { let newDino = { name: name, type: type, height: height, weight: weight, Period: Period } Dinosaur.addDino(newDino, (err, result) => { if (err) { if (err.name) return res.status(409).send({ message: name + ' Already Exist' }); else if (err.url) return res.json({ status: false, error: { url: "Url already exist" }, message: err.url }); else return res.json(err, "Server Error"); } else { return res.status(200).send({ message: "Done" }); } }); } }
// Model
var mongoose = require('mongoose'); //dinosaur schema var DinosaurSchema = mongoose.Schema({ name: { type: String, unique: true }, type: { type: String }, height: { type: Number }, weight: { type: Number }, Period: { type: String } }); var Dinosaur = mongoose.model('dinosaur', DinosaurSchema); //add module.exports.addDino = (query, callback) => { Dinosaur.create(query, callback); }
// GetAll, Already Created a new document with the name "Brachiosaurus"
// > Create, a new create with the first letter lower case "brachiosaurus", Don't want it to be pushed.
-
Update column values based on another dataframe's index
I have the following dataframes:
NUMS = ['1', '2', '3', '4', '5'] LETTERS = ['a', 'b', 'c'] df1 = pd.DataFrame(index=NUMS, columns=LETTERS) a b c 1 NaN NaN NaN 2 NaN NaN NaN 3 NaN NaN NaN 4 NaN NaN NaN 5 NaN NaN NaN df2 = pd.DataFrame([['tom', 10], ['nick', 15], ['james', 14]], index=LETTERS, columns=['col', 'col2']) col col2 a tom 10 b nick 15 c james 14
I'm trying to update
df1
withdf2
so that if the column matches the index fromdf2
, all rows are updated withcol2
:a b c 1 10 15 14 2 10 15 14 3 10 15 14 4 10 15 14 5 10 15 14
I've tried
df1.update(df2['col2'])
, butdf1
does not update.I've also tried
df1.apply(lambda x: df2['col2'].loc[x])
, but I'm getting the following error:KeyError: "None of [Float64Index([nan, nan, nan, nan, nan], dtype='float64')] are in the [index]"
Thank you!
-
How to delete certain number from a list in list using the index in python?
I have a list in a list, and I am trying to delete the third number of each sublist, but every time I am getting an error
TypeError: list indices must be integers or slices, not list
a = [[0.0, 0.0, 0.0], [0.19, 0.36, 0.0], [0.24, 0.42, 0.0], [0.16, 0.08, 0.0], [0.05, -0.57, 0.0] ]
Desired result:-
a_updated = [[0.0, 0.0], [0.19, 0.36], [0.24, 0.42], [0.16, 0.08], [0.05, -0.57] ]
In the second part of my code, I wanted to merge this sublist according to a dictionary shown below, for example, the first value of dictionary:-
1: [1, 2]
shows the merging of 1st and 2nd values i.e.[0, 0, 0.19, 0.36]
.I guess this part of my code is right!
dict_a = { {1: [1, 2], 2: [2, 4], 3: [3, 5], 4: [4, 5] }
my attempt:-
dict_a = { 1: [1, 2], 2: [2, 4], 3: [3, 5], 4: [4, 5]} a = [[0.0, 0.0], [0.19, 0.36], [0.24, 0.42], [0.16, 0.08], [0.05, -0.57]] # first part for i in a: for j in a[i]: del j[2] print(j) #second part a_list = [] list_of_index = [] for i in dict_a: index= [] a_list.append(index) for j in dict_a_updated[i]: print(j-1) index.extend(a_updated[j-1]) print('index',index)
Error output -
file "D:\python programming\random python files\4 may axial dis.py", line 18, in <module> for j in X[i]: TypeError: list indices must be integers or slices, not list
-
FocusLost being called twice
Whenever I use FocusLost on a TextBox, its called twice for some reason
Code:
script.Parent:WaitForChild("CommandBar").Command.FocusLost:Connect(function(enterPressed) print("FocusLost") -- My code end)
FocusLost is printed into my console TWICE. Is this supposed to happen?
-
Read file from project root directory in Lua (for Quarto/Pandoc)
I have a book that I am moving from the Bookdown toolchain to Quarto. Very simply, both tools generate a book from flavoured markdown using Pandoc. Pandoc allows Lua scripts to be used to systematically modify content; I have several of these, and they are essential to the workflow.
One of these scripts automatically generates glossary references whenever it identifies a term in the glossary. The script (glossary.lua) loads a list of terms (from glossary.yml) to do this.
The directory structure is as follows:
. ├── glossary.yml ├── index.qmd ├── ... ├── scripts │ ├── glossary.lua │ └── ... └── contents ├── preface.qmd ├── section1 │ ├── file1.qmd │ └── ... ├── section2 └── ...
The key bits of the glossary.lua:
glossary_file = "glossary.yml" -- Load glossary file local function loadGlossary(filename) file = io.open(filename, "rb") if not file then error("Cannot find the glossary file") else local glossary = file:read("*all") return glossary end end local glossary = exports.eval(loadGlossary(glossary_file))
Previously (in Bookdown) this worked because (as far as I can tell) the script was called from the root directory each time, and the glossary would load without issue. In Quarto however, it seems the script is called from the directory of the file that is being processed, and so fails after loading the
index.qmd
.This can be demonstrated by adding:
cwd = debug.getinfo(1).short_src; print(cwd)
Calling Quarto from the command line in the book root directory then fails after processing the index file:
[1/5] index.qmd scripts/glossary.lua [2/5] content\preface.qmd ../scripts/glossary.lua Error running filter ../scripts/glossary.lua: ../scripts/glossary.lua:600: Cannot find the glossary file
How can I force Lua to read the glossary file from the root directory each time?
-
Add body to luasocket POST request with generic form?
From https://w3.impa.br/~diego/software/luasocket/http.html, there are two ways to make a request, simple and generic. I have gotten the body to work with the simple method. However, when I add an LTN12 source to the generic method, an empty body is sent to the server.
http.request(url [, body]) http.request{ url = string, [sink = LTN12 sink,] [method = string,] [headers = header-table,] [source = LTN12 source], [step = LTN12 pump step,] [proxy = string,] [redirect = boolean,] [create = function] }
This works:
http.request("http://localhost:56218/sendState", "at=" .. AT)
This doesn't:
local reqbody = "hi" local respbody = {} local body, code, headers, status = http.request { url = "http://localhost:56218/sendState", source = ltn12.source.string(reqBody), headers = { ["content-length"] = string.len(reqbody) } sink = ltn12.sink.table(respbody) }
When I try to read the body of the above line of code in my server, it is empty. What am I doing wrong?
-
Null check operator used on a nullsis value flutter
I have problem with null check operator and i using firebase firestore or json model And i using the method to get data user from model
But while i return he give me null check operator help!
-
Is it necessary to use null two times at the end of the code?
I have one question. Help me, please.
I have code in my teaching proggram:
alert(user.address ? user.address.street ? user.address.street.name : null : null);
But I can't understand, why he used "null" two times at the end of the code?
I understand that if
user.adress
- exist, then check whetheruser.address.street
exist, ifuser.address.street
- exist, then check whetheruser.address.street.name exist
, if not alert -null
.But why did he write second
null
? -
SQL Server - NULL vs blank in IF condition - ISNULL vs COALESCE
I am expecting ELSE part to be printed in this case. But it doesn't. It works if the input is blank
''
. But fornull
, it fails. Even withISNULL
andCOALESCE
, it is same. Could you please explain the logic?DECLARE @V_MY_VAR VARCHAR(50) = NULL; IF ISNULL(@V_MY_VAR,'X') = 'HELLO' BEGIN PRINT 'INSIDE IF - '+ @V_MY_VAR; END; ELSE BEGIN PRINT 'INSIDE ELSE - '+ @V_MY_VAR; END;