nonetype

Global variable is None instead of instance - Python

主宰稳场 提交于 2021-02-10 22:52:30
问题 I'm dealing with global variables in Python. The code should work fine, but there is a problem. I have to use global variable for instance of class Back . When I run the application it says that back is None which should be not true because the second line in setup() function - 'back = Back.Back()' # -*- coding: utf-8 -*- from flask import Flask from flask import request from flask import render_template import Search import Back app = Flask(__name__) global back back = None @app.route('/')

python bad operand type for unary -: 'NoneType'

不问归期 提交于 2021-02-08 11:16:29
问题 I send you a question because I have a problem on python and I don't understand why. I created a function "mut1" to change the number inside a list (with a probability to 1/2) either in adding 1 or subtracting 1, except for 0 and 9: def mut1 (m): i=np.random.randint(1,3) j=np.random.randint(1,3) if i==1: if 0<m<9: if j==1: m=m+1 elif j==2: m=m-1 elif m==0: if j==1: m=1 if j==2: m=9 elif m==9: if j==1: m=0 if j==2: m=8 print m mut1 function well, for example, if I create a list P1: >>>p1=np

python bad operand type for unary -: 'NoneType'

£可爱£侵袭症+ 提交于 2021-02-08 11:14:48
问题 I send you a question because I have a problem on python and I don't understand why. I created a function "mut1" to change the number inside a list (with a probability to 1/2) either in adding 1 or subtracting 1, except for 0 and 9: def mut1 (m): i=np.random.randint(1,3) j=np.random.randint(1,3) if i==1: if 0<m<9: if j==1: m=m+1 elif j==2: m=m-1 elif m==0: if j==1: m=1 if j==2: m=9 elif m==9: if j==1: m=0 if j==2: m=8 print m mut1 function well, for example, if I create a list P1: >>>p1=np

AttributeError: 'NoneType' object has no attribute 'encode' with lxml-python

前提是你 提交于 2021-01-29 05:04:12
问题 I'm getting AttributeError: 'NoneType' object has no attribute 'encode' error when parsing out some XML patent inventor data. I'm trying to pull the first inventor plus their address infomation into a string as such below: inventor1 = first(doc.xpath('//applicants/applicant/addressbook/last-name/text()')) inventor2 = first(doc.xpath('//applicants/applicant/addressbook/first-name/text()')) inventor3 = first(doc.xpath('//applicants/applicant/addressbook/address/city/text()')) inventor4 = first

Beautiful Soup 4 .string() 'NoneType' object is not callable

丶灬走出姿态 提交于 2021-01-28 19:24:28
问题 from bs4 import BeautifulSoup import sys soup = BeautifulSoup(open(sys.argv[2]), 'html.parser') print(soup.prettify) if sys.argv[1] == "h": h2s = soup.find_all("h2") for h in h2s: print(h.string()) The first print statement (added as a test) works - so I know BS4 is working and everything. The second print statement throws: File "sp2gd.py", line 40, in <module> print(h.string()) TypeError: 'NoneType' object is not callable 回答1: BeautifulSoup's .string is a property, not a callable method, and

AttributeError: 'NoneType' object has no attribute 'astype'

寵の児 提交于 2021-01-24 07:17:31
问题 I encountered the following problem when I reproduce the ESRGAN related program. libpng error: Read Error Traceback (most recent call last): File "/sda/ZTL/B/codes/train.py", line 173, in <module> main() File "/sda/ZTL/B/codes/train.py", line 97, in main for _, train_data in enumerate(train_loader): File "/root/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 637, in __next__ return self._process_next_batch(batch) File "/root/anaconda3/lib/python3.6/site-packages

AttributeError: 'NoneType' object has no attribute 'astype'

你。 提交于 2021-01-24 07:14:59
问题 I encountered the following problem when I reproduce the ESRGAN related program. libpng error: Read Error Traceback (most recent call last): File "/sda/ZTL/B/codes/train.py", line 173, in <module> main() File "/sda/ZTL/B/codes/train.py", line 97, in main for _, train_data in enumerate(train_loader): File "/root/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 637, in __next__ return self._process_next_batch(batch) File "/root/anaconda3/lib/python3.6/site-packages

Pandas/Numpy NaN None comparison

六月ゝ 毕业季﹏ 提交于 2020-12-30 07:21:08
问题 In Python Pandas and Numpy, why is the comparison result different? from pandas import Series from numpy import NaN NaN is not equal to NaN >>> NaN == NaN False but NaN inside a list or tuple is >>> [NaN] == [NaN], (NaN,) == (NaN,) (True, True) While Series with NaN are not equal again: >>> Series([NaN]) == Series([NaN]) 0 False dtype: bool And None : >>> None == None, [None] == [None] (True, True) While >>> Series([None]) == Series([None]) 0 False dtype: bool This answer explains the reasons

Pandas/Numpy NaN None comparison

回眸只為那壹抹淺笑 提交于 2020-12-30 07:18:14
问题 In Python Pandas and Numpy, why is the comparison result different? from pandas import Series from numpy import NaN NaN is not equal to NaN >>> NaN == NaN False but NaN inside a list or tuple is >>> [NaN] == [NaN], (NaN,) == (NaN,) (True, True) While Series with NaN are not equal again: >>> Series([NaN]) == Series([NaN]) 0 False dtype: bool And None : >>> None == None, [None] == [None] (True, True) While >>> Series([None]) == Series([None]) 0 False dtype: bool This answer explains the reasons

Pandas/Numpy NaN None comparison

纵饮孤独 提交于 2020-12-30 07:17:14
问题 In Python Pandas and Numpy, why is the comparison result different? from pandas import Series from numpy import NaN NaN is not equal to NaN >>> NaN == NaN False but NaN inside a list or tuple is >>> [NaN] == [NaN], (NaN,) == (NaN,) (True, True) While Series with NaN are not equal again: >>> Series([NaN]) == Series([NaN]) 0 False dtype: bool And None : >>> None == None, [None] == [None] (True, True) While >>> Series([None]) == Series([None]) 0 False dtype: bool This answer explains the reasons