python

[python] Tkinter buttons help

I have a class with a button, it runs the command automatically when the gui is constructed (which i dont want it to do) but then doesnt work again after. What am I doing wrong? Builtin commands such as endcommand work as they should. relevant excerpts (ignore the indent problem at the very beginning) class GuiPart(object): def __i...

Ignore optparse if value is given

I would like to have the ability to pass an argument w/o having to specify an option for optparse. If I do pass an option, it has to be a known option or else the script will fail. Rsync the following file to destination myscript.py filename Rsync the following folder to destination (all this is figured out in function I create). m...

Easy to navigate online Python reference manual?

I'm looking for some reference pages for Python similar to PHP.net's documentation. i.e., something that provides a clear, simple list of all the classes and methods within a module that I can click to get more information, such as the arguments. Having descriptions below each class/method makes it harder to find what you're looking for....

What is the best way to serve small static images?

Right now I'm base 64 encoding them and using data uris. The idea was that this will somehow lower the number of requests the browser needs to make. Does this bucket hold any water? What is the best way of serving images in general? DB, from FS, S3? I am most interested in python and java based answers, but all are welcome! ...

In stackless python, is data sent over a channel immutable?

I have a typical producer, consumer pattern. If the producer sends an object over a channel, the producer is blocked until the consumer accepts the object. After the consumer accepts the object, the producer alters the object in some way. Does the consumer see the object get altered? Or was there an implicit copy when sending the data ov...

How do I convert a datetime to a UTC timestamp in python

from http://docs.python.org/library/time.html time.mktime(t): This is the inverse function of localtime(). Its argument is the struct_time or full 9-tuple (since the dst flag is needed; use -1 as the dst flag if it is unknown) which expresses the time in local time, not UTC. It returns a floating point number, for c...

Is there something wrong with this python code, why does it run so slow compared to ruby?

I was interested in comparing ruby speed vs python so I took the simplest recursive calculation, namely print the fibonacci sequance. This is the python code #!/usr/bin/python2.7 def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-1)+fib(n-2) i = 0 while...

Is it possible to use python suds to read a wsdl file from the file system?

From suds documentation, I can create a Client if I have a url for the WSDL. from suds.client import Client url = 'http://localhost:7080/webservices/WebServiceTestBean?wsdl' client = Client(url) I currently have the WSDL file on my file system. Is it possible to use suds to read the WSDL file from my file system instead of hosting ...

quick data processing with python?

I have a file in the following format: [s1,s2,s3,s4,...] SOME_TEXT (per line) For example: [dog,cat,monkey] 1,2,3 [a,b,c,d,e,f] 13,4,6 the brackets are included. let's say I have another field like this, which contains two lines: [banana,cat2,monkey2] 1,2,3 [a2,b2,c2,d,e,f] 13,4,6 I want to take two files of this form and...

Python 2.x: how to automate enforcing unicode instead of string?

How can I automate a test to enforce that a body of Python 2.x code contains no string instances (only unicode instances)? Eg. Can I do it from within the code? Is there a static analysis tool that has this feature? ...

python - how to get the numebr of active threads started by specific class ?

code looks like below: class workers1(Thread): ... def __init__(self): ... Thread.__init__(self) ... def run(self): ... ...do some stuff class workers2(Thread): ... def __init__(self): ... Thread.__init__(self) ... def run(self): ... ...do some stuff if __name__ == "__main__": ... start workers while ...

Date sensitive regression testing using python

Hey, I am helping to set up a regression testing suite for our python web application. Many of our tests are scheduling style tests where the current date is important. For example: create a recurring event that runs every week for a month starting on Feb 1. In order to test this, what I really want to do is override the current date so...

Installing Python-2.7 on Ubuntu 10.4

I can't seem to install zlib properly, I installed Python from source on Ubuntu10.4 '######## edit ##################### bobince and Luper helped. Make sure you install these packages and then recompile Python: sudo aptitude install zlib1g-dev libreadline6-dev libdb4.8-dev libncurses5-dev '################################# After inst...

Doctest and relative imports

I'm having trouble using doctest with relative imports. The simple solution is just to get rid of the relative imports. Are there any others? Say I have a package called example containing 2 files: example/__init__.py """ This package is entirely useless. >>> arnold = Aardvark() >>> arnold.talk() I am an aardvark. """ from .A impor...

Cleaning and stripping of strings/HTML - Python

Hi folks, I have a set of questions, of which I do not have an answer to. 1) Stripping lists of string input: 'item1, item2, \t\t\t item3, \n\n\n \t, item4, , , item5, ' output: ['item1', 'item2', 'item3', 'item4', 'item5'] Anything more efficient than doing the following? [x.strip() for x in l.split(',') if x.strip()] 2) Clea...

Checking if an ISBN number is correct

I'm given some ISBN numbers e.g. 3-528-03851 (not valid) , 3-528-16419-0 (valid). I'm supposed to write a program which tests if the ISBN number is valid. Here' my code: def check(isbn): check_digit = int(isbn[-1]) match = re.search(r'(\d)-(\d{3})-(\d{5})', isbn[:-1]) if match: digits = match.group(1) + match.group...

Why is Loan undefined when type(self) works just fine?

The following code is being used by the admin to save a Loan object import uuid from django.db import models from django.contrib.auth.models import User from apps.partners.models import Agent # Create your models here. class Loan(models.Model): """ This is our local info about the loan from the LOS """ guid = models.CharField(...

How to call a python script with command line args?

I have a script, client.py, that reads command line args straight as a script (not wrapped in a function like main()), like so: opts, args = getopt.getopt(sys.argv[1:], "l:r:a:j:b:f:n:u:") and prints a bunch of stuff. I need to call this script from my code (on Google App Engine, if that matters). It seems that calling import client...

Is there a better way to write this?

Is there a better way to do this? I feel like I am doing something wrong by being too repetitive. O = viz.pick(1, viz.WORLD) BackSetts = ["set_b1b", "set_b2a", "set_b1a", "set_b2b"] LeftSetts = ["set_l1a", "set_l1b", "set_l2a", "set_l1b"] NormSetts = ["set_nr_a", "set_nr_b"] Maps = ["MapA","MapB"] if O.name in BackSetts: for i in...

Pylons: Sharing SQLAlchemy MySQL connection with external library

I am running Pylons using SQLAlchemy to connect to MySQL, so when I want to use a database connection in a controller, I can do this: from myapp.model.meta import Session class SomeController(BaseController): def index(self): conn = Session.connection() rows = conn.execute('SELECT whatever') ... Say my controller ...