Posts

Showing posts with the label file-handling

Test assertion fail

Test assertion fail I've wrote a function which export dictionary as a string into csv file. In my assignment I'm instructed to export this dict as one string (I took keys from dict and separated them with commas - no spaces). I have a file which test this function - I'm here so of course it fails. However when I print output of that function it looks like in my assignment e.g sth1,sth2,sth3,sth4. What I'm missing here? Here is my code: def export_stock(stock, filename="export.csv"): with open(filename, "w+") as exportation: a = list(stock.keys()) a = ",".join(a) exportation.write(a) and here is test func: def test_export(self): export_stock({'sth1': 3, 'sth2': 1, "sth3": 1}, "export.csv") with open("export.csv", newline='') as csvfile: expected = ["sth1", "sth2", "sth3", "sth1", "sth1"] ...

delete a text file from content resolver

delete a text file from content resolver I want to delete a text file from android through its path i am trying below code but the file is not deleting help me if you can public static void deleteDocumentFile(String fs , Context c) { File f = new File(fs); if (f.delete()) { Log.d("00000", "delete"); if(f.exists()){ try { f.getCanonicalFile().delete(); } catch (IOException e) { e.printStackTrace(); } if(f.exists()){ c.deleteFile(f.getName()); } } } else{ Log.d("00000", "Not delete"); } Uri uri = MediaStore.Files.getContentUri("external"); String selectionMimeType = MediaStore.Files.FileColumns.MIME_TYPE + "=?"; ContentResolver contentResolver = c.getContentResolver(); if (contentResolver != null) { Cursor matchingIndex = contentResolver.query(uri, ne...