python oop learning communication between function inside a class
Hello, I would like to know how possible it is to call a member function from a class and pass it a variable Example: class Application(tk.Frame): """docstring for .""" def __init__(self, parent): super(Application, self).__init__(parent) self.parent = parent parent.title('Courses selections') #parent.geometry("700x350") parent.geometry('500x320+0+0') #Width x Height # Create widgets/grid self.create_widgets() self.selected_item = 0 def create_widgets(self): ### FIRST NAME LABEL + ENTRY self.firstName_txt = tk.StringVar() self.firstName_lbl = tk.Label(self.parent, text='First Name', font=('bold')) self.firstName_lbl.place(x=20,y=10) self.firstName_entry = tk.Entry(self.parent, textvariable=self.firstName_txt) self.firstName_entry.place(x=120,y=10) ... def prereq(self): self.boo = 1 if self.firstName_txt.get() == "": msg.showwarning("Missing information", "First name info missing") boo = 0 elif self.lastName_txt.get() == "": msg.showwarning("Missing information", "Last name info missing") boo = 0 elif self.age_txt.get() == "": msg.showwarning("Missing information", "Age info missing") boo = 0 elif self.rBtnGender.get() == 0: msg.showwarning("Missing information", "Gender info missing") boo = 0 if self.boo == 1: self.fname = self.firstName_txt.get() self.lname = self.lastName_txt.get() self.age = int(self.age_txt.get()) self.selectedCourse = self.coursesLBX.get(self.coursesLBX.curselection()) if self.age < 21: msg.showwarning("Invalid Age", "Invalid Age, you are not eligible") return elif self.age >= 21: pass ### SELECTED COURSE if self.selectedCourse == "Quality Management (Adv.)": self.prereq = "The prereq for this course is Quality Management (Int)." self.flag = 1 elif self.selectedCourse == "Financial Management (Adv.)": self.prereq = "The prereq for this course is Financial Management (Bas)." self.flag= 1 elif self.selectedCourse == "Project Management (Adv.)": self.prereq = "The prereq for this course is Project Management (Int)." self.flag = 0 else: self.prereq = "The prereq for this course is Project Management (Bas)." self.flag = 0 ### PART TIME if self.chkBtnPTime.get() == 1 and self.flag == 0: self.str2 = "\nThis course is not available part time." elif self.chkBtnPTime.get() == 1 and self.flag == 1: self.str2 = "\nThis course is available part time." else: self.str2 = "" self.result = self.prereq + self.str2 msg.showinfo('Form info', self.result) def save2db(self): try: db.insert(self.fname, self.lname, self.age) msg.showinfo('DB action', "Selection inserted into db") except: msg.showinfo("Form submission failed", "Plz check ur input") ## all script available on github https://github.com/barpasc/python_tuto_400_oop In function save2db, I would like to know if there is any alternative to using try/except. The alternative I'm thinking is something like def save2db(self,boo): if boo == 1: do something else: do something like return to previous step... Is this possible? -- https://mail.python.org/mailman/listinfo/python-list
python show .
Hello, I'm working on a script where I want to loop into folders somehow recursively to get information but I want to limit the infos for the files on a certain level of folders for example: /home/user/Documents/folder1 /home/user/Documents/folder2 /home/user/Documents/folder3/folder1/file1 /home/user/Documents/folder4/file1 /home/user/Documents/file1 /home/user/Documents/file2 /home/user/Documents/file3 I only want file1, 2, 3 at the root of Documents to show (write to a csv) and I'm using the script below ### SCRIPT### #!/usr/bin/env python3 # -*- coding: utf-8 -*- import os csv_contents = "" output_file = '/home/user/Documents/csv/output2csv.csv' Lpath = '/home/user/Documents/' csv_contents = "FOLDER PATH;Size in Byte;Size in Kb;Size in Mb;Size in Gb\n" for root, dirs, files in os.walk(Lpath, topdown=False): counter = Lpath.count(os.path.sep) if counter < 5: for f in os.listdir(root): path = os.path.join(root, f) f_size = 0 f_size = os.path.getsize(path) csv_contents += "%s ;%.2f ;%.2f ;%.2f ;%.2f \n" % (path, f_size, f_size/1024, f_size/1048576, f_size/1073741824) fp = open(output_file, "w") fp.write(csv_contents) fp.close() ### END OF SCRIPT### When I run this script, I get files in subfolders. For now, I need to keep using "os.walk" because the script includes functions that I didn't include to make thing simple. Pascal -- https://mail.python.org/mailman/listinfo/python-list
Re: python show folder files and not subfolder files
Please advise if the following is ok (i don't think it is) #!/usr/bin/env python3 # -*- coding: utf-8 -*- import os csv_contents = "" output_file = '/home/user/Documents/csv/output3csv.csv' Lpath = '/home/user/Documents/' csv_contents = "FOLDER PATH;Size in Byte;Size in Kb;Size in Mb;Size in Gb\n" d_size = 0 for root, dirs, files in os.walk(Lpath, topdown=False): for i in files: d_size += os.path.getsize(root + os.sep + i) csv_contents += "%s ;%.2f ;%.2f ;%.2f ;%.2f \n" % (root, d_size, d_size/1024, d_size/1048576, d_size/1073741824) counter = Lpath.count(os.path.sep) if counter < 5: for f in os.listdir(Lpath): path = os.path.join(Lpath, f) f_size = 0 f_size = os.path.getsize(path) csv_contents += "%s ;%.2f ;%.2f ;%.2f ;%.2f \n" % (path, f_size, f_size/1024, f_size/1048576, f_size/1073741824) fp = open(output_file, "w") fp.write(csv_contents) fp.close() -- https://mail.python.org/mailman/listinfo/python-list
Re: python show folder files and not subfolder files
ok, i came up with if os.path.isfile(path) following path = os.path.join(Lpath, f) and it seems to be ok, no dupplicates or wrong sizes... thanks -- https://mail.python.org/mailman/listinfo/python-list
python if and same instruction line not working
I need to change the script commented out to the one not commented out. Why? # for x in sorted (fr, key=str.lower): # tmpstr = x.rpartition(';')[2] # if x != csv_contents and tmpstr == "folder\n": # csv_contentsB += x # elif x != csv_contents and tmpstr == "files\n": # csv_contentsC += x for x in sorted (fr, key=str.lower): if x != csv_contents: tmpstr = x.rpartition(';')[2] if tmpstr == "folder\n": csv_contentsB += x elif tmpstr == "file\n": csv_contentsC += x -- https://mail.python.org/mailman/listinfo/python-list
Re: python if and same instruction line not working
On Tuesday, September 29, 2020 at 5:28:22 PM UTC+2, MRAB wrote: > On 2020-09-29 15:42, pascal z via Python-list wrote: > > I need to change the script commented out to the one not commented out. Why? > > > > # for x in sorted (fr, key=str.lower): > > # tmpstr = x.rpartition(';')[2] > > # if x != csv_contents and tmpstr == "folder\n": > > # csv_contentsB += x > > # elif x != csv_contents and tmpstr == "files\n": > > # csv_contentsC += x > > > > for x in sorted (fr, key=str.lower): > > if x != csv_contents: > > tmpstr = x.rpartition(';')[2] > > if tmpstr == "folder\n": > > csv_contentsB += x > > elif tmpstr == "file\n": > > csv_contentsC += x > > > You haven't defined what you mean by "not working" for any test values > to try, but I notice that the commented code has "files\n" whereas the > uncommented code has "file\n". Very good point, it should what caused the issue By the way, it seems it's ok to check \n as end of line, it will work on windows linux and mac platforms even if windows use \r\n -- https://mail.python.org/mailman/listinfo/python-list
Re: python show folder files and not subfolder files
On Thursday, September 24, 2020 at 4:37:07 PM UTC+2, Terry Reedy wrote: > On 9/23/2020 7:24 PM, pascal z via Python-list wrote: > > Please advise if the following is ok (i don't think it is) > > > > #!/usr/bin/env python3 > > # -*- coding: utf-8 -*- > > > > import os > > > > csv_contents = "" > > output_file = '/home/user/Documents/csv/output3csv.csv' > > Lpath = '/home/user/Documents/' > > > > csv_contents = "FOLDER PATH;Size in Byte;Size in Kb;Size in Mb;Size in Gb\n" > > > > d_size = 0 > > for root, dirs, files in os.walk(Lpath, topdown=False): > > for i in files: > > d_size += os.path.getsize(root + os.sep + i) > > csv_contents += "%s ;%.2f ;%.2f ;%.2f ;%.2f \n" % (root, > > d_size, d_size/1024, d_size/1048576, d_size/1073741824) > > > > counter = Lpath.count(os.path.sep) > > if counter < 5: > > for f in os.listdir(Lpath): > > path = os.path.join(Lpath, f) > > f_size = 0 > > f_size = os.path.getsize(path) > > csv_contents += "%s ;%.2f ;%.2f ;%.2f ;%.2f \n" % > > (path, f_size, f_size/1024, f_size/1048576, f_size/1073741824) > > > > fp = open(output_file, "w") > > fp.write(csv_contents) > > fp.close() > > > Read > https://docs.python.org/3/faq/programming.html#what-is-the-most-efficient-way-to-concatenate-many-strings-together > -- > Terry Jan Reedy Thanks for this tip. I do think it's better to use lists than concatenate into string variable. However, writing a list to a csv file is not something easy. If strings stored into the list have commas and single quotes (like song title's), it messes up the whole csv when it first meets this. Example with arr as list: import csv import io (...) csv_contents = "%s;%s;%s;%.2f;%.2f;%.2f;%.2f;%s" % (vfolder_path, vfile_name, vfolder_path_full, 0.00, 0.00, 0.00,0.00, "folder") arr.append([csv_contents]) b = io.BytesIO() with open(CSV_FILE,'w', newline ='\n') as f: #write = csv.writer(f,delimiter=';') #write = csv.writer(f,quotechar='\'', quoting=csv.QUOTE_NONNUMERIC,delimiter=',') write = csv.writer(f,b) for row in arr: write.writerows(row) (...) string samples: ;'Forgotten Dreams' Mix.mp3;'Awakening of a Dream' Ambient Mix.mp3;Best of Trip-Hop & Downtempo & Hip-Hop Instrumental.mp3;2-Hour _ Space Trance.mp3 for the titles above, the easiest thing to write csv for me is (...) csv_contents += "%s;%s;%s;%.2f;%.2f;%.2f;%.2f;%s" % (vfolder_path, vfile_name, vfolder_path_full, 0.00, 0.00, 0.00,0.00, "folder" with open(CSV_FILE,'w') as f: f.write(csv_contents) csv_contents can be very large and it seems to work. It can concatenate 30k items and it's ok. Also with the above, I have the expected result into each of the 8 rows having the corresponding data. This is not always the case with csv writerows. If it meets a character it can't process, from there everything go into a single cell row. The split on semi colon from doesnt work anymore. I am not allowed to change the name of the files (it could be used later somewhere else, making side effects...). -- https://mail.python.org/mailman/listinfo/python-list
learning python building 2nd app, need advices
Hi, This is a python app I was working on, can you help making it a beautiful looking app like bleachbit or ccleaner? The whole code below (what it does: it lists all folders and files from a specified path and tells some infos like size in mb or gb... and export it to a csv file for further processing maybe with customized dashboard...the listing should will also be used to rename multiple files to help ordering and finding files because current renaming tools are difficult to use I find...) For now it just gives infos about folders and files and rename. Maybe a backup tool would be nice, please advise. But the code is opposiite to bullet proof and if could be more bullet proof, it would be a way to start and continue the messy code #!/usr/bin/env python3 # -*- coding: utf-8 -*- import locale import os import csv from tkinter import messagebox as msg try: from tkinter import * import ttk except: import tkinter as tk #GUI package from tkinter import ttk def fx_BasicListing(): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # "txt" pour type enreg csv txt/csv # tree.delete(*tree.get_children()) fx_browseFoldersZ(1) return def fx_AdvancedListing(): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # fx_browseFoldersZ(2,"txt") # tree.destroy() #tree.delete(*tree.get_children()) fx_browseFoldersZ(2) return def fx_browseFoldersZ(argy): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # "txt" pour type enreg csv txt/csv tree.delete(*tree.get_children()) fx_browseFolders(argy,"txt") ### ### ### def fx_writeCSV(*arr): csv_file_title = 'csv_1_baselisting.csv' # csv path entry box CSV_FILE = vcsv_path.get() if not os.path.exists(CSV_FILE): os.makedirs(CSV_FILE) CSV_FILE += csv_file_title print('%s' % CSV_FILE) with open(CSV_FILE,'w', newline ='\n') as f: write = csv.writer(f, doublequote=True, delimiter=';') for row in arr: write.writerows(row) def fx_writeCSV_str(txt_str): csv_file_title = 'csvtxt_1_baselisting.csv' # csv path entry box CSV_FILE = vcsv_path.get() if not os.path.exists(CSV_FILE): os.makedirs(CSV_FILE) CSV_FILE += csv_file_title print('%s' % CSV_FILE) with open(CSV_FILE,'w') as f: f.write(txt_str) # fx_LoadCSV(CSV_FILE) with open(CSV_FILE, 'r') as f: reader = csv.DictReader(f, delimiter=';') for row in reader: col1 = row['Path'] col2 = row['Folder-file'] col3 = row['Size in Byte'] col4 = row['Size in Kb'] col5 = row['Size in Mb'] col6 = row['Size in Gb'] col7 = row['type'] tree.insert('', 'end', values=(col1, col2, col3, col4, col5, col6,col7)) return ### ### def fx_chkPath(xzPath): isxFile = os.path.isfile(xzPath) isxDir = os.path.isdir(xzPath) print("DOSSIER OUI",isxDir) if isxDir: return elif not isxDir: msg.showwarning("Folder path", "WD Path entered not found") return ### ### ### def fx_browseFolders(argz, tycsv): tree.delete(*tree.get_children()) # /// /// /// csv_txt = "" csv_contents = "" counterPath = 0 size = 0 f_size = 0 f_vscale = 0 # /// /// /// # path WD Lpath = vtxt_path.get() print('%s' % Lpath) # include files vvchkboxF = vchkboxF.get() # print("include files:::", vchkboxF.get()) # include modification date print(vchkboxD.get()) # include creation date print(vchkboxC.get()) # scale f_vscale = int(var_scale.get()) print(f_vscale) # path WD 2 if Lpath.endswith(os.path.sep): Lpath = Lpath[:-1] # isFile = os.path.isfile(Lpath) # print("fichier?",isFile) fx_chkPath(Lpath) counterPath = Lpath.count(os.path.sep) csv_contents = "Path;Folder-file;Size in Byte;Size in Kb;Size in Mb;Size in Gb;type\n" csv_txt = csv_contents # csv_contents # 1-FOLDER PATH # 2-FILENAME # 3-FOLDER PATH FULL # 4-Size in Byte # 5-Size in Kb # 6-Size in Mb # 7-Size in Gb # 8-type\n ### BASIC LISTING # if argz == 1: print("basic listing") fi
Re: learning python building 2nd app, need advices
any way to attach a file because I loose indentation? -- https://mail.python.org/mailman/listinfo/python-list
Re: learning python building 2nd app, need advices
And something important to this app, is about listing files, how to avoid listing small application files parts .ini and binary files so if it's an application it would tell the size of of the folder of this application and not list the content or make it optionnal? -- https://mail.python.org/mailman/listinfo/python-list
Re: learning python building 2nd app, need advices
tab to space on linux is not something easy to do, I had to launch windows and use notepad++. Anyway, indentation should all be converted to spaces below #!/usr/bin/env python3 # -*- coding: utf-8 -*- import locale import os import csv from tkinter import messagebox as msg try: from tkinter import * import ttk except: import tkinter as tk #GUI package from tkinter import ttk def fx_BasicListing(): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # "txt" pour type enreg csv txt/csv # tree.delete(*tree.get_children()) fx_browseFoldersZ(1) return def fx_AdvancedListing(): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # fx_browseFoldersZ(2,"txt") # tree.destroy() #tree.delete(*tree.get_children()) fx_browseFoldersZ(2) return def fx_browseFoldersZ(argy): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # "txt" pour type enreg csv txt/csv tree.delete(*tree.get_children()) fx_browseFolders(argy,"txt") ### ### ### def fx_writeCSV(*arr): csv_file_title = 'csv_1_baselisting.csv' # csv path entry box CSV_FILE = vcsv_path.get() if not os.path.exists(CSV_FILE): os.makedirs(CSV_FILE) CSV_FILE += csv_file_title print('%s' % CSV_FILE) with open(CSV_FILE,'w', newline ='\n') as f: write = csv.writer(f, doublequote=True, delimiter=';') for row in arr: write.writerows(row) def fx_writeCSV_str(txt_str): csv_file_title = 'csvtxt_1_baselisting.csv' # csv path entry box CSV_FILE = vcsv_path.get() if not os.path.exists(CSV_FILE): os.makedirs(CSV_FILE) CSV_FILE += csv_file_title print('%s' % CSV_FILE) with open(CSV_FILE,'w') as f: f.write(txt_str) # fx_LoadCSV(CSV_FILE) with open(CSV_FILE, 'r') as f: reader = csv.DictReader(f, delimiter=';') for row in reader: col1 = row['Path'] col2 = row['Folder-file'] col3 = row['Size in Byte'] col4 = row['Size in Kb'] col5 = row['Size in Mb'] col6 = row['Size in Gb'] col7 = row['type'] tree.insert('', 'end', values=(col1, col2, col3, col4, col5, col6,col7)) return ### ### def fx_chkPath(xzPath): isxFile = os.path.isfile(xzPath) isxDir = os.path.isdir(xzPath) print("DOSSIER OUI",isxDir) if isxDir: return elif not isxDir: msg.showwarning("Folder path", "WD Path entered not found") return ### ### ### def fx_browseFolders(argz, tycsv): tree.delete(*tree.get_children()) # /// /// /// csv_txt = "" csv_contents = "" counterPath = 0 size = 0 f_size = 0 f_vscale = 0 # /// /// /// # path WD Lpath = vtxt_path.get() print('%s' % Lpath) # include files vvchkboxF = vchkboxF.get() # print("include files:::", vchkboxF.get()) # include modification date print(vchkboxD.get()) # include creation date print(vchkboxC.get()) # scale f_vscale = int(var_scale.get()) print(f_vscale) # path WD 2 if Lpath.endswith(os.path.sep): Lpath = Lpath[:-1] # isFile = os.path.isfile(Lpath) # print("fichier?",isFile) fx_chkPath(Lpath) counterPath = Lpath.count(os.path.sep) csv_contents = "Path;Folder-file;Size in Byte;Size in Kb;Size in Mb;Size in Gb;type\n" csv_txt = csv_contents # csv_contents # 1-FOLDER PATH # 2-FILENAME # 3-FOLDER PATH FULL # 4-Size in Byte # 5-Size in Kb # 6-Size in Mb # 7-Size in Gb # 8-type\n ### BASIC LISTING # if argz == 1: print("basic listing") file_paths = [] file_paths.append([csv_contents]) for root, dirs, files in os.walk(Lpath, topdown=True): for file in files: if tycsv == "csv": vfolder_path = root + os.sep vfile_name = "'" + file + "'" vfolder_path_full = root + os.sep + file csv_contents = "%s;%s;%s;%s;%s;%s;%s" % (vfolder_path, vfile_name , 'na', 'na', 'na','na', "folder") file_paths.append([csv_contents]) elif tycsv == "txt": vfolder_path = root +
Re: learning python building 2nd app, need advices
tab to space on linux is not something easy to do, I had to launch windows and use notepad++. Anyway, indentation should all be converted to spaces below #!/usr/bin/env python3 # -*- coding: utf-8 -*- import locale import os import csv from tkinter import messagebox as msg try: from tkinter import * import ttk except: import tkinter as tk #GUI package from tkinter import ttk def fx_BasicListing(): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # "txt" pour type enreg csv txt/csv # tree.delete(*tree.get_children()) fx_browseFoldersZ(1) return def fx_AdvancedListing(): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # fx_browseFoldersZ(2,"txt") # tree.destroy() #tree.delete(*tree.get_children()) fx_browseFoldersZ(2) return def fx_browseFoldersZ(argy): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # "txt" pour type enreg csv txt/csv tree.delete(*tree.get_children()) fx_browseFolders(argy,"txt") ### ### ### def fx_writeCSV(*arr): csv_file_title = 'csv_1_baselisting.csv' # csv path entry box CSV_FILE = vcsv_path.get() if not os.path.exists(CSV_FILE): os.makedirs(CSV_FILE) CSV_FILE += csv_file_title print('%s' % CSV_FILE) with open(CSV_FILE,'w', newline ='\n') as f: write = csv.writer(f, doublequote=True, delimiter=';') for row in arr: write.writerows(row) def fx_writeCSV_str(txt_str): csv_file_title = 'csvtxt_1_baselisting.csv' # csv path entry box CSV_FILE = vcsv_path.get() if not os.path.exists(CSV_FILE): os.makedirs(CSV_FILE) CSV_FILE += csv_file_title print('%s' % CSV_FILE) with open(CSV_FILE,'w') as f: f.write(txt_str) # fx_LoadCSV(CSV_FILE) with open(CSV_FILE, 'r') as f: reader = csv.DictReader(f, delimiter=';') for row in reader: col1 = row['Path'] col2 = row['Folder-file'] col3 = row['Size in Byte'] col4 = row['Size in Kb'] col5 = row['Size in Mb'] col6 = row['Size in Gb'] col7 = row['type'] tree.insert('', 'end', values=(col1, col2, col3, col4, col5, col6,col7)) return ### ### def fx_chkPath(xzPath): isxFile = os.path.isfile(xzPath) isxDir = os.path.isdir(xzPath) print("DOSSIER OUI",isxDir) if isxDir: return elif not isxDir: msg.showwarning("Folder path", "WD Path entered not found") return ### ### ### def fx_browseFolders(argz, tycsv): tree.delete(*tree.get_children()) # /// /// /// csv_txt = "" csv_contents = "" counterPath = 0 size = 0 f_size = 0 f_vscale = 0 # /// /// /// # path WD Lpath = vtxt_path.get() print('%s' % Lpath) # include files vvchkboxF = vchkboxF.get() # print("include files:::", vchkboxF.get()) # include modification date print(vchkboxD.get()) # include creation date print(vchkboxC.get()) # scale f_vscale = int(var_scale.get()) print(f_vscale) # path WD 2 if Lpath.endswith(os.path.sep): Lpath = Lpath[:-1] # isFile = os.path.isfile(Lpath) # print("fichier?",isFile) fx_chkPath(Lpath) counterPath = Lpath.count(os.path.sep) csv_contents = "Path;Folder-file;Size in Byte;Size in Kb;Size in Mb;Size in Gb;type\n" csv_txt = csv_contents # csv_contents # 1-FOLDER PATH # 2-FILENAME # 3-FOLDER PATH FULL # 4-Size in Byte # 5-Size in Kb # 6-Size in Mb # 7-Size in Gb # 8-type\n ### BASIC LISTING # if argz == 1: print("basic listing") file_paths = [] file_paths.append([csv_contents]) for root, dirs, files in os.walk(Lpath, topdown=True): for file in files: if tycsv == "csv": vfolder_path = root + os.sep vfile_name = "'" + file + "'" vfolder_path_full = root + os.sep + file csv_contents = "%s;%s;%s;%s;%s;%s;%s" % (vfolder_path, vfile_name , 'na', 'na', 'na','na', "folder") file_paths.append([csv_contents]) elif tycsv == "txt": vfolder_path = root +
Re: learning python building 2nd app, need advices
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import locale import os import csv from tkinter import messagebox as msg try: from tkinter import * import ttk except: import tkinter as tk #GUI package from tkinter import ttk def fx_BasicListing(): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # "txt" pour type enreg csv txt/csv # tree.delete(*tree.get_children()) fx_browseFoldersZ(1) return def fx_AdvancedListing(): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # fx_browseFoldersZ(2,"txt") # tree.destroy() #tree.delete(*tree.get_children()) fx_browseFoldersZ(2) return def fx_browseFoldersZ(argy): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # "txt" pour type enreg csv txt/csv tree.delete(*tree.get_children()) fx_browseFolders(argy,"txt") ### ### ### def fx_writeCSV(*arr): csv_file_title = 'csv_1_baselisting.csv' # csv path entry box CSV_FILE = vcsv_path.get() if not os.path.exists(CSV_FILE): os.makedirs(CSV_FILE) CSV_FILE += csv_file_title print('%s' % CSV_FILE) with open(CSV_FILE,'w', newline ='\n') as f: write = csv.writer(f, doublequote=True, delimiter=';') for row in arr: write.writerows(row) def fx_writeCSV_str(txt_str): csv_file_title = 'csvtxt_1_baselisting.csv' # csv path entry box CSV_FILE = vcsv_path.get() if not os.path.exists(CSV_FILE): os.makedirs(CSV_FILE) CSV_FILE += csv_file_title print('%s' % CSV_FILE) with open(CSV_FILE,'w') as f: f.write(txt_str) # fx_LoadCSV(CSV_FILE) with open(CSV_FILE, 'r') as f: reader = csv.DictReader(f, delimiter=';') for row in reader: col1 = row['Path'] col2 = row['Folder-file'] col3 = row['Size in Byte'] col4 = row['Size in Kb'] col5 = row['Size in Mb'] col6 = row['Size in Gb'] col7 = row['type'] tree.insert('', 'end', values=(col1, col2, col3, col4, col5, col6,col7)) return ### ### def fx_chkPath(xzPath): isxFile = os.path.isfile(xzPath) isxDir = os.path.isdir(xzPath) print("DOSSIER OUI",isxDir) if isxDir: return elif not isxDir: msg.showwarning("Folder path", "WD Path entered not found") return ### ### ### def fx_browseFolders(argz, tycsv): tree.delete(*tree.get_children()) # /// /// /// csv_txt = "" csv_contents = "" counterPath = 0 size = 0 f_size = 0 f_vscale = 0 # /// /// /// # path WD Lpath = vtxt_path.get() print('%s' % Lpath) # include files vvchkboxF = vchkboxF.get() # print("include files:::", vchkboxF.get()) # include modification date print(vchkboxD.get()) # include creation date print(vchkboxC.get()) # scale f_vscale = int(var_scale.get()) print(f_vscale) # path WD 2 if Lpath.endswith(os.path.sep): Lpath = Lpath[:-1] # isFile = os.path.isfile(Lpath) # print("fichier?",isFile) fx_chkPath(Lpath) counterPath = Lpath.count(os.path.sep) csv_contents = "Path;Folder-file;Size in Byte;Size in Kb;Size in Mb;Size in Gb;type\n" csv_txt = csv_contents # csv_contents # 1-FOLDER PATH # 2-FILENAME # 3-FOLDER PATH FULL # 4-Size in Byte # 5-Size in Kb # 6-Size in Mb # 7-Size in Gb # 8-type\n ### BASIC LISTING # if argz == 1: print("basic listing") file_paths = [] file_paths.append([csv_contents]) for root, dirs, files in os.walk(Lpath, topdown=True): for file in files: if tycsv == "csv": vfolder_path = root + os.sep vfile_name = "'" + file + "'" vfolder_path_full = root + os.sep + file csv_contents = "%s;%s;%s;%s;%s;%s;%s" % (vfolder_path, vfile_name , 'na', 'na', 'na','na', "folder") file_paths.append([csv_contents]) elif tycsv == "txt": vfolder_path = root + os.sep vfile_name = file vfolder_path_full = root + os.sep + file f_size = os.path.getsize(vfold
Re: learning python building 2nd app, need advices
On Monday, January 11, 2021 at 12:00:28 PM UTC, Loris Bennett wrote: > pascal z writes: > > > tab to space on linux is not something easy to do > > I would argue that you are mistaken, although that depends somewhat on > your definition of 'easy'. > > > , I had to launch windows and use notepad++. > > There is the Linux command 'expand' , which I have never used, but which > sounds like it will do what you want: > > $ expand --help > Usage: expand [OPTION]... [FILE]... > Convert tabs in each FILE to spaces, writing to standard output. > > As an Emacs user, personally I would use the command > > M-x untabify > > within Emacs. I assume that Vim has something similar. > > Cheers, > > Loris > > -- > This signature is currently under construction. Thanks, I'm going to try As alternative, I pasted it into github and pasted it back into this page, it's ok when pasting but when posting it fails keeping spaces... Until I can find a way to do it, this is the github link https://github.com/barpasc/listfiles/blob/main/pyFilesGest_6B18.py -- https://mail.python.org/mailman/listinfo/python-list
Re: learning python building 2nd app, need advices
On Monday, January 11, 2021 at 1:45:31 PM UTC, Greg Ewing wrote: > On 12/01/21 1:12 am, pascal z wrote: > > As alternative, I pasted it into github and pasted it back into this page, > > it's ok when pasting but when posting it fails keeping spaces... > The indentation in your last three posts looks fine here in > the comp.lang.python newsgroup. If it doesn't look right to > you, it may be the fault of whatever you're using to read > the group. > > -- > Greg @Greg, then if you want, you can post these from what you're using. I tried sending a few times and it seemed it didn't work when refreshing the google group discussion page. However, just looking now at the discussion through emails, shows indentation right. I'm using firefox. I'll try using chromium for later posts if that makes things easier. -- https://mail.python.org/mailman/listinfo/python-list
Re: learning python building 2nd app, need advices
On Monday, January 11, 2021 at 2:07:03 PM UTC, Chris Angelico wrote: > On Tue, Jan 12, 2021 at 1:01 AM pascal z via Python-list > wrote: > > > > On Monday, January 11, 2021 at 1:45:31 PM UTC, Greg Ewing wrote: > > > On 12/01/21 1:12 am, pascal z wrote: > > > > As alternative, I pasted it into github and pasted it back into this > > > > page, it's ok when pasting but when posting it fails keeping spaces... > > > The indentation in your last three posts looks fine here in > > > the comp.lang.python newsgroup. If it doesn't look right to > > > you, it may be the fault of whatever you're using to read > > > the group. > > > > > > -- > > > Greg > > > > @Greg, then if you want, you can post these from what you're using. I tried > > sending a few times and it seemed it didn't work when refreshing the google > > group discussion page. However, just looking now at the discussion through > > emails, shows indentation right. I'm using firefox. I'll try using chromium > > for later posts if that makes things easier. > > > Easy fix: stop looking at the Google Group page. > > ChrisA ok, emails show post fine. 10 years ago or something, I was quite involved to comp.lang.c and I don't remember having this issue. Of course, only Python needs formatting speficities but from what I can remember, indentation was working fine then. One more thing, is that there was a lot less ads than now. And comp.lang.python seems to show more ads than other groups like comp.lang.c -- https://mail.python.org/mailman/listinfo/python-list