I would like to download the CSV file in python ftplib.At that time, the date part of the file name changes every day, so I will search by regular expression and download it.
However, I received the following error, so please tell me how to resolve it.
TypeError: findall() missing 1 required positional argument: 'string'
import ftplib
from logging import getLogger, StreamHandler, Formatter, DEBUG
import re
## FTP Information
HOST='***.ne.jp'
PORT = 21
USER='***'
PASSWORD='***'
DIRECTORY='/***/***'
## Generating Filename to Retrieve
FILE_NAME=(re.findall('item2019????-?.csv'))#←I want to search here by regular expression!
print(FILE_NAME)
I said FILE_NAME=(re.findall('item2019????-?.csv') in re, but I didn't know what to do to make it str type.
Python 3.7.3
Windows 7
jupyter notebook
re.findall
requires at least two arguments: the search pattern
and the search string
.
The code for the question is an error because only the search pattern is specified in the argument.
The sample code below is an excerpt of a simple file listing using ftp.nlst
to find the appropriate file name in a regular expression.
We use re.match
, but the arguments are similar to re.findall
just because the matching method and return value are different.
import re
# items=ftp.nlst(".")# File list returned in array
items=['item201912301913-1.csv', 'item201912301913-1.xlsx', 'item2019 [8 characters are OK-!.csv', 'readme.txt'] #Regular expression sample code
For item in items:
ifre.match(r'item2019.{8}-.\.csv',item):
print(item)
© 2024 OneMinuteCode. All rights reserved.