Python Forum
pymysql: formating ouput of query
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pymysql: formating ouput of query
#1
i need to compare/diff two lists, one comes from an csv file the other from a mysql query. problem is, they have slightly different formatting.

csv output:
[u'SAG01127_ZPIPDB_HA_LPM', u'AIXHEMADBPRC2_HA', u'AIXJBOSS8C2_HA', u'AIXJBOSS7C2_HA', u'AIXSTP16T1', u'AIXSAPP01C2_HA', u'AIXSTP11S1', u'AIXHYDDBT', u'AIXARVOPROD_LPM', u'AIXDEVOPSTEST02', u'AIXARVOT', u'AIXDX4PRODC2_HA', u'AIXSTP16T2', u'AIXSTP16PRC2_HA', u'SAG01128_ZPIPWEB_HA_LPM', u'AIXAPPL1LSHI', u'AIXEGIZENTW', u'AIXHVVIAB', u'AIXAPPL2ITU5', u'AIXSTP13PRC2_HA', u'AIXDDA3C2_HA', u'AIXSAPP03C2_HA', u'AIXEGIZTEST2', u'AIXZPVEDUC']
mysql output:
[(u'AIXDDA3C1_HA',), (u'SAG0168_AMTSSIGN_HA',), (u'KUG01143_STP14PR_HA',), (u'SAG0183_PFIFET',), (u'AIXSAGRU3',), (u'KUG01154_JBOSS5_HA',), (u'AIXSTP14S5',), (u'SAG01135_STP18PR_HA',), (u'AIXAMTEST2DB',), (u'AIXSTP13T1',), (u'AIXTESTHA2C1_HA_LPM',), (u'KUG01110_WPORTAL1',), (u'AIXDBITU5',), (u'SAG0133_ZPVTTM24',), (u'KUG01175_DABATEST',), (u'AIXSIGHTLINET2',), (u'SAG0194_WNOTES',), (u'KUG01177_WEBPROXY_STP_HA_LPM',), (u'KUG0126_JBOSS-E2',), (u'SAG0137_APACHE_HA',)]
python compare routine
csv_data = unicodecsv.reader(file('ansible_load_file.txt'), encoding='utf-8')
    sql = """SELECT DISTINCT NODE FROM ansible_hosts_view;"""
    c2.execute(sql)
    lresult = c2.fetchall()
    csv_hosts_nim = []
    for idx,row in enumerate(csv_data):
        if not idx:#skip header if any
            continue
        csv_hosts_nim.append(row[0])
    print(csv_hosts_nim)
    diff_to_del = (list(set(lresult).difference(csv_hosts_nim)))
so how do i format the mysql output to "look" more like the csv format?
Reply


Messages In This Thread
pymysql: formating ouput of query - by wardancer84 - Oct-03-2018, 12:06 PM
RE: pymysql: formating ouput of query - by buran - Oct-03-2018, 12:22 PM
RE: pymysql: formating ouput of query - by buran - Oct-03-2018, 12:26 PM
RE: pymysql: formating ouput of query - by buran - Oct-03-2018, 12:30 PM
RE: pymysql: formating ouput of query - by buran - Oct-03-2018, 01:18 PM
RE: pymysql: formating ouput of query - by buran - Oct-03-2018, 02:20 PM
RE: pymysql: formating ouput of query - by buran - Oct-03-2018, 03:32 PM
RE: pymysql: formating ouput of query - by buran - Oct-04-2018, 12:23 PM
RE: pymysql: formating ouput of query - by buran - Oct-04-2018, 01:04 PM
RE: pymysql: formating ouput of query - by buran - Oct-04-2018, 01:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Mysql Syntax error in pymysql ilknurg 4 2,499 May-18-2022, 06:50 AM
Last Post: ibreeden
  Formating generated .data file to XML malcoverc 3 1,434 Apr-14-2022, 09:41 PM
Last Post: malcoverc
  pymysql: insert query throws error wardancer84 12 4,823 Jan-28-2022, 06:48 AM
Last Post: wardancer84
  pymysql can't do SELECT * Pedroski55 3 3,069 Sep-11-2021, 10:18 PM
Last Post: Pedroski55
  propper formating paracelsusx 2 1,965 Jul-16-2021, 09:17 AM
Last Post: perfringo
  Adding graph points and formating project_science 4 2,490 Jan-24-2021, 05:02 PM
Last Post: project_science
  Excel: Apply formating of a sheet(file1) to another sheet(file2) lowermoon 1 2,114 May-26-2020, 07:57 AM
Last Post: buran
  pymysql won't handle some diacritic characters awarren2001AD 0 1,308 Apr-16-2020, 08:58 AM
Last Post: awarren2001AD
  pyMySQL - ROW_NUMBER in SQL statement JayCee 1 2,453 Apr-12-2020, 08:40 PM
Last Post: JayCee
  pyMySQL How do I get the row id JayCee 3 2,806 Apr-12-2020, 08:38 PM
Last Post: JayCee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020