Lajos Kuljo wrote: > Hallo, > ich bin voll neu im Python-Programming, deshalb ist mein Problem > wahrscheinlich trivial: > > Wenn ich die Script > #########################################33 > #! /usr/bin/env python > import MySQLdb > db=MySQLdb.connect(host='localhost', db='photum_0_6_2', user='root', > passwd='thkhgfgd') > c=db.cursor() > c.execute('select person from persons order by person') > tup=c.fetchall() > for a in tup: > print a > ################################################ > ausführe, erhalte ich Dinge wie > ('Dieter',) > ('Hulda',) > .... > > Ich brauche die Klammern, Apostrphe und Kommas nicht (ich will nur die > Inhalte) und kann ich sie nicht loswerden. Versucht habe ich u. a. print > a[2:-3] was nur zwei Klammern bringt. > b=lstrip(a, "(") haut auch nicht hin. > Weiss jemand Rat?
Hab gerade kein MySQL da, aber änder mal for a in tup: print a in for a in tup: print a[0] # Das erste Element des Tupels Dann wird statt des ganzen Tupels nur das erste Element ausgegeben. > P.S. Woher kommen diese Klammern und Apostrophen, vom MySQLdb? Die Klammern und Apostrophe kommen daher, dass tup ein Tupel (http://docs.python.org/lib/typesseq.html) mit einem Element (der Person) ist. Dennis -- http://mail.python.org/mailman/listinfo/python-list