繁体   English   中英

如何在此代码中使用 Input() function 更改文件名? 此代码的任何正确形式

[英]how can i change the file name using Input() function in this code ? any correct form of this code

此代码的任何正确形式此代码形成 geeksforgeeks

代码执行正确没有

这一行“与 open("/content/gdrive/My Drive/xyz.exe "wb") 作为文件:"

但是如何使用 input() 函数来改变这个 xyz.exe

import requests 
file_url = "xyz.exe"

r = requests.get(file_url, stream = False) 

file_name = input("Enter your file name")

with open("/content/gdrive/My Drive/"str(file_name)"wb") as file: 
    for block in r.iter_content(chunk_size = 1024): 
        if block: 
            file.write(block) 

Python 2.7

new_file_name = raw_input("Enter file name:")
with open("path/to/{}".format(new_file_name), "wb") as f:

Python 3

new_file_name = input("Enter file name:")
with open(f"path/to/{new_file_name}", "wb") as f:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM