Hi!
I am making a blog and store the publishing date of a blog post in the datastore. It looks like this:
post.date = datetime.datetime.now()
It now displays like: 2010-10-04 07:30:15.204352 But I want the datetime to be displayed differently. How (and where) can I set that how the date is displayed? I'd like to set the date format l...
I have written a python script to transfer files/folders between two machines. I have used scp for this and have included it as import scp
but it's giving me this error:
ImportError: No module named scp.
How can I fix it?
...
Hello.
When using threading module and Thread() class, SIGINT (Ctrl+C in console) could not be catched.
Why and what can I do?
Simple test program:
#!/usr/bin/env python
import threading
def test(suffix):
while True:
print "test", suffix
def main():
for i in (1, 2, 3, 4, 5):
threading.Thread(target=test, ar...
This is probably a silly question.
I am experimenting with python doctest, and I try to run this example
ending with
if __name__ == "__main__":
import doctest
doctest.testfile("example.txt")
I have put "example.txt" in the same folder as the source file containing the example code, but I get the following error:
Traceback (...
I want to make '==' operator use approximate comparison in my program: float values x and y are equal (==) if
abs(x-y)/(0.5(x+y)) < 0.001
What's a good way to do that? Given that float is a built-in type, I don't think I can redefine the == operator, can I?
Note that I would like to use other features of float, the only thing that I'...
hello ,
i have a mysql tables that uses lock-write mechanism. the lock might go for too long (we're talking about 1-2 minutes here).
i had to make a check if the table is in use or not before the update is done (using beforeUpdate signal)
but after checking and returning that my table is in use , system hang until the other user unl...
I have an application that needs to generate its models on runtime.
This will be done according to the current database scheme.
How can it be done?
How can I create classes on runtime in python?
Should I create a json representation and save it in a database and then unserialize it into a python object?
...
How can I convert a negative number to positive in Python? (And keep that positive value.)
...
Hi,
I have a struct in a dll that only contains function pointers (ie a vtable) that I would like to interact with in python (for test purposes). I am having a bit of trouble working out how to do this using ctypes.
What I have is:
struct ITest
{
virtual char const *__cdecl GetName() = 0;
virtual void __cdecl SetName(c...
I have a wx.python application that takes some files and processes them when a button is clicked. I need to process them in parallel.
I use this code inside the bound button function:
my_pool = multiprocessing.Pool(POOLSIZE)
results=[digest_pool.apply_async(self.fun, [args]) for file in list_files() ]
my_pool.close()
my_pool...
I would like to perform an operation on an argument based on the fact that it might be a map-like object or a sequence-like object. I understand that no strategy is going to be 100% reliable for type-like checking, but I'm looking for a robust solution.
Based on this answer, I know how to determine whether something is a sequence and I ...
I have a bit of code that attempts to find the contents of an array at indices specified by another, that may specify indices that are out of range of the former array.
input = np.arange(0, 5)
indices = np.array([0, 1, 2, 99])
What I want to do is this:
print input[indices]
and get
[0 1 2]
But this yields an exception (as exp...
Hi Folks,
I'dl like to generate some alphanumeric passwords in python. Some possible ways are:
import string
from random import sample, choice
chars = string.letters + string.digits
length = 8
''.join(sample(chars,length)) # way 1
''.join([choice(chars) for i in range(length)]) # way 2
But I don't like both because:
way 1 only un...
I had a string which is stored in a variable myvar="Rajasekar SP" . I want to split it with delimiter like we do using explode in PHP. But dont know the alternative for the explode in python. Please help
...
A previous question with the same title as mine has been posted, with (I think) the same question, but had other problems in the code. I was not able to determine if that case was identical to mine or not.
Anyway, I want to replace an element within a list in a list.
Code:
myNestedList = [[0,0]]*4 # [[0, 0], [0, 0], [0, 0], [0, 0]]
myN...
I am trying to use the SetProductKey method of Win32_WindowsProductActivation to set the windows xp key for a custom need of mine as per the second Microsoft vbs script here :http://support.microsoft.com/kb/328874. No matter what method i use i always get shut down. I have tried wmi:
import wmi
c = wmi.WMI()
c.Win32_WindowsProductActiva...
Can anyone tell me what's wrong in this code:
#!/usr/local/bin/python
import os
import string, sys
a='sys.argv[1]'
b='sys.argv[2]'
os.system("scp a:/export/home/sample/backup.sql b:/home/rushi/abc.sql")
it's giving the following error:
ssh: a: node name or service name not known
...
Using pypdf python module how to read the following pdf file http://www.envis-icpe.com/pointcounterpointbook/Hindi_Book.pdf
# -*- coding: utf-8 -*-
from pyPdf import PdfFileWriter, PdfFileReader
import pyPdf
def getPDFContent(path):
content = ""
# Load PDF into pyPDF
pdf = pyPdf.PdfFileReader(file(path, "rb"))
# Iterate pag...
When an attribute is not found object.__getattr__ is called. Is there an equivalent way to intercept undefined methods?
...
I need to create a Python string consisting of non-ascii bytes to be used as a command buffer in a C module.
I can do that if I write the string by hand:
mybuffer = "\x00\x00\x10"
But I cannot figure out how to create the string on the fly if I have a set of integers which will become the bytes in the string. Concatenating an integer ...