Turns out the 'with' statement in Python is fairly straight forward. Here is an article (oldie but goodie) that gives a quick thumbnail sketch of how that statement works:
http://effbot.org/zone/python-with-statement.htm
On another note, this is the first blog of the New Year!
Tuesday, January 6, 2015
Sunday, November 23, 2014
Parsing Excel with Python
Cos sometimes you don't want to deal with xml, csv, json or any other text format. Check out https://openpyxl.readthedocs.org/en/latest/.
Tuesday, September 23, 2014
Design Patterns
I generally avoid buying computer books because they become outdated very quickly. However, Design Patterns by Gamma, Helm, Johnson, and Vlissides is an exception (probably due to its general nature):
http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_1?s=books&ie=UTF8&qid=1411492186&sr=1-1&keywords=design+patterns
This book makes me rethink how I approach object oriented programming.
http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_1?s=books&ie=UTF8&qid=1411492186&sr=1-1&keywords=design+patterns
This book makes me rethink how I approach object oriented programming.
Tuesday, September 9, 2014
Setting the PYTHONPATH with the Powershell permanently
I actually got a lot of tips on how to do this through this article:
http://technet.microsoft.com/en-us/library/ff730964.aspx
If you have the .NET Framework, you can do the following:
> [Environment]::SetEnvironmentVariable("PYTHONPATH", "D:/mypath", "User")
In order to see the changes, you need to open a new Powershell.
http://technet.microsoft.com/en-us/library/ff730964.aspx
If you have the .NET Framework, you can do the following:
> [Environment]::SetEnvironmentVariable("PYTHONPATH", "D:/mypath", "User")
In order to see the changes, you need to open a new Powershell.
Thursday, August 21, 2014
Setting the PYTHONPATH with Powershell
Powershell is the Windows hacker's best friend until it isn't. Actually, I really do enjoy the power you get from Powershell. However, figuring out how to set my python path in the shell was a frustrating experience that I hope to spare other users from.
PS C:\Users\spearsc> Get-ChildItem Env:PYTHONPATH
Name Value
---- -----
PYTHONPATH r:/env
PS C:\Users\spearsc> $env:PYTHONPATH = "D:/localenv"
PS C:\Users\spearsc> Get-ChildItem Env:PYTHONPATH
Name Value
---- -----
PYTHONPATH D:/localenv
There you have it! Pretty sure this setting is not permanent, which is fine for testing purposes.
PS C:\Users\spearsc> Get-ChildItem Env:PYTHONPATH
Name Value
---- -----
PYTHONPATH r:/env
PS C:\Users\spearsc> $env:PYTHONPATH = "D:/localenv"
PS C:\Users\spearsc> Get-ChildItem Env:PYTHONPATH
Name Value
---- -----
PYTHONPATH D:/localenv
There you have it! Pretty sure this setting is not permanent, which is fine for testing purposes.
Thursday, August 7, 2014
Dealing with the error message: "Cross origin requests are only supported for HTTP."
I know I have dealt with this before, but I found a Stack Overflow thread that does a pretty good job of explaining this problem. Plus, the thread shows you how to use Python to fire up a simple web server to get around the issue:
http://stackoverflow.com/questions/20041656/xmlhttprequest-cannot-load-file-cross-origin-requests-are-only-supported-for-ht
http://stackoverflow.com/questions/20041656/xmlhttprequest-cannot-load-file-cross-origin-requests-are-only-supported-for-ht
Thursday, July 17, 2014
Multiprocessing Versus Threading in Python
I keep forgetting the difference between multiprocessing and threading in Python. This Stack Overflow thread explains the difference between the two pretty well:
http://stackoverflow.com/questions/3044580/multiprocessing-vs-threading-python
http://stackoverflow.com/questions/3044580/multiprocessing-vs-threading-python
Subscribe to:
Posts (Atom)