Change the file extension for files in a folder?

The open on the source file is unnecessary, since os.rename only needs the source and destination paths to get the job done. Moreover, os.rename always returns None, so it doesn’t make sense to call open on its return value. import os import sys folder=”E:/…/1936342-G/test” for filename in os.listdir(folder): infilename = os.path.join(folder,filename) if not os.path.isfile(infilename): continue … Read more

Django – Create A Zip of Multiple Files and Make It Downloadable [duplicate]

I’ve posted this on the duplicate question which Willy linked to, but since questions with a bounty cannot be closed as a duplicate, might as well copy it here too: import os import zipfile import StringIO from django.http import HttpResponse def getfiles(request): # Files (local path) to put in the .zip # FIXME: Change this … Read more

Parse key value pairs in a text file

I suggest storing the values in a dictionary instead of in separate local variables: myvars = {} with open(“namelist.txt”) as myfile: for line in myfile: name, var = line.partition(“=”)[::2] myvars[name.strip()] = float(var) Now access them as myvars[“var1”]. If the names are all valid python variable names, you can put this below: names = type(“Names”, [object], … Read more

How to check if a file is open by another process (Java/Linux)?

Here’s a sample how to use lsof for unix based systems: public static boolean isFileClosed(File file) { try { Process plsof = new ProcessBuilder(new String[]{“lsof”, “|”, “grep”, file.getAbsolutePath()}).start(); BufferedReader reader = new BufferedReader(new InputStreamReader(plsof.getInputStream())); String line; while((line=reader.readLine())!=null) { if(line.contains(file.getAbsolutePath())) { reader.close(); plsof.destroy(); return false; } } } catch(Exception ex) { // TODO: handle exception … … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)