
Hallo Liste,
Für euch warscheinlich eine Kleinigkeit, ich suche mir momentan einen Wolf.
Ich suche für folgenden bash-Aufruf das äquivalent in python cat *.4go > xxx.4gi

Roland M. Kruggel wrote:
Ich suche für folgenden bash-Aufruf das äquivalent in python cat *.4go > xxx.4gi
import glob, shutil
outfile = open("xxx.4gi", "w") for f in glob.glob("*.4go"): infile = open(f) shutil.copyfileobj(infile, outfile) infile.close() outfile.close()
HTH, Martin
_______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de

--On 30. März 2006 21:00:22 +0200 "\"Martin v. Löwis\"" martin@v.loewis.de wrote:
Roland M. Kruggel wrote:
Ich suche für folgenden bash-Aufruf das äquivalent in python cat *.4go > xxx.4gi
oder die 1-Zeiler Version:
import glob; open('xxx.4gi','w').write(''.join([open(f).read() for f in glob.glob('*.4go')]))
-aj
_______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Andreas Jung schrieb:
oder die 1-Zeiler Version:
import glob; open('xxx.4gi','w').write(''.join([open(f).read() for f in glob.glob('*.4go')]))
Damit bekommst Du aber in Software-Design eine "6".
- -- Schönen Gruß - Regards Hartmut Goebel
| Hartmut Goebel | IT-Security -- effizient | | h.goebel@goebel-consult.de | www.goebel-consult.de |
_______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de

--On 31. März 2006 09:19:35 +0200 Hartmut Goebel h.goebel@goebel-consult.de wrote:
oder die 1-Zeiler Version:
import glob; open('xxx.4gi','w').write(''.join([open(f).read() for f in glob.glob('*.4go')]))
Damit bekommst Du aber in Software-Design eine "6".
Ich weiss :-) die Lösung von Martin war mir zu lang.
SCNR, Andreas
_______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Andreas Jung schrieb:
Ich weiss :-) die Lösung von Martin war mir zu lang.
Hmm, dann solltest Du überlegen, doch zu Perl zu wechseln ;-)
- -- Schönen Gruß - Regards Hartmut Goebel
| Hartmut Goebel | IT-Security -- effizient | | h.goebel@goebel-consult.de | www.goebel-consult.de |
_______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de

Andreas Jung wrote:
Ich weiss :-) die Lösung von Martin war mir zu lang.
In Python 2.5 kannst Du noch zwei Zeilen einsparen:
import glob, shutil with open("xxx.4gi", "w") as outfile: for f in glob.glob("*.4go"): with open(f) as infile: shutil.copyfileobj(infile, outfile)
Ciao, Martin
_______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Martin v. Löwis schrieb:
import glob, shutil
outfile = open("xxx.4gi", "w") for f in glob.glob("*.4go"): infile = open(f) shutil.copyfileobj(infile, outfile) infile.close() outfile.close()
Ich dachte, das wäre endlich mal eine Anwendung für das Module 'fileinput'. Aber shutil.copyfileobj ist da wesendlich elleganter und effizienter.
- -- Schönen Gruß - Regards Hartmut Goebel
| Hartmut Goebel | IT-Security -- effizient | | h.goebel@goebel-consult.de | www.goebel-consult.de |
_______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de
participants (4)
-
"Martin v. Löwis"
-
Andreas Jung
-
Hartmut Goebel
-
Roland M. Kruggel