尝试在GUI中显示cpu使用时出现此错误
cputext = tk.Label(self,text =“CPU”,cpu) ^ SyntaxError:位置参数跟随关键字参数
这是我的代码
x = (2)
while x > 0:
cpu = psutil.cpu_percent(interval=1, percpu=False)
cputext = tk.Label(self, text="CPU", cpu)
cputext.pack()
当我像这样打印时,它可以,但它在控制台中打印
print("CPU Usage :", cpu)
答案 0 :(得分:1)
cpu
当您执行上述操作时,编译器会将Label
视为self
的选项,因为所有选项都以逗号分隔(就像text
,labelText = "CPU Usage : " + str(cpu)
tk.Label(self, text = labelText)
)。
您需要预先设置字符串格式或创建字符串并传递它。
cputext = tk.Label(self, text="CPU Usage : {}".format(cpu))
OR
val conf = new SparkConf(true)
.setAppName("Backup app").setMaster("local[4]")
.set("spark.cassandra.connection.host", "XXXX")
.set("spark.cassandra.auth.username", "XXXX")
.set("spark.cassandra.auth.password", "XXXX")
.setJars(Array("./lib/spark-cassandra-connector-assembly-2.0.2-39-g24f392d.jar"))
val sc = new SparkContext(conf)
val sqlContext = new org.apache.spark.sql.SQLContext(sc);
CassandraConnector(conf).withSessionDo { session =>
sc.cassandraTable("stb", "users").select("salt").where("role = ?", "user").collect().toList.foreach {
user =>
val userSalt = user.getString("salt")
val iterator = session.getCluster.getMetadata.getKeyspace(userSalt).getTables().iterator()
while(iterator.hasNext) {
val tableName = iterator.next().getName
println(keyspace + " " + tableName)
}
}
}