我有一个 Python Web 应用程序,为了界面方便,它在 Web 浏览器中本地运行,处理用户选择的文件并保存处理后的数据。我需要添加在选择文件的同一文件夹中创建新子目录的功能(即,如果文件是path/fname.txt,我需要创建path/fname/,可以在其中放置处理后的数据)。如何访问该文件的路径?
在其他项目中,我单独询问了路径,但这很笨拙,我不想让用户为每个文件执行这个无关的步骤。
@app.route('/getthefile', methods=['POST'])
def getthefile():
file = request.files['myfile']
filename = secure_filename(file.filename)
new_path = os.path.abspath(filename)
# gives me the wrong path
Run Code Online (Sandbox Code Playgroud) 我正在尝试从CSV数据集构建d3.js热图.使用d3.csv导入后,数据如下所示:
[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, columns: Array(11)]
Run Code Online (Sandbox Code Playgroud)
每个对象的位置如下:
Object {0: "0.934999642", 1: "0.1031451091", 2: "0.077435557", 3:
"0.129644215", 4: "0.666245944", 5: "0.133087829", 6: "0.113218775", 7:
"0.120796943", 8: "0.257501418", 9: "0.840916491", "": "0"}
Run Code Online (Sandbox Code Playgroud)
我一直在尝试按原样使用数据,但是for循环太慢(真实数据集有1300个值),并且尝试嵌套结构不起作用,因为d3的data()函数只能接受数组.
像这样:
var row = svg.selectAll(".rows")
.data(data)
.enter()
.append("rect")
[etc]
d3.selectAll(".blocks")//nested data
.data(function(d) {//d has no length property, so this line fails
return d;
})
.enter()
.append("rect")
[etc]
Run Code Online (Sandbox Code Playgroud)
如何将对象数组转换为数组数组?或者,有没有办法成功使用对象数组?另外,有没有理由说它不是直接来自数组数组中的CSV而不是这个奇怪的对象数组?数据是在Python的Pandas中导出并导出的,如果这有所不同,我们可以在那里进行调整.
谢谢.