Created
February 22, 2019 03:35
-
-
Save ayuLiao/fd61699223b06c27e32ddfe071b7ef47 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| In [1]: import glob | |
| In [2]: %pwd | |
| Out[2]: u'/Users/ayuliao/Desktop/workplace/9377code/agent_flask' | |
| In [3]: f1 = glob.glob(r'/Users/ayuliao/Desktop/workplace/9377code/agent_flask') #没有使用正则,则什么都不返回 | |
| ...: | |
| In [4]: print(f1) | |
| ['/Users/ayuliao/Desktop/workplace/9377code/agent_flask'] | |
| In [5]: f1 = glob.glob(r'/Users/ayuliao/Desktop/workplace/9377code/agent_flask/* | |
| ...: .py') # 返回绝对路径 | |
| In [6]: print(f1) | |
| ['/Users/ayuliao/Desktop/workplace/9377code/agent_flask/filelock.py', | |
| '/Users/ayuliao/Desktop/workplace/9377code/agent_flask/agent_test.py', | |
| '/Users/ayuliao/Desktop/workplace/9377code/agent_flask/agent.py', | |
| '/Users/ayuliao/Desktop/workplace/9377code/agent_flask/app.py', | |
| '/Users/ayuliao/Desktop/workplace/9377code/agent_flask/agentconf.py'] | |
| In [7]: f2 = glob.glob(r'*.py') #只会返回相对路径 | |
| In [8]: print(f2) | |
| ['filelock.py', 'agent_test.py', 'agent.py', 'app.py', 'agentconf.py'] | |
| In [9]: f3 = glob.iglob(r'*.py') #返回一个生成器,用法与glob一致 | |
| In [10]: f3 | |
| Out[10]: <generator object iglob at 0x108648870> | |
| In [11]: print([i for i in f3]) | |
| ['filelock.py', 'agent_test.py', 'agent.py', 'app.py', 'agentconf.py'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment