私は最初の(より大きな)Pythonアプリケーションを開発していますが、いくつかの問題があります。 web.py importを使用してテーブルからエントリを選択しようとしています(後でウェブフロントエンドを使用するので、これを使用しています)。以下web.py select結果は返されませんが、そのリストの長さは(SQLプロットの手動クエリでも結果を返します)
マイ(簡略化)コードである:以下
db = web.database(dbn='mysql', host='xxx', port=3306, user='monitor', pw='xxx', db='monitor')
dict = dict(hostname=nodeName)
#nodes = db.select('Nodes', dict,where="hostName = $hostname")
nodes = db.query('SELECT * FROM Nodes') <-- I have tried both, but have comparable results (this returns more entries)
length = len(list(nodes))
print(length)
print(list(nodes))
print(list(nodes)[0])
パイソンから出力された:
以下0.03 (1): SELECT * FROM Nodes
6 <-- Length is correct
[] <-- Why is this empty?
Traceback (most recent call last):
File "monitor.py", line 30, in <module>
print(list(nodes)[0]) <-- If it is empty I can't select first element
IndexError: list index out of range
は、MySQL出力である:
mysql> select * from monitor.Nodes;
+--------+-------------+
| nodeId | hostName |
+--------+-------------+
| 1 | TestServer |
| 2 | raspberryPi |
| 3 | TestServer |
| 4 | TestServer |
| 5 | TestServer |
| 6 | TestServer |
+--------+-------------+
6 rows in set (0.00 sec)
結論:表がエントリを含んでいます、select/query文は部分的に取得できます(長さは取得されますが、実際の値は取得されません)。 ?)
私は複数の方法を試みましたが、現在私は自分が望むものを手に入れることができません。私は自分のテーブルからデータを選択し、自分のコードで使用したいと思っています。私はこの問題を解決することができたのredditで人々に