Specifically, I am using:
Python 2.4.3 (# 1, 24 May 2008, 13:47:28) [GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2
I get a raw result of a mysql query Trying column names and boundaries are running the command here:
[root @ machine ~] # mysql -u root -e 'show database;' + -------------------- + + | Database | + -------------------- + + | DBA | | DBB | | DBC | + -------------------- +
I have a problem in python accumulating this value in a variable: Import Subtitled cmd_array = ["mysql", "-u", "root", "-e", "show database"] p = subprocess.open (cmd_array) raw_data = p. Communicate () [0] # console output: # + -------------------- + # database | # + -------------------- + # DBA | #dbb | #dbc # + -------------------- + # # raw_data None P = Sub-process POPIN (CMD_ARE, stdout = subprocess.PIPE) rawData = p.communicate () [0] print raw data #console output: # database #dba #dbb #dbc # # raw data "database \ ndbA \ ndbb \ nndbC"
What is the best way to print beautiful version of mysql output in a python variable?
You -t
:
P = check_output (["mysql", "- u", "root", "-t", "- e", 'show database' '']) print (p) + --------- ----------- + | Database | + -------------------- + + | Information_schema | | Mysql | | Performance_schema | | World | + -------------------- +
You also use check_output
to store the output can do.
No comments:
Post a Comment