I didn’t really know that you escape a % in a string by itself, not \ or anything.
So there you have it..
"1%% %s" % "hello" returns 1% hello
I didn’t really know that you escape a % in a string by itself, not \ or anything.
So there you have it..
"1%% %s" % "hello" returns 1% hello
→ Leave a CommentCategories: Life
#!admin.py
from django.contrib.admin.sites import AdminSite
my_new_admin = AdminSite()
#!urls.py
from myproject.admin import my_new_admin
(r'^my_new_admin/(*.)', my_new_admin.root)
→ Leave a CommentCategories: Life
If you get this error, it might be because you are returning Http404 instead of raise ing it.
You must raise django.http.Http404, not return it.
That’s all!
→ Leave a CommentCategories: Life
Truebosko said it well: [530] i must say you are a man of not-so well known django techniques
>>>from django.forms.models import model_to_dict
>>>model_to_dict(model_instance)
Out:
{'id': 1,
'name': u'joe'
}
etc.
I’m sure i’ll use it in the future.
→ 1 CommentCategories: Life
Run linux to administer a linux server. I’m running the same OS on my desktop as my server partition — doesn’t it make sense to do so?
To me it’s more about the focus I get from switching over. Minimizing distractions is the goal of programming. Working on Ubuntu puts me in the same place as my server, not cluttered with a completely different OS, remotely working with a combination of putty terminals and or tortoise SVN on windows.
Nah. This is much better.
It helps that there are all of daft punk’s albums on this side of the border. What better to drown out all noise?
Alright, here we go.
→ Leave a CommentCategories: Life · Linux
Pythons CSV module turns your csv into an iterator for efficiency and your data is gone after you do myreader.next()
I just wanted a quick way to add and edit entries in our database of wines via a spreadsheet. I suppose I could have used pyExcelerator, but I magically decided to go with CSV.
Trying to write on the same file as you are reading from, even if you do open(’blah’, ‘rw+’) won’t exactly work.
My solution was just to write a function that takes a path as it’s argument, and have the function read from the CSV from that path & create a reader/writer instance, with the writer file being temporary. It’s important to keep a reference to it, like:
fread=open(path, 'r')
fwrite=open(path.replace('.csv','_temp'), 'w')
Then I read as I wrote into this temporary file called whateverfile_temp. Specifically, I needed the csv to be updated with primary key values from the database if an object was created so that future uploads of the same file would not result in duplicates but UPDATE.
I kept having trouble because I couldn’t close the file when I started using it as the official docs do: reader/writer = csv.reader/writer(open('blah','rw')) It just resulted in a mangled csv.
But now I could close the files, then replace the original csv that was just read with the new one written.
fread.close()
fwrite.close()
os.rename(mypath.replace('.csv', '_temp'), mypath)
Sure, inefficient, but for me it will come in very useful.
→ Leave a CommentCategories: Django · Python
As a newbie, I often couldn’t find information on file write modes, like rb, U, etc.
Python has great documentation…. open a python interpreter, type help(file) and you will see:
class file(object)
file(name[, mode[, buffering]]) -> file object
Open a file. The mode can be ‘r’, ‘w’ or ‘a’ for reading (default),
writing or appending. The file will be created if it doesn’t exist
when opened for writing or appending; it will be truncated when
opened for writing. Add a ‘b’ to the mode for binary files.
Add a ‘+’ to the mode to allow simultaneous reading and writing.
If the buffering argument is given, 0 means unbuffered, 1 means line
buffered, and larger numbers specify the buffer size.
Add a ‘U’ to mode to open the file for input with universal newline
support. Any line ending in the input file will be seen as a ‘\n’
in Python. Also, a file so opened gains the attribute ‘newlines’;
the value for this attribute is one of None (no newline read yet),
’\r’, ‘\n’, ‘\r\n’ or a tuple containing all the newline types seen.
‘U’ cannot be combined with ‘w’ or ‘+’ mode.
Mmmm. Perfect. One of the reason why I like Django so much is the documentation. Freaking amazing! So many python questions have been self answered by just typing help( blah ).
→ Leave a CommentCategories: Python
You know, I learned this and completely forgot after months of not dealing with it. Google searches are so difficult to reach the right subject.
I’m certain this will be something I refer to in the future..
Setting environment variables via Python is as simple as:
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
Of course, this doesn’t permanently set the variable, but if you have a script that needs that envvar, perfect.
Enjoy.
→ Leave a CommentCategories: Django · Python
Okay, I’ve been having intermittent photoshop SUPER slowdowns and finally tracked it down (i think). We’re talking, “I can’t even use the internet” slowdowns, with mouse skippage and all of that stuff.
The bottom line might be that you are using Adobe’s file viewer in thumbnail view. I think the thumbnailer is looking through / reading the contents of EVERY file you flip across to try to generate a thumbnail, which would explain the seemingly random processes I found where AdobeAssetServicesCS3 was reading into stuff like huge CD ISOs on my desktop.
Googling this term gives me absolutely nothing. I expect this blog post to get to the top of the google results for it (AdobeAssetServicesCS3) because all I found were auto generated pages.
Anyways, I tracked down an old post from some CS3 beta people who asked about this same exe. I can’t read the thread they linked, but they posted an excerpt:
“It sounds like you are using the Adobe Dialog for Open or Save correct and most likely have the view set to show Thumbnails. That process provides the ability to generate thumbnails for various file types in those dialogs. We’re going to take a look into what might be going on here. Thanks for the post.
- Adobe Photoshop QE “
So there you have it. Go back to OS filesystem view.
My System specs are:
Vista Ultimate 64 bit
E6600 @ 3.0ghz
4gb DDR2-1066 RAM
Seagate 7200.9 RAID 0
I’m not sure what systems are affected, but it could be a 64bit issue if nobody is crying about it on the internet aside from myself.
Hope it helped somebody!
→ Leave a CommentCategories: Life
UPDATE: I have since found out that the problem I mention below with the random reads was caused by something else, a certain Adobe CS3 program that was attempting to generate thumbnails by digging into 1.5gb Data images. Still, SuperFetch does account for some random reads.
Turning off the indexing service was great. Finding out about SuperFetch was even better.
SuperFetch is a technology that pre-loads commonly used applications into the memory to reduce their load times. It’s based on the “prefetcher” function in Windows XP. [7]
The intent is to improve performance in situations where running an anti-virus scan or back-up utility would result in otherwise recently-used information being paged out to disk, or disposed from in-memory caches, resulting in lengthy delays when a user comes back to their computer after a period of non-use.
SuperFetch also keeps track of what times of day that applications are used, which allows it to intelligently pre-load information that is expected to be used in the near future
I think the bottom line is that nothing can intelligently decide what is best for you. While “wasted CPU cycles” sounds, well, wasteful, I could care less if the alternative is some background process I have no idea about slowing down my computer when I need it the most.
SuperFetch: “keeps track of what times of day that applications are used, which allows it to intelligently pre-load…” so this is why a completely random CD ISO on my desktop was being accessed at full read. The ‘last time’ it was accessed was upon installing the contents. Pre-loading that huge image would have done nothing for me. I think it might serve a cause if you are amazingly predictable and SuperFetch has a long time to get to know your patterns / determine what ISNT a pattern, like my single use ISO. With that disclaimer out of the way, I’ll still never use it again.
To disable SuperFetch, go to Start > type in services.msc > find SuperFetch, go to properties, change startup type to disable, then right click SuperFetch and click stop.
It’s amazing having a quiet computer now.
The main reason I invest in high end computers is: to save myself from the frustration of dealing with slow machines. The waiting game as you think; “really? more problems?” It is THE biggest productivity killer I have ever experienced. Becoming frustrated to the point that you simply can’t work. While I would recommend Linux to get rid of this issue (talk about screaming fast, you can tell down to the mouse clicks and windows opening that it is snappy fast), I’m using vista at the moment to hold on to my precious photoshop workflow.
Let me know if anyone agrees, or wants to agree to disagree.
→ Leave a CommentCategories: Life