簡體   English   中英

MySql的Python腳本在0x7f79ce81b440>行中打印出SRE_Match對象,如何獲取它以打印實際的查詢結果?

[英]Python script for MySql prints out SRE_Match object at 0x7f79ce81b440> lines, how can I get it to print actual query results?

我正在搜索acars表中消息中的緯度/經度坐標。 ,方向字符組合(例如N或NW,后跟5位數字),腳本會運行,但是它只給我這樣的代碼:

<_sre.SRE_Match object at 0x7f79ce81b440>
<_sre.SRE_Match object at 0x7f79ce81b440>
<_sre.SRE_Match object at 0x7f79ce81b440>
<_sre.SRE_Match object at 0x7f79ce81b440>
<_sre.SRE_Match object at 0x7f79ce81b440>
<_sre.SRE_Match object at 0x7f79ce81b440>

我想查看腳本的結果(緯度/經度),我嘗試了這些解決方案 ,所有這些解決方案導致終端在我嘗試執行代碼時永遠暫停。 我也從這里嘗試了.search()的建議,結果相同。 從那里嘗試了Findall選項,得到了無窮無盡的PBI D024

我正在使用基於Unix的VM(ScotchBox)在該環境Windows 10 PC的終端上運行mysql

碼:

#!/usr/bin/python

# from: http://www.mysqltutorial.org/python-mysql-query

import mysql.connector
import re
import datetime

# Open connection.  My database is named planes.  If you named yours something else
# then change the database= here. 
db = mysql.connector.connect(host='localhost',database='planes',user='root',password='root')

# prepare a cursor "SELECT * from planes.acars limit 10")
cursor = db.cursor ( )

# Do the query -- the limit is just to keep this small, you will not need it

query = ("SELECT msg_text FROM acars "
"WHERE date_time_stamp BETWEEN %s AND %s")
first_of_june = datetime.date(2016, 6,1)
last_of_june = datetime.date(2016, 6,30)
cursor.execute(query, (first_of_june, last_of_june))
# Fetch rows
data = cursor.fetchone ( )
while data is not None:
    coordinates = re.compile ("N|NW|S|SW|E|NE|S|SE^[0-9]{5}")
    print(coordinates.search(str(data)))
    data = cursor.fetchone()

# close cursor
cursor.close ( )

# close connection
db.close ( )

任何幫助深表感謝!!

“ SRE_Match對象”表示搜索查詢成功命中了搜索模式。

我們可以使用sre_match_object.groups()打印所有匹配的結果

用搜索結果的可打印版本重新編寫while循環:

while data is not None:
    coordinates = re.compile ("N|NW|S|SW|E|NE|S|SE^[0-9]{5}")
    match_obj = coordinates.search(str(data))
    if match_obj:
        print(match_obj.groups())
    data = cursor.fetchone()

-內存

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM