def import_module(name): sys.path.append(os.path.join("script", "libs", "thirdparty", "dns")) mod = __import__(name) components = name.split(".") for comp in components[1:]: mod = getattr(mod, comp) return mod
def import_module(name): sys.path.append(os.path.join("script", "libs", "thirdparty", "dns")) mod = __import__(name) components = name.split('.') for comp in components[1:]: mod = getattr(mod, comp) return mod
def stripParity( self ): nameToks = name.split() lowerToks = [ tok.lower() for tok in nameToks ] lowerToksSet = set( lowerToks ) for parityTests in (parityTestsL, parityTestsR): parityTokensPresent = lowerToksSet.intersection( set( parityTests ) ) if parityTokensPresent: parityToken = parityTokensPresent.pop() idxInName = lowerToks.index( parityToken ) name[ idxInName ] = '' return name return name
def stripParity(self): nameToks = name.split() lowerToks = [tok.lower() for tok in nameToks] lowerToksSet = set(lowerToks) for parityTests in (parityTestsL, parityTestsR): parityTokensPresent = lowerToksSet.intersection(set(parityTests)) if parityTokensPresent: parityToken = parityTokensPresent.pop() idxInName = lowerToks.index(parityToken) name[idxInName] = '' return name return name
>>> a5 = Article(headline='NASA finds intelligent life on Earth') >>> a5.save() >>> p2.article_set.add(a5) >>> Article.objects.values_list(id) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/ilabs/django/django/db/models/manager.py", line 182, in values_list return self.get_query_set().values_list(*args, **kwargs) File "/opt/ilabs/django/django/db/models/query.py", line 585, in values_list _fields=fields) File "/opt/ilabs/django/django/db/models/query.py", line 864, in _clone c._setup_query() File "/opt/ilabs/django/django/db/models/query.py", line 988, in _setup_query self.query.add_fields(self.field_names, True) File "/opt/ilabs/django/django/db/models/sql/query.py", line 1649, in add_fields name.split(LOOKUP_SEP), opts, alias, False, allow_m2m, AttributeError: 'builtin_function_or_method' object has no attribute 'split' >>> Article.objects.values_list(id,headline) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'headline' is not defined >>> Article.objects.values_list('id','headline') [(1L, u'headline1'), (3L, u'NASA finds intelligent life on Earth'), (4L, u'NASA finds intelligent life on Earth')] >>> Article.objects.values_list('id') [(1L,), (3L,), (4L,)] >>> """ p.choice_set.create() p.choice_set.all() p.choice_set.count()