-1

I have output generated by python

(u'PK_LampFactoryTest',)
(u'DF__Thermosta__Enabl__7B264821',)
(u'filestream_tombstone_2073058421',)
(u'RetentionSettings',)
(u'Alarms',)
(u'syscommittab',)

sqlquery = 'SELECT NAME FROM sys.objects' cursor.execute(sqlquery)

    #conn.commit()
    for row in cursor:
        print(row)
bison
  • 739
  • 5
  • 21
A.Ranjan
  • 119
  • 1
  • 2
  • 12
  • 2
    Possible duplicate of [Removing u in list](https://stackoverflow.com/questions/9773121/removing-u-in-list) – bison Aug 23 '18 at 14:02
  • 2
    The u simply indicates that it is unicode – NotSoShabby Aug 23 '18 at 14:02
  • Your `row` is a tuple. If you simply print it, Python will print the `repl` of the tuple, that is, what you would have to type in Python source to create an equivalent data structure. That includes the fact that `row` is a 1-tuple containing a Unicode string. If you don't like the formatting, don't ask `print()` to print the whole data structure. Just print the data you want to see: for example, `print(row[0])`. – BoarGules Aug 23 '18 at 15:11
  • @BoarGules Okay got it . I want to get the details of schema . I mean db structure without any data so if i will print(row[0]) . will it cover all the schema – A.Ranjan Aug 23 '18 at 15:17
  • @A.Ranjan Sorry, that question is DBMS-specific. In other DBMSs that table may be called something else, or may not be a table at all. So I don't know for sure what your query returns or how your code should handle what it gets. I can guess, of course, but in my experience educated guesses are not specific enough for SO. – BoarGules Aug 24 '18 at 08:14

2 Answers2

1

The u simply means that it is unicode. A simple fix for you will be

for row in cursor:
     print(row.encode('ascii', 'ignore'))

But thats without understanding the bigger picture of your code and will just make that print statement look nice (by encoding the string)

NotSoShabby
  • 3,316
  • 9
  • 32
  • 56
0

Try it:

import json, ast

for row in cursor:
    print(ast.literal_eval(json.dumps(row)))
Ala Tarighati
  • 3,507
  • 5
  • 17
  • 34
  • It removed the u but it gave ['DF__PluginApp__Admin__7908F585'] ['ServiceBrokerQueue'] ['LampFactoryTest'] I want only name .no special character . Is there any way . – A.Ranjan Aug 23 '18 at 15:08
  • What do you mean with `no special character`? could you provide an example? – Ala Tarighati Aug 23 '18 at 15:10
  • ['sysrscols'] here I dont want bracket and colon just the name . I have used python script to get the details of schema from sql server – A.Ranjan Aug 23 '18 at 15:14
  • wouldn't that help if you replace `row` by `row[0]` in `print` statement? – Ala Tarighati Aug 23 '18 at 15:19