Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Python中将两个字符串组成一个列表?_Python - Fatal编程技术网

如何在Python中将两个字符串组成一个列表?

如何在Python中将两个字符串组成一个列表?,python,Python,我想在列表类型中包含两个字符串: str1=从tbl中选择某个内容 str2=从tbl2中选择某些内容 我想把它作为我的输出: 列表=[“从tbl中选择某物”,“从tbl2中选择某物”] 因此我可以将每个字符串传递到for循环中: 对于列表中的语句: 做点什么,它就会执行传递的语句 以下是附加上下文: list = [soql_w_compoundedAttributes, soql_wo_compoundedAttributes] for item in list: final_df =

我想在列表类型中包含两个字符串:

str1=从tbl中选择某个内容 str2=从tbl2中选择某些内容 我想把它作为我的输出:

列表=[“从tbl中选择某物”,“从tbl2中选择某物”] 因此我可以将每个字符串传递到for循环中:

对于列表中的语句: 做点什么,它就会执行传递的语句 以下是附加上下文:

list = [soql_w_compoundedAttributes, soql_wo_compoundedAttributes]

for item in list:
  final_df = []
  print(item)
  df = spark.read.format("com.springml.spark.salesforce") \
       .option("login", "https://test.salesforce.com") \
       .option("username", user) \
       .option("password", pass) \
       .option("soql",item) \
       .load()
  final_df.append(df)
sfDF = reduce(DataFrame.unionAll, final_df)
我得到一个错误请求错误的原因,当我查看printitem结果时,我看到两条sql语句同时被传递。有人能解释为什么吗

简单地说:

myList = [str1, str2]
然后:


myList=[str1,str2]?您在第4行回答了自己的问题。您还需要什么?问题是,当我将此列表中的每个项传递到spark dataframe creator时,该项包含两条sql语句,导致请求错误。我想创建的列表可能不适合此任务。请发布错误的完整堆栈跟踪。另外,请张贴您使用的实际代码,包括任何设置。我们需要一个完整的工作示例来帮助您。请参阅上的本指南,然后更新您的问题。另外,出于您的理解,您获得否决票的原因是您的潜在问题似乎是您对spark的称呼方式,而标题或您的初始帖子根本没有说明这一点。如果您在创建列表时确实遇到了问题,那么在您发布的代码中肯定不明显。请确保您发布的代码可以由我们(没有您的上下文的人)运行,并且它会重现您询问的错误或结果。否则,我们无法判断您的代码中出现了什么错误!
print(myList)
str1 = "select something from tbl"
str2 = "select somethingElse from tbl2"

list1 = [str1, str2]

for item in list1:
    #the rest of the code goes here