Is there any reason to do anything more complicated than one of these two lines when you want to clear a list in Python:
old_list = []
old_list = list()
The reason I ask is that I just saw this in some running code:
del old_list[ 0:len(old_list) ]
...
I have a dictionary. I want to take only the words containing a simple word pattern (i.e. "cow") and write them to another file. Each line starts with a word and then the definition. I'm still extremely new at python so I don't have a good grasp of the syntax, but the pseudocode in my head looks something like:
infile = open('C:/infile....
Is there a way to sum up a list of numbers faster than with a for-loop, perhaps in the Python library? Or is that something really only multi-threading / vector processing can do efficiently?
Edit: Just to clarify, it could be a list of any numbers, unsorted, just input from the user.
...
I have a multi-layered PSD, with one specific layer being non-rasterized text. I'm trying to figure out a way I can, from a bash/perl/python/whatever-else program:
load the PSD
edit the text in said layer
flatten all layers in the image
save as a web-friendly format like PNG or JPG
I immediately thought of ImageMagick, but I don't t...
I want to do something like the following
class A:
def static_method_A():
print "hello"
def main(param=A):
param.static_method_A()
I want this to be equivalent to A.static_method(). Is this possible?
...
Say I want to manipulate some files on a floppy drive or a USB card reader. How do I check to see if the drive in question is ready? (That is, has a disk physically inserted.)
The drive letter exists, so os.exists() will always return True in this case. Also, at this point in the process I don't yet know any file names, so checking to...
In the following code segment:
try:
raise Bob()
except Fred:
print "blah"
How is the comparison of Bob and Fred implemented?
From playing around it seems to be calling isinstance underneath, is this correct?
I'm asking because I am attempting to subvert the process, specifically I want to be able to construct a Bob such that...
hi,
I am trying to get status msg of the user in my facebook app.
But getting error in loading page.
here is the code:
user, created = FacebookUser.objects.get_or_create(id = request.facebook.uid)
key = request.facebook.session_key
some = request.facebook.friends.get()
status_msg = request.facebook.status.get(request.facebook.uid)
fr...
How can I open __init__.pyc here?
>>> import stompservice
<module 'stompservice' from 'C:\Python25\lib\site-packages\stompservice-0.1.0-py2.5.egg\stompservice\__init__.pyc'>
All I see in C:\Python25\lib\site-packages\ is the .egg file, but where are the internal files of the package?
...
I'm using a 3rd party DLL to load in some raw image data, and I want to use this raw image data as a texture in openGL. However, the c function returns a void*, and I need to somehow convert this so it will work as the "pixels" parameter to glTexImage2D. Right now my code looks like something this:
data = c_void_p(vdll.vlImageGetData(...
I'm trying to get hold of Django. I use Pydev on Eclipse. I have written a simple signup page that I can't get to work. Eclipse complains that User.DoesNotExist is undefined. Most likely, I am missing something trivial. Here's the relevant portion of the code:
from django.contrib.auth.models import User
...
class SignUpForm (forms.Form)...
from shutil import copy
f = open(r'C:\temp.txt', 'r')
for i in f.readlines():
print i
copy(i,r"C:\opencascade")
f.close()
I am reading path from temp.txt file which has 500 lines each line is a path for specific file to be copied to location "C:\opencascade"
How to convert 'i' in above code to be raw string to make the ...
I have a similar model
Class Student(models.Model):
"""A simple class which holds the basic info
of a student."""
name = models.CharField(max_length=50)
age = models.PositiveIntegerField()
photo = models.ImageField(upload_to='foobar', blank=True, null=True)
As we can see photo field is optional. I wanted all the students who have the...
Except for CPython, which other Python implementations are currently usable for production systems?
The questions
What are the pros and cons of the various Python implementations?
I have been trying to wrap my head around the PyPy project. So, fast-foward 5-10 years in the future what will PyPy have to offer over CPython, Jython, and...
Say I have the following model:
class Schedule(db.Model):
tripCode = db.StringProperty(required=True)
station = db.ReferenceProperty(Station, required=True)
arrivalTime = db.TimeProperty(required=True)
departureTime = db.TimeProperty(required=True)
And let's say I have a Station object stored in the var foo.
How d...
Are there real world adaptations of JaikuEngine on Google App Engine?
(Question from my boss which wants to use it instead writing our own system)
...
How the methods invocation works in Python?
I mean, how the python virtual machine interpret it.
It's true that the python method resolution could be slower in Python that in Java.
What is late binding?
What are the differences on the reflection mechanism in these two languages?
Where to find good resources explaining these aspects?
...
Can someone provide me code to encrypt / decrypt using m2crypto aes256 CBC using Python
...
If I define a function:
def f(x):
return x+3
I can later store objects as attributes of the function, like so:
f.thing="hello!"
I would like to do this from inside the code of the function itself. Problem is, how do I get a reference to the function from inside itself?
...
From an example you can see a multiple OR query filter:
Article.objects.filter(Q(pk=1) | Q(pk=2) | Q(pk=3))
For example, this results in:
[<Article: Hello>, <Article: Goodbye>, <Article: Hello and goodbye>]
However, I want to create this query filter from a list. How to do that?
e.g. [1, 2, 3] -> Article.obj...