mirror of
https://github.com/davrot/pytutorial.git
synced 2025-04-19 05:36:42 +02:00
Update README.md
Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com>
This commit is contained in:
parent
3ee1e389a0
commit
e1e98a2a5a
1 changed files with 18 additions and 0 deletions
|
@ -77,3 +77,21 @@ print(list)
|
|||
['Testfile_1.mat', 'Testfile_2.mat', 'Testfile_3.mat', 'Testfile_10.mat']
|
||||
```
|
||||
|
||||
## rsplit
|
||||
|
||||
And maybe you don't want to have the file extensions. Then we can use [rsplit](https://docs.python.org/3/library/stdtypes.html#str.rsplit) on the string.
|
||||
|
||||
```python
|
||||
import glob
|
||||
from natsort import natsorted
|
||||
|
||||
for filename in natsorted(glob.glob("*.mat")):
|
||||
print(filename.rsplit(".", 1)[0])
|
||||
```
|
||||
|
||||
```python console
|
||||
Testfile_1
|
||||
Testfile_2
|
||||
Testfile_3
|
||||
Testfile_10
|
||||
```
|
||||
|
|
Loading…
Add table
Reference in a new issue