对于IndexError:元组索引超出范围---Python感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍python元组的索引,并为您提供关于BeautifulSoup4和请求模块“Inde
对于IndexError:元组索引超出范围--- Python感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍python元组的索引,并为您提供关于BeautifulSoup4 和请求模块“IndexError:列表索引超出范围”、CRMint部署问题-IndexError:元组索引超出范围、CSV文件IndexError:列表索引超出范围、GPT-2 Google Colab IndexError:列出索引超出范围的有用信息。
本文目录一览:- IndexError:元组索引超出范围--- Python(python元组的索引)
- BeautifulSoup4 和请求模块“IndexError:列表索引超出范围”
- CRMint部署问题-IndexError:元组索引超出范围
- CSV文件IndexError:列表索引超出范围
- GPT-2 Google Colab IndexError:列出索引超出范围
IndexError:元组索引超出范围--- Python(python元组的索引)
请帮我。我正在运行一个简单的python程序,它将以tkinter形式显示来自mySQL数据库的数据…
from Tkinter import *
import MySQLdb
def button_click():
root.destroy()
root = Tk()
root.geometry("600x500+10+10")
root.title("Ariba")
myContainer = Frame(root)
myContainer.pack(side=TOP,expand=YES,fill=BOTH)
db = MySQLdb.connect ("localhost","root","","chocoholics")
s = "Select * from member"
cursor = db.cursor()
cursor.execute(s)
rows = cursor.fetchall()
x = rows[1][1] + " " + rows[1][2]
myLabel1 = Label(myContainer,text = x)
y = rows[2][1] + " " + rows[2][2]
myLabel2 = Label(myContainer,text = y)
btn = Button(myContainer,text = "Quit",command=button_click,height=1,width=6)
myLabel1.pack(side=TOP,expand=NO,fill=BOTH)
myLabel2.pack(side=TOP,fill=BOTH)
btn.pack(side=TOP,fill=NONE)
那就是整个程序。
错误是
x = rows[1][1] + " " + rows[1][2]
IndexError: tuple index out of range
y = rows[2][1] + " " + rows[2][2]
IndexError: tuple index out of range
谁能帮我???我在python中是新的。
非常感谢....
BeautifulSoup4 和请求模块“IndexError:列表索引超出范围”
如何解决BeautifulSoup4 和请求模块“IndexError:列表索引超出范围”?
我是使用 python 进行网络抓取的新手,并且在使用我编写的天气网络抓取脚本时遇到了问题。这是整个代码“weather.py”:
#! python3
import bs4,requests
weatherSite = requests.get(''https://weather.com/en-CA/weather/today/l/eef019cb4dca2160f08eb9714e30f28e05e624bbae351ccb6a855dbc7f14f017'')
weatherSoup = bs4.BeautifulSoup(weatherSite.text,''html.parser'')
weatherLoc = weatherSoup.select(''.CurrentConditions--location--kyTeL'')
weatherTime = weatherSoup.select(''.CurrentConditions--timestamp--23dfw'')
weatherTemp = weatherSoup.select(''.CurrentConditions--tempValue--3a50n'')
weatherCondition = weatherSoup.select(''.CurrentConditions--phraseValue--2Z18W'')
weatherDet = weatherSoup.select(''.CurrentConditions--precipValue--3nxCj > span:nth-child(1)'')
location = weatherLoc[0].text
time = weatherTime[0].text
temp = weatherTemp[0].text
condition = weatherCondition[0].text
det = weatherDet[0].text
print(location)
print(time)
print(temp + ''C'')
print(condition)
print(det)
它基本上解析来自“天气频道”的天气信息并将其打印出来。昨天我写这段代码时,它运行良好。但是,我今天试过了,它给了我以下错误:
Traceback (most recent call last):
File "C:\Users\username\filesAndStuff\weather.py",line 16,in <module>
location = weatherLoc[0].text
IndexError: list index out of range
解决方法
替换:
weatherLoc = weatherSoup.select(''.CurrentConditions--location--kyTeL'')
# print(weatherLoc)
# []
weatherLoc = weatherSoup.select(''h1[class*="CurrentConditions--location--"]'')
# print(weatherLoc)
# [<h1>Hamilton,Ontario Weather</h1>]
如您所见,您的后缀 kYTeL
对我来说是不一样的 2_osB
。您需要对类属性 (class*=
) 进行部分匹配(注意 *
)
CRMint部署问题-IndexError:元组索引超出范围
有一个open issue link与您的问题类似。一种解决方法是使用dev分支进行部署。我尝试在终端部署,目前也对我有用。只需确保删除计算机上的master分支并使用dev CLI。
从dev branch在Google Cloud Platform上部署CRMint:
# Double check if a Cloud Project is selected.
[ "$GOOGLE_CLOUD_PROJECT" == "" ] && echo -n 'Input a Cloud Project ID: ' && read project_id && gcloud config set project "$project_id"
# Install the command-line.
bash <(curl -Ls https://raw.githubusercontent.com/google/crmint/master/scripts/install.sh) dev
# Create a stage definition for your environment.
crmint stages create
# Re-run the setup in case new elements are needed.
crmint cloud setup
# Deploy the updated App Engine services.
crmint cloud deploy
CSV文件IndexError:列表索引超出范围
您有两种解决方案,要么将if条件放在“尝试/期望”中,要么在if条件之前添加另一个if:
try:
if "spam" in row[1]:
writer.writerow([row[1],2])
except Exception as e:
print(e)
或者:
if len(row) < 2:
if "spam" in row[1]
...
GPT-2 Google Colab IndexError:列出索引超出范围
如何解决GPT-2 Google Colab IndexError:列出索引超出范围?
我正在使用这个 google colab notebook https://colab.research.google.com/drive/1qxcQ2A1nNjFudAGN_mcMOnvV9sF_PkEb#scrollTo=aeXshJM-Cuaf 来尝试生成文本。当我跑
sess = gpt2.start_tf_sess()
gpt2.finetune(sess,dataset=file_name,model_name=''355M'',steps=2000,restore_from=''fresh'',run_name=''run1'',print_every=10,sample_every=500,learning_rate=1e-5
)
我收到此错误:
WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/gpt_2_simple/src/sample.py:17: where (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.where in 2.0,which has the same broadcast rule as np.where
WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/gpt_2_simple/src/memory_saving_gradients.py:62: get_backward_walk_ops (from tensorflow.contrib.graph_editor.select) is deprecated and will be removed after 2019-06-06.
Instructions for updating:
Please use tensorflow.python.ops.op_selector.get_backward_walk_ops.
Loading checkpoint models/355M/model.ckpt
INFO:tensorflow:Restoring parameters from models/355M/model.ckpt
0%| | 0/1 [00:00<?,?it/s]Loading dataset...
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-6-b6ee97fb7ddf> in <module>()
9 print_every=10,10 sample_every=500,---> 11 learning_rate=1e-5
12 )
1 frames
/usr/local/lib/python3.7/dist-packages/gpt_2_simple/src/load_dataset.py in load_dataset(enc,path,combine)
37 reader = csv.reader(fp)
38 for row in reader:
---> 39 raw_text += start_token + row[0] + end_token + "\n"
40 else:
41 # Plain text
IndexError: list index out of range
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
我们今天的关于IndexError:元组索引超出范围--- Python和python元组的索引的分享已经告一段落,感谢您的关注,如果您想了解更多关于BeautifulSoup4 和请求模块“IndexError:列表索引超出范围”、CRMint部署问题-IndexError:元组索引超出范围、CSV文件IndexError:列表索引超出范围、GPT-2 Google Colab IndexError:列出索引超出范围的相关信息,请在本站查询。
本文标签: