These three methods of personal feeling is very practical, and very similar, so put together:
| Split && Join |
|
|
|
| |
Split |
Note 1 |
NOTE 2 |
| |
Function: Splits a string; Returns a list |
1. You can split characters that do not exist in the string and return to the full list: string = ' Sadhjfhdj ' Print String.Split ("5") >>>[' SADHJFHDJ '] |
But you can't leave the separator blank! |
| |
|
2. Can be used in conjunction with various methods of the list, such as slicing |
|
| |
|
3. You can add a parameter to determine how many splits are made: string = ' 121212121 ' Print String.Split ("2", 1) >>>[' 1 ', ' 1212121 '] |
|
| |
|
|
|
| |
Os.path.split () |
Ex:
Import OS
Print Os.path.split ("C://documents and Xxx/junzhou/what/file.txt")
>>> (' c://documents and Xxx/junzhou/what ', ' file.txt ') |
|
| |
Function: Divides the path from the file name; returns a tuple |
|
|
| |
|
|
|
|
join |
ex: A = (' A ', ' B ', ' C ', ' d ') print ". Join (a) >>>ABCD b = [' 1 ', ' 2 ', ' 3 ', ' 4 '] print '. Join (b) >>>123456 C = ' 123456 ' print '. '. Join© >>>1.2.3.4.5.6 |
|
| |
Os.path.join () |
Ex print os.path.join (' windows\temp ', ' c:\\ ', ' csv ', ' test.csv ')
>>>c:\csv\test.csv
Print Os.path.join (' c:\\ ', ' csv ', ' test.csv ')
>>>c:\csv\test.csv |
Parameters before the first absolute path will be ignored! |
Append
Append is the list method that will add elements to the list tail:
A = [' 1 ', ' 2 ', ' 3 ']
A.append (4)
Print a
>>>[' 1 ', ' 2 ', ' 3 ', ' 4 ']
Here's a little bit to do with the join: Append is for list, so no matter what list can be implemented, and join only for the STR type, if you need to connect to a list, each item in this list must be str type
Such as:
A = [1,2,3,4]
print '. '. Join (a)
>>> Error exception because the item in list A is of type int