Python csv文件查找
在一个项目中,按城市名称向我们提供了三个csv文件。Project需要编写一个交互式代码,如果用户指定了一个城市,则会显示该城市的完整路径名Python csv文件查找,python,csv,Python,Csv,在一个项目中,按城市名称向我们提供了三个csv文件。Project需要编写一个交互式代码,如果用户指定了一个城市,则会显示该城市的完整路径名 def get_city(): '''Asks the user for a city and returns the filename for that city's bike share data. Args: none. Returns: (str) Filename for a city's
def get_city():
'''Asks the user for a city and returns the filename for that city's bike share data.
Args:
none.
Returns:
(str) Filename for a city's bikeshare data.
'''
city = input('\nHello! Let\'s explore some US bikeshare data!\n'
'Would you like to see data for Chicago, New York, or Washington?\n')
我假设您有一个特定的文件夹或文件夹列表,其中存储了所有文件。因为它们的名称类似于城市,这应该是用户输入,所以您只需要将路径与用户输入和文件扩展名结合起来
def return_path(city):
fname = city.lower() + '.csv'
path = os.path.join(path, fname)
return path
如果有路径列表,可以使用for循环搜索它们。如果要在文件夹中搜索给定的名称,或者要对文件内容执行任何操作,请指定您的问题。您的问题是什么?欢迎使用SO。不幸的是,这不是一个讨论论坛或教程。请花点时间阅读该页面上的链接和其他链接。花些时间练习这些例子。它将让您了解Python提供的帮助您解决问题的工具。