by split. To satisfy this requirement, the splitter uses zero-padding notation in a
string formatting expression ('part%04d') to make sure that filenames all have the
same number of digits at the end (four). When sorted, the leading zero characters
in small numbers guarantee that part files are ordered for joining correctly.
Alternatively, we could strip off digits in filenames, convert them with int, and sort
numerically, by using the list sort method’s keys argument, but that would still
imply that all filenames must start with the some type of substring, and so doesn’t
quite remove the file-naming dependency between the split and join scripts. Be-
cause these scripts are designed to be two steps of the same process, though, some
dependencies between them seem reasonable.
Usage Variations
Finally, let’s run a few more experiments with these Python system utilities to demon-
strate other usage modes. When run without full command-line arguments, both
split and join are smart enough to input their parameters interactively. Here they are
chopping and gluing the Python self-installer file on Windows again, with parameters
typed in the DOS console window:
C:\temp> python C:\...\PP4E\System\Filetools\split.py
File to be split? python-3.1.msi
Directory to store part files? splitout
Splitting C:\temp\python-3.1.msi to C:\temp\splitout by 1433600
Split finished: 10 parts are in C:\temp\splitout
Press Enter key
C:\temp> python C:\...\PP4E\System\Filetools\join.py
Directory containing part files? splitout
Name of file to be recreated? newpy31.msi
Joining C:\temp\splitout to make C:\temp\newpy31.msi
Join complete: see C:\temp\newpy31.msi
Press Enter key
C:\temp> fc /B python-3.1.msi newpy31.msi
Comparing files python-3.1.msi and NEWPY31.MSI
FC: no differences encountered
When these program files are double-clicked in a Windows file explorer GUI, they work
the same way (there are usually no command-line arguments when they are launched
this way). In this mode, absolute path displays help clarify where files really are. Re-
member, the current working directory is the script’s home directory when clicked like
this, so a simple name actually maps to a source code directory; type a full path to make
the split files show up somewhere else:
[in a pop-up DOS console box when split.py is clicked]
File to be split? c:\temp\python-3.1.msi
Directory to store part files? c:\temp\parts
Splitting c:\temp\python-3.1.msi to c:\temp\parts by 1433600
Split finished: 10 parts are in c:\temp\parts
Press Enter key
Splitting and Joining Files | 289