python

Static properties in Python

I am relatively new to Python and was hoping someone could explain the following to me: class MyClass: Property1 = 1 Property2 = 2 print MyClass.Property1 # 1 mc = MyClass() print mc.Property1 # 1 Why can I access Property1 both statically and through a MyClass instance? ...

Python Webbrowser question

I'm opening a webpage in the default webbrowser on the system using python's webbrowser module. I want to check if the site is already open in the browser and only open a new tab/window if it is not. Otherwise reload the already opened page. Is there a way to do this with webbrowser module? If not, is there any other module i can use t...

how to set the python framework path before building cxfreeze for python3

I m building a python script using a setup.py file. In building process, it links to python framework. I want to change the linking framework path as its linking to the wrong location. How to set the framework path before building the script. Thanks in advance for sparring ur valuable time for this thread. ...

Python: Load module by its name

I'm working on a django project that serves multiple sites; depending on the site I want to import different functionality from a different module; how do I import a module in Python if I have the name of its package and the module name itself as a string? ...

how to parse a string to spider from another script

Hi all!!! I am new to python and scrapy . I am running the scrapy-ctl.py from another python script using subprocess module.But I want to parse the 'start url' to the spider from this script itself.Is it possible to parse start_urls(which are determined in the script from which scrapy-ctl is run) to the spider? I will be greatful f...

Does it make sense to check for identity in __eq__?

When implementing a custom equality function for a class, does it make sense to check for identity first? An example: def __eq__(self, other): return (self is other) or (other criteria) This interesting is for cases when the other criteria may be more expensive (e.g. comparing some long strings). ...

Problem unpacking list of lists in a for loop?

I have a list of lists that I want to unpack in for loops, but I'm running into an issue. >>> a_list = [(date(2010, 7, 5), ['item 1', 'item 2']), (date(2010, 7, 6), ['item 1'])] >>> >>> for set in a_list: ... a, b = set ... print a, b ... 2010-07-05 ['item 1', 'item 2'] 2010-07-06 ['item 1'] >>> >>> for set in a_list: ... fo...

gae-sessions returning None when deployed on App Engine

I'm using gae-sessions in my App Engine program, and I have the following function: def get_token(): session = get_current_session() access_token = session.get('access_token', None) The code that sets the session up is simple enough: session = get_current_session() session['access_token'] = token I've put error trapping in ...

Using python function callbacks with PyObjC?

I'm trying to use an Objective-C class made in Python to do this but Objective-C can't call the method which calls the python function. Here's the framework code which the Objective-C code: // // scalelib.h // Scalelib Cocoa Framework // // Created by Matthew Mitchell on 04/07/2010. // Copyright 2010 __MyCompanyName__. All rights r...

Python, ConfigParser: What is 'magical interpolation'

The documentation for ConfigParser in Python talks a lot about the so-called "magical interpolation" feature, but never explains what it actually does. I've tried searching for it, but haven't found any answers. ...

Calling custom Objective-C from a pyobjc application?

This question is basically the inverse of this other question: http://stackoverflow.com/questions/1308079/calling-python-from-objective-c I have implemented my iPhone application logic in Objective-C (obviously), and am now trying to re-use as much as possible from my XCode project in the server component to save on double-implementatio...

Processing High-Volume Streaming Data with Twisted or using Threads, Queue in Python

Hi Everyone, I am getting at extremely fast rate, tweets from a long-lived connection to the Twitter API Streaming Server. I proceed by doing some heavy text processing and save the tweets in my database. I am using PyCurl for the connection and callback function that care of text processing and saving in the db. See below my approach ...

HTML Tag Cloud in Python

I am looking for a simple library which can be given a set of items:value pair and which can generate a tag cloud as output. Library can preferably be in python ...

imap deleting messages

How can I delete messages from the mail box? I am using this code, but the letters are not removed. Sorry for my English. def getimap(self,server,port,login,password): import imaplib, email box = imaplib.IMAP4(server,port) box.login(login,password) box.select() box.expunge() typ, data = box.search(None, 'ALL') ...

Creating a multi-page TIFF with Python

This has already been asked here, but I was looking for a solution that would work on Linux.. Is tiffcp the only way? ...

Linking GSL (or other library) statically into a shared library

Hello, Note: Despite the mentioning of Python in the following there is a good chance for my problem not to be Python related at all. If I am not mistaken the “module” I mention is equivalent to a C library—at least for the concerns of my problem. On Debian I am trying to create a Python module with C, which in turn uses the GSL. The f...

Can a PyQt program consume a DBus interface that exposes custom C++ types (marhsalled via Qt's MetaType system)? If so, how?

I have a Qt/C++ application that exposes some custom C++ classes via DBus methods (by registering them as MetaTypes, and using annotations in the xml), and I want my PyQt program to consume these methods. The problem I see is that the exposed types are C++ classes, not python, so how can I make python aware of these classes? ...

Microsoft Powerpoint Python Parser

I am looking for a python based microsoft office parser - specifically powerpoint. I want to be able to parse PPT in python and extract things like text and images from the powerpoint file. Is there a library available? ...

Parsing arbitrary number of arguments in Python OptParser

How can I define an option with an arbitrary number of arguments in Python's OptParser? I'd like something like: python my_program.py --my-option X,Y # one argument passed, "X,Y" python my_prgoram.py --my-option X,Y Z,W # two arguments passed, "X,Y" and "Z,W" the nargs= option of OptParser limits me to a defined number. How can ...

reading file data mixing strings and numbers in python

I would like to read different files in one directory with the following structure: # Mj = 1.60 ff = 7580.6 gg = 0.8325 I would like to read the numbers from each file and associate every one to a vector. If we assume I have 3 files, I will have 3 components for vector Mj, ... How can I do it in Python? Thanks for y...