Python Forum
save content of table into file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
save content of table into file
#10
the paragraph to import information data from a database cursor to the prettytable,there is the command :
mytable = from_cursor(cursor)
does not work and creates an error.
at one video in youtube I remark that I must write it like that : mytable = from_db_cursor(cursor)

my final works now correctely
after installing prettytable by : pip install PTable

and :

from prettytable import from_db_cursor
#Fonction pour creer un fichier texte et sauvegarder dedans le contenu de la bdd :
def create_file_from_loc35R(self):

	script_path_ils35R = os.path.dirname(os.path.realpath(__file__))#récupérer le répertoire courant
	new_path_ils35R=script_path_ils35R + '\\data_base'  #concaténer au path ci-dessus  le path du dossier data_base
	os.makedirs(new_path_ils35R, exist_ok=True)   #creer le dossier data_base au nouveau path

	script_path_filesave_loc35R = os.path.dirname(os.path.realpath(__file__))#récupérer le répertoire courant
	new_path_filesave_loc35R=script_path_filesave_loc35R + '\\filesave'  #concaténer au path ci-dessus  le path du dossier data_base
	os.makedirs(new_path_filesave_loc35R, exist_ok=True)   #creer le dossier data_base au nouveau path
        
	try:

		conn = sqlite3.connect (new_path_ils35R+'\\ils35R.db')
		curseur=conn.cursor()			
		c=curseur.execute("SELECT * FROM loc35R")
							
		mytable = from_db_cursor(c)
		table_txt = mytable.get_string()

		local_dir = os.path.dirname(__file__)
			with open(os.path.join(local_dir, "filesave/loc35R.txt"), "w",encoding="utf-8") as file_loc35R:
				file_loc35R.write(table_txt)
        
	except :
		self.messageInfo_filesave()
there is the output text file :

[Image: dt7g.jpg]

thanks for the link of the prettytable
Reply


Messages In This Thread
save content of table into file - by atlass218 - Aug-20-2019, 09:13 AM
RE: save content of table into file - by atlass218 - Aug-21-2019, 10:39 AM
RE: save content of table into file - by ThomasL - Aug-21-2019, 11:26 AM
RE: save content of table into file - by atlass218 - Aug-22-2019, 02:47 PM
RE: save content of table into file - by atlass218 - Aug-23-2019, 12:12 PM
RE: save content of table into file - by SheeppOSU - Aug-23-2019, 01:06 PM
RE: save content of table into file - by atlass218 - Aug-23-2019, 03:01 PM
RE: save content of table into file - by atlass218 - Aug-26-2019, 10:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Copy xml content from webpage and save to locally without special characters Nik1811 14 1,080 Mar-26-2024, 09:28 AM
Last Post: Nik1811
  Open/save file on Android frohr 0 363 Jan-24-2024, 06:28 PM
Last Post: frohr
  how to save to multiple locations during save cubangt 1 592 Oct-23-2023, 10:16 PM
Last Post: deanhystad
  save values permanently in python (perhaps not in a text file)? flash77 8 1,284 Jul-07-2023, 05:44 PM
Last Post: flash77
  Save and Close Excel File avd88 0 3,167 Feb-20-2023, 07:19 PM
Last Post: avd88
  Save multiple Parts of Bytearray to File ? lastyle 1 984 Dec-10-2022, 08:09 AM
Last Post: Gribouillis
  Use module docx to get text from a file with a table Pedroski55 8 6,356 Aug-30-2022, 10:52 PM
Last Post: Pedroski55
  Extracting Specific Lines from text file based on content. jokerfmj 8 3,125 Mar-28-2022, 03:38 PM
Last Post: snippsat
Sad Want to Save Print output in csv file Rasedul 5 11,133 Jan-11-2022, 07:04 PM
Last Post: snippsat
Thumbs Up Parsing a YAML file without changing the string content..?, Flask - solved. SpongeB0B 2 2,323 Aug-05-2021, 08:02 AM
Last Post: SpongeB0B

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020