Limit file format when using ?

Strictly speaking, the answer is no. A developer cannot prevent a user from uploading files of any type or extension. But still, the accept attribute of <input type = “file”> can help to provide a filter in the file select dialog box provided by the user’s browser/OS. For example, <!– (IE 10+, Edge (EdgeHTML), Edge … Read more

Writing a list to a file with Python, with newlines

Use a loop: with open(‘your_file.txt’, ‘w’) as f: for line in lines: f.write(f”{line}\n”) For Python <3.6: with open(‘your_file.txt’, ‘w’) as f: for line in lines: f.write(“%s\n” % line) For Python 2, one may also use: with open(‘your_file.txt’, ‘w’) as f: for line in lines: print >> f, line If you’re keen on a single function … Read more

Is there a way to check if a file is in use?

Updated NOTE on this solution: Checking with FileAccess.ReadWrite will fail for Read-Only files so the solution has been modified to check with FileAccess.Read. ORIGINAL: I’ve used this code for the past several years, and I haven’t had any issues with it. Understand your hesitation about using exceptions, but you can’t avoid them all of the … Read more

“Cross origin requests are only supported for HTTP.” error when loading a local file

My crystal ball says that you are loading the model using either file:// or C:/, which stays true to the error message as they are not http:// So you can either install a webserver in your local PC or upload the model somewhere else and use jsonp and change the url to http://example.com/path/to/model Origin is … Read more

How to create a file in memory for user to download, but not through server?

Simple solution for HTML5 ready browsers… function download(filename, text) { var element = document.createElement(‘a’); element.setAttribute(‘href’, ‘data:text/plain;charset=utf-8,’ + encodeURIComponent(text)); element.setAttribute(‘download’, filename); element.style.display = ‘none’; document.body.appendChild(element); element.click(); document.body.removeChild(element); } form * { display: block; margin: 10px; } <form onsubmit=”download(this[‘name’].value, this[‘text’].value)”> <input type=”text” name=”name” value=”test.txt”> <textarea name=”text”></textarea> <input type=”submit” value=”Download”> </form> Usage download(‘test.txt’, ‘Hello world!’);

How do I remove/delete a folder that is not empty?

import shutil shutil.rmtree(‘/folder_name’) Standard Library Reference: shutil.rmtree. By design, rmtree fails on folder trees containing read-only files. If you want the folder to be deleted regardless of whether it contains read-only files, then use shutil.rmtree(‘/folder_name’, ignore_errors=True)

Remove a symlink to a directory

# this works: rm foo # versus this, which doesn’t: rm foo/ Basically, you need to tell it to delete a file, not delete a directory. I believe the difference between rm and rmdir exists because of differences in the way the C library treats each. At any rate, the first should work, while the … Read more

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