Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > de.comp.lang.python > #6239
| From | Hartmut Goebel <h.goebel@goebel-consult.de> |
|---|---|
| Newsgroups | de.comp.lang.python |
| Subject | [Python-de] Re: PDT: Dateien kopieren und Kopien verifizieren |
| Date | 2024-08-28 08:49 +0200 |
| Organization | Goebel Consult |
| Message-ID | <ad030c93-3480-471d-ab72-64c54f2d3411@goebel-consult.de> (permalink) |
| References | <Kopieren-20240826223722@ram.dialup.fu-berlin.de> |
Am 27.08.24 um 00:01 schrieb Stefan Ram:
> sources =[ source.strip() for source in '''
>
> C:\otherdir\example.txt
> C:\somedir\example.txt
> C:\somedir\example1.txt
>
> ''' .strip().split( '\n' ) if source ]
a) splitlines() ist eleganter
b) Wenn in einer Zeile nur Leerzeichen stehen, landet sie trotzdem in
Deiner Liste.
# Generator, um alle Zeilen zu strippen, erspart mehrmaliges .strip()
sources = (source.strip() for source in '''
…
'''.splitlines()) # generator expression
# Liste mit nicht-leeren Zeilen
sources = [source for source in sources if source]
> if not target_path.is_dir():
> raise RuntimeError( f'Target must be a directory! Target is "{target}".' )
> else:
Nach einem "raise" brauchst Du keinen else-Zweig. Wenn Du ihn weg lässt,
hat der Code weniger Ebenen und ist leichter zu lesen. DIto unten.
> if filecmp.cmp( source_path, target_file_path, shallow=False ):
> pass
Hier würde ich eine "okay" ausgeben.
HTH
--
Schönen Gruß
Hartmut Goebel
Dipl.-Informatiker (univ), CISSP, CSSLP, ISO 27001 Lead Implementer
Information Security Management, Security Governance, Secure Software
Development
Goebel Consult, Landshut
http://www.goebel-consult.de
Blog:
https://www.goebel-consult.de/blog/2020/alternative-android-betriebssysteme/
Kolumne:
https://www.goebel-consult.de/blog/cissp-gefluester/2011-11-in-troja-nichts-neues/
Back to de.comp.lang.python | Previous | Next | Find similar
[Python-de] Re: PDT: Dateien kopieren und Kopien verifizieren Hartmut Goebel <h.goebel@goebel-consult.de> - 2024-08-28 08:49 +0200
csiph-web