-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirstModule.py
More file actions
66 lines (53 loc) · 2.11 KB
/
Copy pathFirstModule.py
File metadata and controls
66 lines (53 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
'''
Created on 24.02.2015
version: 0.0.1
@author: frank
'''
import tkMessageBox
from tkFileDialog import *
from Tkinter import * ## Tkinter importieren
def buttonBeendenClick():
if tkMessageBox.askyesno('Beenden', 'Soll das Programm wirklich beendet werden?'):
root.quit()
root.destroy()
root=Tk() ## Wurzelfenster!
root.title('CSV-Datei: Kommas gegen Semikolons tauschen!') ## Titel festlegen
textfenster = Text(root,background='grey') ## Ein Textfenster erzeugen
textfenster.pack() ## und anzeigen
labelHinweis = Label(master=root, text='Programm um eine .csv Datei von Google in eine\r.csv-Datei für den Import in myrcm vorzubereiten!', fg='white', bg='gray', font=('Arial', 12))
labelHinweis.place(x=80, y=0, width=420, height=120)
#import tkMessageBox
tkMessageBox.showinfo('Quelldatei','Bitte die Quelldatei auswählen!')
# Datei zum Lesen oeffnen, mit Kontrolle ob Datei lesbar. Ansonsten exit()
myPath = askopenfilename(filetypes=[("Quelldatei", ".csv")])
try:
fobj_in = open(str(myPath),"r")
except IOError:
print "Error: can\'t find file or read data"
tkMessageBox.showerror("Error", "Can't read file!")
exit()
else:
print "Written content in the file successfully"
#import tkMessageBox
tkMessageBox.showinfo('Zieldatei','Bitte die Zieldatei auswählen!')
# Datei zum Schreiben oeffnen.
myPath2 = asksaveasfilename(filetypes=[("Zieldatei", ".csv")])
fobj_out = open(str(myPath2),"w")
# Variable i definieren
i = 1
# For-Schleife
for line in fobj_in:
#print line.rstrip() #schreibt jede gefundene Zeile in die Konsole
zeile = line.replace(",", ";")
fobj_out.write(str(i) + ": " + zeile) # schreibt jede geaenderte Zeile in die neue Datei
print zeile.rstrip() #schreibt jede geaenderte Zeile in die Konsole
i = i + 1
# Dateien wieder schliessen
fobj_in.close()
fobj_out.close()
# Button Beenden
buttonBeenden = Button(master=root, bg='#FBD975', text='Programm beenden?',
command=buttonBeendenClick)
buttonBeenden.place(x=164, y=94, width=240, height=27)
root.mainloop()