Import from sibling directory

as a literal answer to the question ‘Python Import from parent directory‘: to import ‘mymodule’ that is in the parent directory of your current module: import os parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) os.sys.path.insert(0,parentdir) import mymodule edit Unfortunately, the __file__ attribute is not always set. A more secure way to get the parentdir is through the inspect module: … Read more

guidelines for where to put classes in Rails apps that don’t fit anywhere

Good question – i don’t have a concrete answer for you but I recommend checking out this post – http://blog.codeclimate.com/blog/2012/02/07/what-code-goes-in-the-lib-directory/ – be sure to read through all the comments on a current project i have a ton of non-ActiveRecord objects under app/models, it works but not ideal i put ‘re-useable’ non application specific code under … Read more

Deleting read-only directory in Python

shutil.rmtree can take an error-handling function that will be called when it has problem removing a file. You can use that to force the removal of the problematic file(s). Inspired by http://mail.python.org/pipermail/tutor/2006-June/047551.html and http://techarttiki.blogspot.com/2008/08/read-only-windows-files-with-python.html: import os import stat import shutil def remove_readonly(func, path, excinfo): os.chmod(path, stat.S_IWRITE) func(path) shutil.rmtree(top, onerror=remove_readonly) (I haven’t tested that snippet out, … Read more

How to get files in a relative path in C#

To make sure you have the application’s path (and not just the current directory), use this: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.getcurrentprocess.aspx Now you have a Process object that represents the process that is running. Then use Process.MainModule.FileName: http://msdn.microsoft.com/en-us/library/system.diagnostics.processmodule.filename.aspx Finally, use Path.GetDirectoryName to get the folder containing the .exe: http://msdn.microsoft.com/en-us/library/system.io.path.getdirectoryname.aspx So this is what you want: string folder = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) … Read more

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