以下是source code to pyspark's (v1.1.1) addPyFile。 (官方pyspark文檔中1.4.1的源代碼鏈接在我寫這篇文章時被破壞)
它返回None
,因爲沒有return
聲明。另請參見:in python ,if a function doesn't have a return statement,what does it return?
所以,如果你當然做sc2 = sc.addPyFile("mymodule.py")
sc2
將是無因.addPyFile()
不返回任何東西!
相反,只需撥打sc.addPyFile("mymodule.py")
並繼續使用sc
爲SparkContext
def addPyFile(self, path):
635 """
636 Add a .py or .zip dependency for all tasks to be executed on this
637 SparkContext in the future. The C{path} passed can be either a local
638 file, a file in HDFS (or other Hadoop-supported filesystems), or an
639 HTTP, HTTPS or FTP URI.
640 """
641 self.addFile(path)
642 (dirname, filename) = os.path.split(path) # dirname may be directory or HDFS/S3 prefix
643
644 if filename.endswith('.zip') or filename.endswith('.ZIP') or filename.endswith('.egg'):
645 self._python_includes.append(filename)
646 # for tests in local mode
647 sys.path.append(os.path.join(SparkFiles.getRootDirectory(), filename))
您正在嘗試兩種不同的星火背景? – eliasah
你想做什麼? – eliasah
@eliasah:將python redis模塊添加到不同的工作人員。 – kamalbanga