目前,我使用它来下载文件,但它将它们放在运行它的同一文件夹中,但是如何将下载的文件保存到我选择的另一个目录中.
r = requests.get(url)
with open('file_name.pdf', 'wb') as f:
f.write(r.content)
Run Code Online (Sandbox Code Playgroud) 我需要使用url下载文件-> https://readthedocs.org/projects/django/downloads/pdf/latest/
该URL重定向到带有.pdf文件的URL。
如何使用python使用该网址下载该文件?
我试过了 :-
import urllib
def download_file(download_url):
web_file = urllib.urlopen(download_url)
local_file = open('some_file.pdf', 'w')
local_file.write(web_file.read())
web_file.close()
local_file.close()
if __name__ == 'main':
download_file('https://readthedocs.org/projects/django/downloads/pdf/latest/')
Run Code Online (Sandbox Code Playgroud)
但这不起作用
我写了这段代码来合并两个排序的数组.所需的输出是:
Merged array:0 1 2 3 4 5 6 7 8 9 10 11 12
Run Code Online (Sandbox Code Playgroud)
我正在使用gcc(Ubuntu 5.4.0-6ubuntu1~16.04.4)5.4.0 20160609来编译我的代码.
问题是,当我执行a.out文件时有时会得到所需的输出,但在其他情况下,光标会一直闪烁并且没有显示结果.为什么会这样?我的代码有问题吗?
#include<stdio.h>
#include<stdlib.h>
int main(void){
//change arrays as per your need but it should be sorted
int a[] = {1,2,3,7,8};
int b[] = {0,3,5,6,9,10,11,12};
int m =sizeof(a) / sizeof(int);
int n =sizeof(b) / sizeof(int);
int index=0, j=0, k=0;
int size = m + n;
int array[size];
while(index < size) {
while(a[j] < b[k] && j<m ){
array[index] = a[j];
++index;
++j;
} …Run Code Online (Sandbox Code Playgroud)