Questions tagged [nonetype]
Nonetype refers to an object or type whose value is null (none).
1,213
questions
1
vote
1
answer
19
views
Edit regex to recognise very short street name or number for Python 2.7 script and avoid fatal attribute error
I have a little script in Python 2.7 with regex that recognises when a street or avenue name is in a string. However it doesn't work for street names of only two letters (OK that's very rare) OR ...
0
votes
1
answer
55
views
'NoneType' object is not iterable when working with API Pagination
I am trying to create some code that establishes an API connection, iterates through all the pages, and returns a list of data. The frustrating thing is that this code sometimes works without any ...
-2
votes
1
answer
22
views
python: Pick the x amount of biggest numbers from list, but I get TypeError - NoneType
I'am new to python. I tried to write this code but I always get a TypeError.
This is the task:
finds the length_subset biggest values in a
Parameters
a:
array to find the biggest values in
...
1
vote
2
answers
36
views
Adding None to PySpark array
I want to create an array which is conditionally populated based off of existing column and sometimes I want it to contain None. Here's some example code:
from pyspark.sql import Row
from pyspark.sql ...
0
votes
2
answers
63
views
Replace None in pandas data frame with Null
I have a pandas dataframe and I am getting None for many values. I need to write it to SQL server DB and want to update it with Null. How can i do that?
I cannot use df.to_sql to write to DB, it is ...
-1
votes
0
answers
26
views
Flask request.json.get returning nan instead of NULL [closed]
I have been using Flask request.json.get to return POST parameters to my application, but I believe on a recent update from Flask or possibly from upgrading another package it is now returning nan ...
0
votes
1
answer
20
views
Integrate Class
So I have been trying to create an integrate class for an assignment and while I have gotten a simple skeletal structure for the functions within said class, I keep on getting a None result, which ...
0
votes
0
answers
24
views
Adding integers together from a list [duplicate]
Thanks for taking the time to help as I'm new to Python.
I'm trying to add random values together from a list. Not just any random values. I'm sorting the values, then trying to add the last 3 digits ...
-3
votes
1
answer
31
views
Using None in a Python if conditional
When I do:
if breadcrumb is not None:
attrdict['breadcrumb'] = breadcrumb[0]
I get:
TypeError: 'NoneType' object is not subscriptable
The whole point of the conditional was to skip ...
0
votes
0
answers
85
views
T5Tokenizer and T5ForConditionalGeneration producing error in Databricks
I am running my code in a Databricks notebook environment.
Error 1:
To get a tokenizer returned, I am running the following code:
tokenizer = T5Tokenizer.from_pretrained("t5-base")
But I ...
0
votes
0
answers
10
views
What is the correct way to do a type hint for an argument that has to be either an int or a None? [duplicate]
I want to create a function which takes one argument, which has to be either an int or a None object.
I did the following, which works:
from typing import Union
def f(x: Union[int, type(None)]):
...
1
vote
1
answer
67
views
Checking for non-None values
Let's say we have two integer or string values and we would like to select the value out of those two which is not None.
val1 = None
val2 = 100
The mainstream or conventional way of doing this would ...
0
votes
1
answer
34
views
how to sum values of a csv column ,that are type="None"
I do the sum of values of a column of a CSV file, the types of the values are "None", I used a filter, before summing the values of the column but I got this error:TypeError: unsupported ...
1
vote
0
answers
19
views
Why does it ask me that the keys are of type text if they already are?
import os
import tweepy as tw
consumer_key=os.environ.get("CONSUMER_KEY")
consumer_secret=os.environ.get("CONSUMER_SECRET")
access_token=os.environ.get("ACCESS_TOKEN")
...
-1
votes
0
answers
45
views
argument 1 has unexpected type 'NoneType'
first of all, I have tried this solution but if I do so, it doesn't work.
What I want to do is clear the input box when I click "File" > "New file":
Picture of the App
The ...
0
votes
0
answers
11
views
Scikit optimize with objective function returning None
Can the expensive objective function that is being passed to scikit-optimize return None (NA/NaN/...) type? I would need to optimize simulation parameters and sometimes, the simulation can return a ...
-1
votes
2
answers
42
views
AttributeError: 'NoneType' object has no attribute 'upper' when fetching Reddit darkmode
Im trying to fetch Reddit's dark mode but resulting in this error in the title, here's my current code;
if getenv("THEME").upper() == "DARK":
cookie_file = open('./...
2
votes
1
answer
34
views
Append Glitch Not Recognizing Inputs
I was making a slope calculator when I ran into a problem. I took their inputted points, stripped the parentheses, and split at the comma. It gave me an error about not recognizing the term "...
0
votes
1
answer
39
views
How do I pass a 'NoneType' object has no attribute 'parts' error [extracting data from a midi database]? [duplicate]
Where do I put "try:[...]except"? Or how do I pass/ignore/exclude files that return an AttributeError 'NoneType' object has no 'xyz'? I have a huge database of midis and it will make it half ...
1
vote
1
answer
43
views
Get dictionary keys for given batched values - Python
I defined a dictionary A and would like to find the keys given a batch of values a:
def dictionary(r):
return dict(enumerate(r))
def get_key(val, my_dict):
for key, value in my_dict.items():
...
0
votes
0
answers
36
views
Code Works Sometimes, Other Times Gives: TypeError: cannot unpack non-iterable NoneType object
I am trying to write a random forest algorithm, but I am having trouble making a decision tree. The code runs fine some of the time, but then it will give me a TypeError: cannot unpack non-iterable ...
-3
votes
1
answer
22
views
didnt work return statement. Instead of value it return None in python? [duplicate]
i create a function for binary search and i find the position of searched element but i cannot get the value through the return statement instead of the value it return null
def binary_search(array,...
0
votes
1
answer
50
views
Pyomo: TypeError: argument of type 'NoneType' is not iterable
I tried to maximize a non-linear function with pyomo in Python over positive integers y. When it comes to the optimization. The objective function was approximized, because it contained the pdf and ...
1
vote
1
answer
41
views
Why do print statements sometimes fail to print in Pytorch?
I am working with the pycocotools library, and with an implementation of DETR (deformable transformers for object detection).
I am debugging a portion of the code which makes a call to the loadRes ...
0
votes
0
answers
17
views
Getting "NoneType object is not subscriptable" when creating fasta file
I am trying to create a multiple alignment fasta file from an user search of a gen and a sequence. To create this fasta file I am using the following:
for seq in fasta_result:
ofile.write(&...
-1
votes
3
answers
30
views
Bypassing NoneType in a list comprehension
To work around when there is no value x.competition.name, I tried to use is not None:
'competition': [x.competition.name if x.competition.name is not None else '-' for x in a]
But the error still ...
1
vote
1
answer
376
views
AttributeError: 'NoneType' object has no attribute 'split' SMOTE
I'm resampling some data using SMOTE and getting an error like this:
AttributeError: 'NoneType' object has no attribute 'split'
my code :
sm = SMOTE(random_state = 42)
X_train_resampled, ...
1
vote
1
answer
37
views
How can I fix this specific instance of a TypeError in python
# importing necessary libraries & my own library of functions called dependancies:
from tkinter import N
import Dependancies
import pandas as pd
import time
from pathlib import Path
import os
#...
0
votes
1
answer
50
views
Method returns NoneType object
Classes and Objects in Python
I'm creating a bot in discord.py, and I have a class which stores all the information related to the user, like name, settings, preferences etc. When I try to get the ...
0
votes
0
answers
50
views
My plt animation doesn't work: "'NoneType' object has no attribute 'canvas'"
I'm trying to simulate the segregation process in a city for a school project. I've managed to plot the city when initialized and after segregation, but I don't manage to create the animation showing ...
0
votes
1
answer
67
views
M2M100Tokenizer.from_pretrained 'NoneType' object is not callable
I have the following chunk of code from this link:
from transformers import M2M100ForConditionalGeneration, M2M100Tokenizer
hi_text = "जीवन एक चॉकलेट बॉक्स की तरह है।"
chinese_text = "...
0
votes
1
answer
46
views
Python3 python CAN notifier - TypeError: 'NoneType' object is not callables
I'm trying to implement a notifier for for the python-can (4.0.0) following the exact same approach as in here but I'm getting the following error:
Exception in thread can.notifier for bus "...
1
vote
1
answer
50
views
Python, __exit__ method should it use return False or no return at all
What's the preferred way and why for __exit__ method when it comes to returning value?
Should I write return False or no return at all since that will return None, I think behaviour in both cases will ...
0
votes
0
answers
29
views
Hyperopt NoneType object has no attribute 'randint'
I'm facing some problems using hyperopt
# Here we use a single parameter grid, and execute just one iteration
space = _set_space(parameters_grid)
trials = hyperopt.Trials()
best_params = hyperopt....
0
votes
0
answers
19
views
AttributeError: 'NoneType' object has no attribute 'gene_doc'
I have an async method
async def test_doc(item_id, order_id, acc_number):
test_doc = None
try:
test_doc = TestGene(item_id, order_id, acc_number)
gene = test_doc.determine_gene(...
0
votes
0
answers
36
views
None difference for Python versions
I've read a lot about Python versions differences but never met those
Python 2.7.18 (default, Mar 8 2021, 13:02:45)
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits&...
0
votes
0
answers
15
views
My torch.backward/torch.grad functions are coming back as 'none' and I don't know why (gradient comes back as 'NoneType') [PYTHON]
I am trying to find the Lotka-Volterra ODE PARAMETERS(alpha,beta,gamma,delta) from a set of (x , y, t) data (full code at the bottom)
Lotka-Volterra Equations
I believe the error is at gradLoss=loss....
1
vote
1
answer
757
views
AttributeError 'Nonetype' object has no attribute. But i check for Nonetype
I get AttributeError: 'NoneType' object has no attribute 'rstrip'
So I added if clist is not None: But I keep getting the same error. Why?
if clist is not None:
result = [
[name, clist....
0
votes
2
answers
340
views
I am getting a "'NoneType' object is not subscriptable" when trying to bring in data from a URL
Here is my code:
#Import libraries
import os
import pandas as pd
import requests
import matplotlib.pyplot as plt
import numpy as np
from datetime import date
import matplotlib.ticker as ticker
# ...
1
vote
0
answers
29
views
What is the cannot unpack non-iterable error here?
choice2 = input("Encrypt(e) or Decrypt(d): ")
cipherlist = []
keylist= []
key = input("Input a key: ")
key = key + 'abcdefghijklmnopqrstuvwxyz'
...
0
votes
1
answer
25
views
Is it possible to set the result value of 'None < None' to False in python?
I want to get that result when I write only None < None in the editor without using try, except. Of course, I tried to redefine the __lt__ function of None, but an error occurred. Is there any good ...
0
votes
0
answers
23
views
logo':logo.image_tag(self) AttributeError: 'NoneType' object has no attribute 'image_tag'
from . import models
def get_logo(request):
logo=models.AppSetting.objects.first()
data={
'logo':logo.image_tag(self)
}
return data
`
This is my coding part here it is ...
0
votes
0
answers
19
views
File "Solution.py", line 41, in <module> fptr.write(result + '\n') TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
def getPhoneNumber(s):
# Write your code here
ref_dict = {
'one' : '1',
'two' : '2',
'three' : '3',
'four' : '4',
'five' : '5',
'six' : '6',
...
1
vote
3
answers
131
views
nested dictionary TypeError: 'NoneType' object is not subscriptable
I have a dictionary - questions.
the key is a number and the value is another dictionary. here is an example of the structure:
questions = {
2313: {"question": "How much is 2+2&...
0
votes
1
answer
59
views
How to pass a Tree as an argument in a function?
I want to pass a Tree as an argument in a function. In fact, what I want is to pass an object from the class Node as an argument to my function evaluate.
This is the code.
PLUS = "+"
...
0
votes
0
answers
146
views
TypeError: 'NoneType' object is not callable, how can i solve this error?(I'm a beginner)
import numpy as np
import matplotlib.pyplot as plt
import os
from PIL import Image
import tensorflow as tf
import keras
from keras.models import Model
from keras.layers import Conv2D, MaxPooling2D, ...
0
votes
1
answer
30
views
Interpolation value can't be multiplied, show Nonetype
I have a written a interpolation function. but when I called the function, it works perfectly. but when the obtained value is multiplied, it shows TypeError: unsupported operand type(s) for *: '...
-1
votes
1
answer
57
views
scrapy none type object is not subscriptable
I am trying to extracting json data from a website by making a post request I am getting all the data problem is some of the json data fields are None e.g {'tax_history': None}
and I am aware of the ...
1
vote
1
answer
426
views
TypeError: argument of type NoneType is not iterable in python
I currently have a function that iterates through a dictionary of contract addresses and then adds them into the allowedTokens and then set their price feed.
I set the values of the dictionary in a ...
0
votes
0
answers
35
views
How to remove specific data from a dataframe and append the filtered data into a new dataframe in python?
I have a large data frame of thousands of words with its corresponding values
0 Keyword Value
0 ('approach', 0.08186274413288347) ('approach' 0....