python

Can git automatically switch between spaces and tabs?

I use tabs for indentation in my python programs, but I would like to collaborate (using git) with people who use spaces instead. Is there a way for git to automatically convert between spaces and tabs (say, 4 spaces = 1 tab) on pushing/fetching? (similar to the CR/LF conversion) ...

Pipe output of a command to an interactive python session?

What I'd like to do is something like $echo $PATH | python --remain-interactive "x = raw_input().split(':')" >>> >>> print x ['/usr/local/bin', '/usr/bin', '/bin'] I suppose ipython solution would be best. If this isn't achievable, what would be your solution for the situation where I want to process output from various other comm...

Is there a way to extract a dict in Python into the local namespace?

PHP has a function called extract() which takes an associative array as the argument and creates local variables out of the keys whose values are assigned to the key's values. Is there a way to do this in Python? A quick google search didn't immediately show me how. I suspect there's a way with exec() but it'd be nice if there were some ...

Is it just me...or is "Facebook Mobile Web" only for PHP?

http://wiki.developers.facebook.com/index.php/Mobile I use Django/Python as my mobile website. Am I missing something? ...

Coverting a string to a formatted date-time string using Python

I'm trying to convert a string "20091229050936" into "05:09 29 December 2009 (UTC)" >>>import time >>>s = time.strptime("20091229050936", "%Y%m%d%H%M%S") >>>print s.strftime('%H:%M %d %B %Y (UTC)') gives AttributeError: 'time.struct_time' object has no attribute 'strftime' clearly, I've made a mistake: time is wrong, it's a datetime ...

Python+parsing custom config file

I have a quite big custom made config file I need to extract data from once a week. This is an "in house" config file which doesn't comply to any know standard like INI or such. My quick and dirty approach was to use re to search for the section header I want and then extract the one or 2 lines of information under this header that I wa...

SQLAlchemy - maximum column length

Hi, is it possible in SQLAlchemy to enforce maximum string length of value assigned to mapped column? All I want is to raise an exception if an assigned string value is longer then the length of the corresponding table column of type STRING. Thank you ...

Regular expression

Hi all, I am a newbie in Python. I want to write a regular expression for some name checking. My input string can contain a-z, A-Z, 0-9, and ' _ ', but it should start with either a-z or A-Z (not 0-9 and ' _ '). I want to write a regular expression for this. I tried, but nothing was matching perfectly. Once the input string follows th...

setting windows live messenger nick and status message using win32com.client

is their any way to set windows live messenger using the win32com library ? ...

Django group / aggregation

Hi. I have following structure with example data: id season_id title 1 1 Intro 2 1 Second part 3 1 Third part 4 4 Other intro 5 4 Other second part (don't ask why), where season_id is always point to id of first episode of season... What i want, to get follo...

PIP: Installing only the dependencies

I have a script that creates a virtualenv, installs distribute and pip in it and then optionally clones a git repo. Now I have the project I will be working on, installed. But its dependencies are not installed. How can I make pip install all the dependencies as if I have issued a pip install MyApp? EDIT: Appareantly my question is a d...

Django count RawQuerySet

Hay, I'm using django 1.2 and i want to know how to count rows from a raw queryset(RawQuerySet). The traditional .count() method doesn't work. Heres my query query = "SELECT *, ((ACOS(SIN(%s * PI() / 180) * SIN(lat * PI() / 180) + COS(%s * PI() / 180) * COS(lat * PI() / 180) * COS((%s - lon) * PI() / 180)) * 180 / PI()) * 60 * 1.1515)...

Asynchronous COMET query with Tornado and Prototype

Hello everyone. I'm trying to write simple web application using Tornado and JS Prototype library. So, the client can execute long running job on server. I wish, that this job runs Asynchronously - so that others clients could view page and do some stuff there. Here what i've got: #!/usr/bin/env/ pytthon import tornado.httpserver impo...

xml file using python

i have made a xml file using python. how can i retrieve an element from it? will u help me with the code? Also i need to have my output(i.e. element of each attribute come in seperate lines in that particular xml file) ...

clicking "cancel" in tkColorChooser dialog leads to Error

I use python 2.6 under linux (SUSE Linux Enterprise Desktop 11 (x86_64)). I tested some very simple code : import tkColorChooser tkColorChooser.askcolor() then if I click on cancel, I always get error like: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python2.6/lib-tk/tkColorChooser.py",...

Error using MSSet (MySQL SET extension) in SQLAlchemy

Hi, I'm trying to use MSSet datatype in SQL Alchemy I'm usinge declarative extension, here is the class: class SMSEmailOption(Base): __tablename__ = 'sms_email_options' id = Column(Integer, primary_key=True) sms_active = Column(Integer) email_active = Column(Integer) delivery_time = Column(Date) days = Column(...

JSON serializers not working in Django

Hay, serializers is not returning JSON object make = Make.objects.filter(slug__exact=make) models = Model.objects.filter(make=make).values('slug','name') json_models = serializers.get_serializer("json")() json_models.serialize(models) return HttpResponse(json_models.getvalue()) I'm getting an error 'dict' object...

How can I use a SOCKS 4/5 proxy with urllib2 ?

How can I use a SOCKS 4/5 proxy with urllib2 to download a web page? ...

print_r functionality in iPython

Is there a way to get PHP-like 'print_r(object)' funcionality in iPython? I know I can use '?' to get info about an object, but how do I view the values of the object? ...

Python equivalent for Ruby's ObjectSpace?

Hello guys, I've a name of a class stored in var, which I need to create an object from. However I do not know in which module it is defined (if I did, I would just call getattr(module,var), but I do know it's imported. Should I go over every module and test if the class is defined there ? How do I do it in python ? What if I have the ...