python

best scripting language to develop rational clearcase plugin to extract some functionalities

Dear all, I just want to know about clearcase. Basically i want to write some application which will extract some files from clearcase vobs. Right now i am not getting any clue that which scripting language like python or perl i should use. basically i am looking for perl scripting for that. I also want to know is there any proper docu...

Improve fetch time and this function's performance

I am searching the Final model (defined below) with a query which filters on its name property. This query is taking about 2200ms to execute on the development server. How can I speed it up? Here is an AppStats screenshot. I was filtering on the created field too, but this was taking in excess of 10000ms so I've removed that part of ...

Verifying constructor parameters in Python

What is the best-practice method for verifying constructor params in Python? I am new to the language, and am using raise: class Breakfast(object): def __init__(self, spam=None, eggs=0): if not spam: raise Error("Error: no spam") Is this stupid, or what? Thanks! ...

Python cached list

Hi, I have a module which supports creation of geographic objects using a company-standard interface. After these objects are created, the update_db() method is called, and all objects are updated into a database. It is important to have all objects inserted in one session, in order to keep counters and statistics before updating a pro...

Create a reference to a variable (similar to PHP's "=&")?

In PHP one can create a reference variable, so that two named variables can look at the same value: $a = 1; $b =& $a; echo $a; // 1 echo $b; // 1 $b = 2; echo $a; // 2 I'm looking to achieve something similar in Python. Specifically, I want to create a reference to an object's property, eg: class Foo(object): @property def bar(se...

Python: Import module CairoPlot fails

I'm using cairo plot to draw charts with python. I followed the instruction as stated on the website to install Cairplot, http://linil.wordpress.com/2008/09/16/cairoplot-11/ : sudo apt-get install bzr bzr branch lp:cairoplot/1.1 The installation completes successfully. I then try to import the modules in python: >>> import CairoPl...

Writing file line to Django model field

I can't seem to write a line from a file to a field of a Django model. The field is described in the model as: text = models.TextField(null=True, blank=True, help_text='A status message.') However, when I attempt to create a new object I cannot fill this field using the readline function: file = open(filename, 'r') str = file.readli...

Using Python property() inside a method.

Assuming you know about Python builtin property: http://docs.python.org/library/functions.html#property I want to re-set a object property in this way but, I need to do it inside a method to be able to pass to it some arguments, currently all the web examples of property() are defining the property outside the methods, and trying the ob...

Anjuta IDE - Simple Python Question

I'm new to Linux, Python and the Anjuta IDE. I have created a new file called hello.py. This is the contents of that file: #!/usr/bin/env python print "Hello World!" All I want to do is run this in the terminal. I go to Run > Execute but I get the following error message: Program 'home/joe/Programming/Python//hello.py' does not h...

Calling a Python function in C++ with Swig

Here is my c++ code: void callMethod(void (*someMethod)()) { (*someMethod)(); } My Swig .i file is: %module test %{ #define SWIG_FILE_WITH_INIT extern void callMethod(void (*someMethod)()); %} %typemap (in) void* %{ $1 = PyCObject_AsVoidPtr($input); %} extern void callMethod(void (*someMethod)()); Here is my error: In ...

Python twisted: how to schedule?

Hi, all! Having 1-day experience in Twisted I try to schedule message sending in reply to tcp client: import os, sys, time from twisted.internet import protocol, reactor self.scenario = [(1, "Message after 1 sec!"), (4, "This after 4 secs"), (2, "End final after 2 secs")] for timeout, data in self.scenario: reactor.callLater(ti...

How to retrieve result of calling a script from within a Python function?

I would like to call an external script from within a function, for instance: import subprocess def call_script(script): subprocess.call(script) return answer #retrieving the result is the part I'm struggling with call_script("/user/bin/calc_delta.py") The script calc_delta.py simply prints the result when it is done. How can ...

Python function based on Scrapy to crawl entirely a web site

hi, I recently discovered Scrapy which i find very efficient. However, I really don't see how to embed it in a larger project written in python. I would like to create a spider in the normal way but be able to launch it on a given url with a function start_crawl(url) which would launch the crawling process on a given domain and stop o...

Running a python script from crontab

I've got a python program which runs via crontab and that works perfectly. However, I decided to add the ability to notify me of what it's doing, and suddenly it's failing. It runs from the command line, however, running it as a crontab program causes it to fail libnotify-Message: Unable to get session bus: /bin/dbus-launch terminated a...

Python parsing: lxml to get just part of a tag's text

I'm working in Python with HTML that looks like this. I'm parsing with lxml, but could equally happily use pyquery: <p><span class="Title">Name</span>Dave Davies</p> <p><span class="Title">Address</span>123 Greyfriars Road, London</p> Pulling out 'Name' and 'Address' is dead easy, whatever library I use, but how do I get the remainder...

What this line doing? Django-template.

Explain me please what this line doing: <a href="{% url video.media.views.channel_browse slug=slug%}">Archie Channel</a> Actually this: {% url video.media.views.channel_browse slug=slug%} I know that it give me URL, but what from, or how it is making this URL? does this url depend from context? if it depend from context so which c...

Celery - Get task id for current task

How can I get the task_id value for a task from within the task? Here's my code: from celery.decorators import task from django.core.cache import cache @task def do_job(path): "Performs an operation on a file" # ... Code to perform the operation ... cache.set(current_task_id, operation_results) The idea is that when I c...

How to access the web with Python?

I want to access websites without using their API. Would i do this by using something like Mechanize? ...

Splicing NumPy arrays

I am having a problem splicing together two arrays. Let's assume I have two arrays: a = array([1,2,3]) b = array([4,5,6]) When I do vstack((a,b)) I get [[1,2,3],[4,5,6]] and if I do hstack((a,b)) I get: [1,2,3,4,5,6] But what I really want is: [[1,4],[2,5],[3,6]] How do I accomplish this without using for loops (it needs to b...

Matplotlib legend help

I am writing a script that plot's several points. I am also trying to create a legend from these points. To sum up my script, I am plotting several 'types' of points (call them 'a', 'b', 'c'). These points have different colors and shapes: 'a'-'go' 'b'-'rh' 'c'-'k^'. This is a shortened version of the relevant parts of my script: lbl =...