35
голосов
3ответов
32228 просмотров

String arguments in python multiprocessing

I'm trying to pass a string argument to a target function in a process. Somehow, the string is interpreted as a list of as many arguments as there are characters. This is the code: import multiprocessing def write(s): print s write('hello') p = multiprocessing.Process(target=write, args=...

0
голосов
2ответов
1356 просмотров

How do i use perspective projection in this library

i found a library called pyeuclid and it seems to do what i want in respect to 3D math. it contins a 3D vector class and a 4X4 matrix class capable of transformations like rotate,translate and scale. matrix creation is simple, simply pass along the arguments and the matrix is created. >&gt...

2
голосов
2ответов
7256 просмотров

Convert from hex string to unicode

How can i convert the 'dead' string to an unicode string u'\xde\xad'? Doing this: from binascii import unhexlify out = ''.join(x for x in [unhexlify('de'), unhexlify('ad')]) creates a <type 'str'> string '\xde\xad' Trying to use the Unicode.join() like this: from binascii import unhex...

2
голосов
1ответов
82 просмотров

how do I get only the time in models

How do I format datetime to give me only the time in my model

102
голосов
7ответов
71682 просмотров

How can I distribute python programs?

My application looks like this: main.py windows/ __init__.py mainwindow.py ... model/ __init__.py orders.py ... resources/ image1.png logo.jpg ... The program is started with main.py. Is there a good way to create a 'final' application out of it? I'm thinki...

1
голосов
1ответов
285 просмотров

relevant query to what is the best python method for encryption

