简体   繁体   中英

Getting empty list when using glob.glob in python to return paths from pc

I use jupyter notebook anaconda, I need to read paths of specific files from folder

paths = glob.glob('E:\master\neural network\mit-bih-arrhythmia-database-1.0.0/*.atr', recursive=True)
paths = glob.glob('E:\master\neural network\mit-bih-arrhythmia-database-1.0.0/*.atr')
**paths = glob.glob('E:\master\neural network\mit-bih-arrhythmia-database-1.0.0\*.atr')**

I try these lines but paths returns empty

You need double backslashes because they're special characters:

paths = glob.glob('E:\\master\\neural network\\mit-bih-arrhythmia-database-1.0.0\\*.atr', recursive=True)

You can also use an r string instead, so that all the characters will be interpreted as normal:

paths = glob.glob(r'E:\master\neural network\mit-bih-arrhythmia-database-1.0.0\*.atr', recursive=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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