I have 2 versions of python installed, but cmake is using older version. How do I force cmake to use the newer version?

You may try either of these depending on what you need: For CMake >= 3.12 According to the changelog: New “FindPython3” and “FindPython2” modules, as well as a new “FindPython” module, have been added to provide a new way to locate python environments. find_package(Python COMPONENTS Interpreter Development) Docs: This module looks preferably for version 3 … Read more

Decorator error: NoneType object is not callable

You should return the wrapper function itself, not its result: def tsfunc(func): def wrappedFunc(): print ‘%s() called’ % func.__name__ return func() return wrappedFunc # Do not call the function, return a reference instead Decorators replace the decorated item with the return value of the decorator: @tsfunc def foo(): # …. is equivalent to: def foo(): … Read more

Pathname too long to open?

Regular DOS paths are limited to MAX_PATH (260) characters, including the string’s terminating NUL character. You can exceed this limit by using an extended-length path that starts with the \\?\ prefix. This path must be a Unicode string, fully qualified, and only use backslash as the path separator. Per Microsoft’s file system functionality comparison, the … Read more

Accessing attribute from parent class inside child class

During the class definition, none of the inherited attributes are available: >>> class Super(object): class_attribute = None def instance_method(self): pass >>> class Sub(Super): foo = class_attribute Traceback (most recent call last): File “<pyshell#7>”, line 1, in <module> class Sub(Super): File “<pyshell#7>”, line 2, in Sub foo = class_attribute NameError: name ‘class_attribute’ is not defined >>> … Read more

Get data from Twitter using Tweepy and store in csv file

This will do the job! I will recommend you to use csv from Python. Open a file and write to it during your loop like this: #!/usr/bin/python import tweepy import csv #Import csv auth = tweepy.auth.OAuthHandler(‘XXXXXX’, ‘XXXXXXX’) auth.set_access_token(‘XXX-XXX’, ‘XXX’) api = tweepy.API(auth) # Open/create a file to append data to csvFile = open(‘result.csv’, ‘a’) #Use … Read more

get the namespaces from xml with python ElementTree

The code for creating a dictionary with all the declared namespaces can be made quite simple. This is all that is needed: import xml.etree.ElementTree as ET my_namespaces = dict([node for _, node in ET.iterparse(‘file.xml’, events=[‘start-ns’])]) You don’t need to use StringIO or open(). Just provide the XML filename as an argument to iterparse(). Each item … Read more