python

How to make python urllib2 follow redirect and keep post method

I am using urllib2 to post data to a form. The problem is that the form replies with a 302 redirect. According to Python HTTPRedirectHandler the redirect handler will take the request and convert it from POST to GET and follow the 301 or 302. I would like to preserve the POST method and the data passed to the opener. I made an unsuccessf...

How to get webcam info with WMI

Which class that we can obtain webcam info? Thank ...

How to get user input during a while loop without blocking

I'm trying to write a while loop that constantly updates the screen by using os.system("clear") and then printing out a different text message every few seconds. How do I get user input during the loop? raw_input() just pauses and waits, which is not the functionality I want. import os import time string = "the fox jumped over the lazy...

storing classmethod reference in tuple does not work as in variable

#!/usr/bin/python class Bar(object): @staticmethod def ruleOn(rule): if isinstance(rule, tuple): print rule[0] print rule[0].__get__(None, Foo) else: print rule class Foo(object): @classmethod def callRule(cls): Bar.ruleOn(cls.RULE1) Bar.ruleOn(cls.RULE2) @classmethod def check(cls): ...

fuzzy timestamp parsing with Python

hello, Is there a Python module to interpret fuzzy timestamps like the date command in unix: > date -d "2 minutes ago" Tue Aug 11 16:24:05 EST 2009 The closest I have found so far is dateutil.parser, which fails for the above example. thanks ...

Python Subprocess - Redirect stdout/err to two places

Hi, I have a small python script which invokes an external process using subprocess. I want to redirect stdout and stderr to both a log file and to the terminal. How can this be done? Thanks, Udi ...

Python: How can I choose which module to import when they are named the same

Lets say I'm in a file called openid.py and I do : from openid.consumer.discover import discover, DiscoveryFailure I have the openid module on my pythonpath but the interpreter seems to be trying to use my openid.py file. How can I get the library version? (Of course, something other than the obvious 'rename your file' answer would b...

django Datefield to Unix timestamp

Hello In a model I have a such field: mydate = models.DateField() now a javascript graph function requires unix timestamp such as "1196550000000", how can I return the unix timestamp of my mydate input. Thanks ...

How to find the installation path of IronPython

Hi, I have few python scripts of which one is to be executed in IronPython interpreter. How to find the installation path of IronPython. I searched the registry. To my surprise, it was not there. ...

Is it a good idea to use super() in Python?

Or should I just explicitly reference the superclasses whose methods I want to call? It seems brittle to repeat the names of super classes when referencing their constructors, but this page http://fuhm.net/super-harmful/ makes some good arguments against using super(). ...

icalender reader for python

I'm looking to automate the status reports that I have to send to my manager. Since I use a todo software that writes to icalendar format, I would like be able to format an email out of the ics file. I'm starting my work with : http://codespeak.net/icalendar/ which looks pretty good, but it does have some rough edges. What icalender re...

How can I use Emacs Flymake mode for python with pyflakes and pylint checking code?

For checking code in python mode I use flymake with pyflakes Also I want check code style (pep8) with pylint (description on the same page with pyflakes) This solutions work. But I can't configure flymake for work with pyflakes and pylint together. How can I do it? ...

Python : Assert that variable is instance method?

How can one check if a variable is an instance method or not? I'm using python 2.5. Something like this: class Test: def method(self): pass assert is_instance_method(Test().method) ...

OS locale support for use in Python

The following Python code works on my Windows machine (Python 2.5.4), but doesn't on my Debian machine (Python 2.5.0). I'm guessing it's OS dependent. import locale locale.setlocale( locale.LC_ALL, 'English_United States.1252' ) I receive the following error: Traceback (most recent call last): File "<stdin>", line 1, in <module> ...

How to comply to PEP 257 docstrings when using Python's optparse module?

According to PEP 257 the docstring of command line script should be its usage message. The docstring of a script (a stand-alone program) should be usable as its "usage" message, printed when the script is invoked with incorrect or missing arguments (or perhaps with a "-h" option, for "help"). Such a docstring should docum...

Start with pyglet or pygame?

Hey, I would like to know what is the best to start with, pyglet or pygame? Which one is faster and which one is more active? I would also like to know if pyglet will get python 3 support, because I have read here that it might not be possible or it would take a long time. Would it be better to choose pygame, because of the python 3 ...

Interrupt Python program deadlocked in a DLL

How can I ensure a python program can be interrupted via Ctrl-C, or a similar mechanism, when it is deadlocked in code within a DLL? ...

Locking a custom dictionary

Good day pythonians, I want to make a custom dictionary with two main features: All keys are declared on creation It is impossible to add new keys or modify current ones (values are still modifiable) Right now code is this: class pick(dict): """This will make delicious toffee when finished""" def __init__(self, *args): ...

Python: import a file from a subdirectory

Hi, I have a file called tester.py, located on /project. /project has a subdirectory called lib, with has a file called BoxTime.py: /project/tester.py /project/lib/BoxTime.py I want to import BoxTime from tester. I have tried this: import lib.BoxTime Which resulted: Traceback (most recent call last): File "./tester.py", line 3...

Which credentials should I put in for Google App Engine BulkLoader at development server?

Hello everyone, I would like to ask which kind of credentials do I need to put on for importing data using the Google App Engine BulkLoader class appcfg.py upload_data --config_file=models.py --filename=listcountries.csv --kind=CMSCountry --url=http://localhost:8178/remote_api vit/ And then it asks me for credentials: Please enter...