python

How do I inspect the scope of a function where Python raises an exception?

I've recently discovered the very useful '-i' flag to Python -i : inspect interactively after running script, (also PYTHONINSPECT=x) and force prompts, even if stdin does not appear to be a terminal this is great for inspecting objects in the global scope, but what happens if the exception was raised in a function call, ...

Alternative to innerhtml that includes header?

I'm trying to extract data from the following page: http://www.bmreports.com/servlet/com.logica.neta.bwp_PanBMDataServlet?param1=&param2=&param3=&param4=&param5=2009-04-22&param6=37# Which, conveniently and inefficiently enough, includes all the data embedded as a csv file in the header, set as a variable called gs_...

exec statement with/without prior compile

These weekend I've been tearing down to pieces Michele Simionato's decorator module, that builds signature-preserving decorators. At the heart of it all there is a dynamically generated function, which works something similar to this... src = """def function(a,b,c) :\n return _caller_(a,b,c)\n""" evaldict = {'_caller_' : _caller_} co...

A neat way of extending a class attribute in subclasses

Let's say I have the following class class Parent(object): Options = { 'option1': 'value1', 'option2': 'value2' } And a subclass called Child class Child(Parent): Options = Parent.Options.copy() Options.update({ 'option2': 'value2', 'option3': 'value3' }) I want to be able to overrid...

European date input in Django Admin

Django has a DATE_FORMAT and a DATE_TIME_FORMAT options that allow us to choose which format to use when viewing dates, but doesn't apparently let me change the input format for the date when editing or adding in the Django Admin. The default for the admin is: YYYY-MM-DD But would be awesome to use: DD-MM-YYYY Is this integrated in an...

Making a Python script executable chmod755?

My hosting provider says my python script must be made to be executable(chmod755). What does this mean & how do I do it? Cheers! ...

Gather all Python modules used into one folder?

I don't think this has been asked before-I have a folder that has lots of different .py files. The script I've made only uses some-but some call others & I don't know all the ones being used. Is there a program that will get everything needed to make that script run into one folder? Cheers! ...

How to let Django's generic view use a form with initial values?

I know how to set initial values to a form from the view. But how do I go about letting a generic view set initial values to a form? I can write a wrapper view for the generic view, but I still have no access to the form object instantiation. The specific goal I'm trying to achieve is to have a user create a new object, using the create...

Gather all Python modules used into one folder?

Possible Duplicate: Gather all Python modules used into one folder? I don't think this has been asked before-I have a folder that has lots of different .py files. The script I've made only uses some-but some call others & I don't know all the ones being used. Is there a program that will get everything needed to make that scri...

Generating file to download with Django

Is it possible to make a zip archive and offer it to download, but still not save a file to the hard drive? ...

Secure plugin system for python application

Hi, I have an application written in python. I created a plugin system for the application that uses egg files. Egg files contain compiled python files and can be easily decompiled and used to hack the application. Is there a way to secure this system? I'd like to use digital signature for this - sign these egg files and check the signat...

How to write binary data in stdout in python 3?

In python 2.x I could do this: import sys, array a = array.array('B', range(100)) a.tofile(sys.stdout) Now however, I get a TypeError: can't write bytes to text stream. Is there some secret encoding that I should use? ...

Python Getting date online?

How can I get the current date, month & year online using Python? Thanks! EDIT-By this I mean, rather than getting it from the computer's date-visit a website & get it, so it doesn't rely on the computer. ...

Regex Subtitution in Python

I have a CSV file with several entries, and each entry has 2 unix timestamp formatted dates. I have a method called convert(), which takes in the timestamp and converts it to YYYYMMDD. Now, since I have 2 timestamps in each line, how would I replace each one with the new value? EDIT: Just to clarify, I would like to convert each occur...

How can I mine an XML document with awk, Perl, or Python?

I have a XML file with the following data format: <net NetName="abc" attr1="123" attr2="234" attr3="345".../> <net NetName="cde" attr1="456" attr2="567" attr3="678".../> .... Can anyone tell me how could I data mine the XML file using an awk one-liner? For example, I would like to know attr3 of abc. It will return 345 to me. ...

Why is the compiler package discontinued in Python 3?

I was just pleasantly surprised to came across the documentation of Python's compiler package, but noticed that it's gone in Python 3.0, without any clear replacement or explanation. I can't seem to find any discussion on python-dev about how this decision was made - does anyone have any insight inot this decision? ...

Python code that needs some overview

Hi guys, im currently learning python (in the very begining), so I still have some doubts about good code manners and how should I proceed with it. Today I created this code that should random trought 01 to 60 (but is running from 01 to 69) import random dez = ['0', '1', '2', '3', '4', '5', '6'] uni = ['0', '1', '2', '3', '4', '5', '6...

Programmatically fetching contacts from Yahoo! Address Book

Is there a way to programmatically log into Yahoo!, providing email id and password as inputs, and fetch the user's contacts? I've achieved the same thing with Gmail, thanks to the its ClientLogin interface. Yahoo Address book API provides BBAuth, which requires the user to be redirected to Yahoo login page. But I'm looking for a way...

Factory for Callback methods - Python TKinter

Writing a test app to emulate PIO lines, I have a very simple Python/Tk GUI app. Using the numeric Keys 1 to 8 to simulate PIO pins 1 to 8. Press the key down = PIO High, release the Key = PIO goes low. What I need it for is not the problem. I kind of went down a rabbit hole trying to use a factory to create the key press call back funct...

on my local Windows machine, how do i write a script to download a comic strip every day and email it to myself?

on my local Windows machine, how do i write a script to download a comic strip every day and email it to myself? such as http://comics.com/peanuts/ Update: i know how to download the image as a file. the hard part is how to email it from my local Windows machine. ...