I tried to use the gnupg.py module encryption decryption function named " def test_encryption_and_decryption(self): " Could i use this function by passing the key or fingerprint retrieved from public key server. I am getting the key by this : retk = urllib.urlopen('http://pool.sks-keyserver...

0
голосов
1ответов
406 просмотров

Install custom modules in a python virtual enviroment

I am doing some pylons work in a virtual python enviorment, I want to use MySQL with SQLalchemy but I can't install the MySQLdb module on my virtual enviorment, I can't use easyinstall because I am using a version that was compiled for python 2.6 in a .exe format, I tried running the install fro...

1
голосов
2ответов
532 просмотров

How to get multiple properties at the same time?

I am using Appscript - a Python interface to AppleScript - in a project of mine that basically gets data from a Mac application. Here is a sample code: asobj = app('Things').to_dos()[0] self.id = asobj.id() self.name = asobj.name() self.status = asobj.status() Every invocation...

1
голосов
1ответов
326 просмотров

PyQt: Displaying QTextEdits over the window

I want to display some QTextEdits over my main window at arbitrary locations. Below is my first attempt. It doesn't quite work. If I create the text edits before I show the window, the text edits appear, but if I create them after I have shown the window they don't appear. What's up with that...

1
голосов
3ответов
1482 просмотров

How to make complex contains queries in Django?

I need to make query like this: WHERE Comment like '%ev% 3628%' or Comment like '%ew% 3628%' the number '3628' is a parametr. So I've tried in my view: First try: wherestr = "Comment like '%%ev%% %s%%' or Comment like '%%ew%% %s%%'" % (rev_number, rev_number) comment_o = Issuecomme...

2
голосов
2ответов
2181 просмотров

PIL vs Python-GD for crop and resize

I am creating custom images that I later convert to an image pyramid for Seadragon AJAX. The images and image pyramid are created using PIL. It currently take a few hours to generate the images and image pyramid for approximately 100 pictures that have a combined width and height of about 32,00...

1045
голосов
31ответов
1238020 просмотров

How do I get time of a Python program's execution?

I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running. I've looked at the timeit module, but it seems it's only for small snippets of code. I want to time the whole program.

72
голосов
3ответов
73511 просмотров

python: delete non-empty dir

How do I delete a possibly non-empty dir in Python. The directory may have nested subdirectories many levels deep.

6
голосов
4ответов
6758 просмотров

non-blocking read/log from an http stream

I have a client that connects to an HTTP stream and logs the text data it consumes. I send the streaming server an HTTP GET request... The server replies and continuously publishes data... It will either publish text or send a ping (text) message regularly... and will never close the connect...

18
голосов
9ответов
14134 просмотров

3d Math Library For Python

i'm looking for a 3d math library in python or with python bindings. it needs to handle rotation, translation, perspective projection, everything basically. what im NOT looking for is a library aimed at drawing on the screen, googling for hours only led to 3d libraries bent on rendering someth...

3
голосов
4ответов
261 просмотров

Should you import all classes you use in Python?

Python's lack of static typing makes it possible to use and rely on classes without importing them. Should you import them anyway? Does it matter? Example someclass.py class SomeClass: def __init__(self, some_value): self.some_value = some_value someclient.py class SomeClient: ...

1
голосов
7ответов
375 просмотров

Recommendations for perl-to-python interoperation?

We have a sizable code base in Perl. For the forseeable future, our codebase will remain in Perl. However, we're looking into adding a GUI-based dashboard utility. We are considering writing the dashboard in Python (using tkinter or wx). The problem, however, is that we would like to leverage our...

27
голосов
4ответов
27596 просмотров

How do I html-escape dangerous unsanitized input in jinja2?

Can I do it inside the template or must it be done in python code? I have a variable that may contain dau&s chars. How do I escape it in jinja2?

76
голосов
7ответов
69080 просмотров

Circular import dependency in Python

Let's say I have the following directory structure: a\ __init__.py b\ __init__.py c\ __init__.py c_file.py d\ __init__.py d_file.py In the a package's __init__.py, the c package is imported. But c_file.py imports a...

8
голосов
2ответов
11845 просмотров

python: run a process with timeout and capture stdout, stderr and exit status

Possible Duplicate: subprocess with timeout What is the easiest way to do the following in Python: Run an external process Capture stdout in a string, stderr, and exit status Set a timeout. I would like something like this: import proc try: status, stdout, stderr = proc.run(["l...

2
голосов
6ответов
2308 просмотров

How to select an item from a list with known percentages in Python

I wish to select a random word from a list where the is a known chance for each word, for example: Fruit with Probability Orange 0.10 Apple 0.05 Mango 0.15 etc How would be the best way of implementing this? The actual list I will take from is up to 100 items longs and the % do not all ta...

1
голосов
1ответов
338 просмотров

In Django, How Do I Move Images When A Dynamic Path Changes?

I have a Django app with an image field (a custom ThumbnailImageField type) that auto-generates the file path for an image based on the title, type, and country of the item the image is attached to (upload_ to = get_ image_path). Here's how: def get_image_path(instance, filename): dir = 'i...

0
голосов
3ответов
199 просмотров

Python AppEngine And HTML

I have a simple Hello World application in Python that i'm using with AppEngine, but i want to insert this in a HTML file, like this: I have a file called test.html and on it i have this snippet: <center><img src="test.png></center> // Here comes the Python App // I want to p...

7
голосов
4ответов
17772 просмотров

Efficient way to find the largest key in a dictionary with non-zero value

I'm new Python and trying to implement code in a more Pythonic and efficient fashion. Given a dictionary with numeric keys and values, what is the best way to find the largest key with a non-zero value? Thanks

15
голосов
1ответов
17797 просмотров

How to dereference a memory location from python ctypes?

I want to replicate the following c code in python ctypes: main() { long *ptr = (long *)0x7fff96000000; printf("%lx",*ptr); } I can figure out how to call this memory location as a function pointer but not just do a normal dereference: from ctypes import * """ >>> fptr = CFUNCTYP...

3
голосов
3ответов
1463 просмотров

Can one prevent Genshi from parsing HTML entities?

I have the following Python code using Genshi (simplified): with open(pathToHTMLFile, 'r') as f: template = MarkupTemplate(f.read()) finalPage = template.generate().render('html', doctype = 'html') The source HTML file contains entities such as ©, ™ and ®. Gensh...

13
голосов
6ответов
11602 просмотров

sending a non-blocking HTTP POST request

I have a two websites in php and python. When a user sends a request to the server I need php/python to send an HTTP POST request to a remote server. I want to reply to the user immediately without waiting for a response from the remote server. Is it possible to continue running a php/python scr...

3
голосов
2ответов
2076 просмотров

appengine remote api unable to login

When I go to appengine.google.com/a/mydomain.com i am able to login and see all my apps and administer them. However, when I try to use the remote_api the same username/password does not work. I'm using the interactive console code from http://code.google.com/appengine/articles/remote_api.html

2
голосов
2ответов
3610 просмотров

Cherrypy server unavailable from anything but localhost

I am having an issue with cherrypy that looks solved, but doesn't work. I can only bind on localhost or 127.0.0.1. Windows XP Home and Mac OS X (linux untested), cherrypy 3.1.2, python 2.5.4. This is the end of my app: global_conf = { 'global': { 'server.environment= "production"' ...

4
голосов
2ответов
4463 просмотров

webbrowser.get("firefox") on a Mac with Firefox "could not locate runnable browser"

I think what I need here is to know which magic command-line or OSA script program to run to start up a URL in an existing Firefox browser, if one is running, or to also start up Firefox if it isn't. On Mac. I'm testing a Python program (Crunchy Python) which sets up a web server then uses Firef...