python

standalone application in python

Hi, I wanted to know how can I make standalone application in python. Basically what I am doing right now is I have a template.tex file and my script generate the pdf by giving some input values. So I have to make exe file for windows and same for linux. I can use cx_freeze for creating exe file. But my problem is most of people do not c...

Technique to limit number of instances of our application under Terminal Server

I'm looking for simple ways to monitor and limit the number of instances of our application under Terminal Server (2003 and 2008). The purpose of this restriction is to make sure we don't overload our servers. This is an internal administrative requirement - I am not looking for a licensing solution. The application in question is writ...

how to get data from csv file in python

I am using csv.reader to read file but it giving me whole file. file_data = self.request.get('file_in'); file_Reader = csv.reader( file_data ); for fields in file_Reader: I want one line at a time and separate data from that line. ex: filedata = name,sal,dept x,12000,it o\p= name sal dept . . . ...

seleniumRC: Problems with browser starting on OS X

Hi! I am trying to start simple selenium test on OSX (just downloaded the latest version of RC), with a python client driver. But the browser can't start (it crashes). The error which I see in console is 15:33:32.867 INFO - Preparing Firefox profile... dyld: Library not loaded: /System/Library/Frameworks/ApplicationServices.frame...

Python: How expensive is to create a small list many times?

I encounter the following small annoying dilemma over and over again in Python: Option 1: cleaner but slower(?) if called many times since a_list get re-created for each call of do_something() def do_something(): a_list = ["any", "think", "whatever"] # read something from a_list Option 2: Uglier but more efficient (spar...

How do I do this regex in Python?

Suppose I have a string of text, of all characters Latin-based. With punctuation. How do I "find" all the characters and put <strong> tags around it? hay = The fox jumped up the tree. needle = "umpe" In this case, part of the word "jumped" would be highlighted. ...

Python methods on an object - which is better?

Hopefully an easy question. If I have an object and I want to call a method on it which is the better approach, A or B? class foo(object): def bar(): print 'bar' # approach A f = foo() f.bar() # approach B foo().bar() ...

How can I produce student-style graphs using matplotlib?

I am experimenting with matplotlib at the moment. Some time ago I used Excel VBA code to produce images such as the one attached. You will notice it is not presented in a scientific/research style but rather as if produced by a school-student on graph paper - with three different grid-line styles. Is there a fairly straightforward way ...

Should we use Pylons or PHP for our webapp?

My friend and I are planning on building a sort of a forum type of webapp. We've used the major PHP frameworks but we're really thinking about using Python specifically the Pylons framework for our app. Although we're competent PHP programmers, we're somewhat noobs at Python (We could create practical scripts and such). But the thing is ...

Where to put the separation between a stateful object and a stateless calculation in Python?

Which of the following code snippets is the most "pythonic"? The calculation is trivial in this example but could be assumed to be complex in real life. class A(object): """Freely mix state and calcs - no good I presume""" def __init__(self, state): self.state = state def calc_with_state(self, x): return (se...

Adding up time durations in Python

I would like to add up a series of splits in Python. The times begin as strings like "00:08:30.291". I can't seem to find the right way to use the Python objects or API to make this convenient/elegant. It seems that the time object doesn't use microseconds, so I'm using datetime's strptime to parse the strings, successfully. But then dat...

Google OAuth and local dev

Hi guys, i am trying to use Google OAuth to import a user 's contacts. In order to get a consumer and secret key for you app you have to verify your domain at https://www.google.com/accounts/ManageDomains Google allows you to use only domains without ports. I want to test and build the app locally so usually (Facebook, Linkedin apps) i u...

How to only pay the dependency penalty for the implementation you use in Python?

I have a fairly simple set of functionality for which I have multiple implementations, e.g., a datastore that could be backed by Redis, MongoDB, or PostgreSQL. How should I structure/write my code so that code that wants to use one of these implementations only needs the dependencies for that implementation, e.g., they don't need to have...

Python - file contents to nested list

Hi All, I have a file in tab delimited format with trailing newline characters, e.g., 123 abc 456 def 789 ghi I wish to write function to convert the contents of the file into a nested list. To date I have tried: def ls_platform_ann(): keyword = [] for line in open( "file", "r" ).readlines(): for value in line....

Using Vaadin (Java) UI Framework inside Python

What would be the best way to use Vaadin within Python/Django applications? I will be more than satisfied with having access to components/widgets, if the whole UI framework cannot be exposed to me directly. I am aware of Jython, but I am still not sure if it's the way to go about Vaadin in a Python web application. Any positive input/s...

Get Time Machine path?

I need to parse the TimeMachine.plist file to get the current backup path, but I have no clue how to parse the data correctly. I get that there's a data field, which is supposed to be encoded as base64 somewhere inside that plist, but I just can't find what I need inside it... Can anyone point out whatever it is I'm missing, and what to...

GAE db.Model getting property instead of a string value

I have a db.Model which has a string property on it, email_type. Now I've the values for type defined in a readonly class. When I save this to the datastore I get the string instead of "Register", it also raises a BadValueError. How do I get it to save as a string, not as a property. Here's the (slimmed down) code: class EmailTypes(ob...

pymssql connect function

i have this function pymssql.connect(host="my host",user="my user",password="my pass",database="mydb") I want to read the user and password from the user and put them there is that possible or named arguments lvalue should not be variable and if yes then how could i do that ? i.e is it possible to call this function like: pymssql,conn...

Python Socket Getting Connection Reset

I created a threaded socket listener that stores newly accepted connections in a queue. The socket threads then read from the queue and respond. For some reason, when doing benchmarking with 'ab' (apache benchmark) using a concurrency of 2 or more, I always get a connection reset before it's able to complete the benchmark (this is taking...

How to get an item from a set of Queues?

Hello. Say there are two empty Queues. Is there a way to get an item from the queue that gets it first? So I have a queue of high anonymous proxies, queues of anonymous and transparent ones. Some threads may need only high anon. proxies, while others may accept both high anon. and just anon. proxies. That's why I can't put them all to a...