Я считаю, что вы хотите что-то вроде этого:
список атрибутов от объекта
blockquote>По моему скромному мнению, в функции
dir()
может выполнить эту работу за вас. Взято из выводаhelp(dir)
в вашей оболочке Python:dir (...)
dir([object]) -> list of strings
Если вызывается без аргумента, верните имена в текущей области .
Else, верните алфавитный список имен, содержащий (некоторые) атрибуты данного объекта и атрибуты, доступные из него.
Если объект поставляет метод с именем
__dir__
, он будет использоваться; в противном случае используется логика dir () по умолчанию и возвращает:blockquote>
- для объекта модуля: атрибуты модуля.
- для объекта класса: его атрибуты и рекурсивно атрибуты его баз.
- для любого другого объекта: его атрибуты, атрибуты его класса и рекурсивно атрибуты базовых классов его класса.
Например :
$ python Python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a = "I am a string" >>> >>> type(a) <class 'str'> >>> >>> dir(a) ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
Поскольку я проверял вашу проблему, я решил продемонстрировать свой ход мысли с лучшим форматированием вывода
dir()
.dir_attributes .py (Python 2.7.6)
#!/usr/bin/python """ Demonstrates the usage of dir(), with better output. """ __author__ = "ivanleoncz" obj = "I am a string." count = 0 print "\nObject Data: %s" % obj print "Object Type: %s\n" % type(obj) for method in dir(obj): # the comma at the end of the print, makes it printing # in the same line, 4 times (count) print "| {0: <20}".format(method), count += 1 if count == 4: count = 0 print
dir_attributes.py (Python 3.4.3)
#!/usr/bin/python3 """ Demonstrates the usage of dir(), with better output. """ __author__ = "ivanleoncz" obj = "I am a string." count = 0 print("\nObject Data: ", obj) print("Object Type: ", type(obj),"\n") for method in dir(obj): # the end=" " at the end of the print statement, # makes it printing in the same line, 4 times (count) print("| {:20}".format(method), end=" ") count += 1 if count == 4: count = 0 print("")
Надеюсь, что я внесла свой вклад:).
Это даст вам результат, который вы ищете:
SELECT
yourTable.ID,
regexp_split_to_table(yourTable.fruits, E',') AS split_fruits
FROM yourTable
EDIT: Исправлено регулярное выражение.