python

Printing python modulus operator as it is over command line

I want to print modulus operator as it is over the command line: E.g this is how the output should look like: 1%2 2%4 or 30% 40% I am using the print statement like this: print 'computing %s % %s' % (num1, num2) Its throwing the default error: TypeError: not all arguments converted during string formatting For now I am ...

Calculate score in a pyramid score system

I am trying to calculate gamescores for a bunch over users and I haven't really got it yet. It is a pyramid game where you can invite people, and the people you invite is placed beneth you in the relations tree. So if i invite X and X invites Y i get kickback from both of them. Let's say 10%^steps... So from X i get 10% of his score an...

Is generator.next() visible in python 3.0?

I have a generator that generates a series, for example: def triangleNums(): '''generate series of triangle numbers''' tn = 0 counter = 1 while(True): tn = tn + counter yield tn counter = counter + 1 in python 2.6 I am able to make the following calls: g = triangleNums() # get the generator g.n...

PyQt clipboard doesn't copy to system clipboard

The following snippet of code doesn't seem to affect the system clipboard at all: clipboard = QtGui.QApplication.clipboard() clipboard.setText(text) According to the Qt documentation, this is how you copy text to clipboard, Why isn't it working? Googling turned this up. It suggests adding this after the above code: event = QtCore...

Why does SCons VariantDir() not put output in the given directory?

I'm thinking about using SCons for a new project. It looks really good, though I'm finding VariantDir quite confusing. I have a simple project with a handful of C source files in one directory, and I want to build in "normal" and in "profile" mode -- with two different sets of options to gcc. I want the outputs to go in the normal/ and ...

Pyinstaller traceback

Traceback (most recent call last): File "<string>", line 137, in <module> File C:\Python26\buildSVG_Resizer\out1.pyz/encodings", line 100, in search_function TypeError: importHook() got an unexpected keyword argument 'level' The imports in my .py file are: import xml.etree.ElementTree as ET import os, stat import tkFileDialog My sc...

Serve a dynamically generated image with Django

How do I serve a dynamically generated image in Django? I have an html tag <html> ... <img src="images/dynamic_chart.png" /> ... </html> linked up to this request handler, which creates an in-memory image def chart(request): img = Image.new("RGB", (300,300), "#FFFFFF") data = [(i,randint(100,200)) for i in range(0,300,1...

restore registry from file

I am trying to migrate microsoft office settings from one system to other system by backing up office registry and restoring it on the destination machine using Python.I am able to do the saving part,but on trying to restore the existing settings in destination machine to overwrite existing office settings,i am getting an error. This is ...

Generating an image thumbnail that is <10KB and did not lose proportions

Notice how for every image that google indexes it has a small thumbnail. These thumbnails are: Less than 10KB in size. The proportions of the width / height are the same as the ones in the original image. I would like to write a function (in python) that would take an image and create a thumbnail with these to properties. EDIT: So ...

How do I find the memory address of a Python / Django model object?

An ordinary object, I can use o.__repr__() to see something like '<__main__.A object at 0x9d78fec>' But, say, a Django User just returns <User:bob> How can I see the actual address of one of these, or compare whether two such model-objects are actually the same object or not? ...

How to debug SCons scripts using eclipse and pydev?

I'm a newbie to SCons and also using pydev. Can someone help me with instructions on how to debug scons scripts using Eclipse and pydev? Is it even possible considering the fact that SCons is a seperate app and not an extension to python? ...

CherryPy interferes with Twisted shutting down on Windows

I've got an application that runs Twisted by starting the reactor with reactor.run() in my main thread after starting some other threads, including the CherryPy web server. Here's a program that shuts down cleanly when Ctrl+C is pressed on Linux but not on Windows: from threading import Thread from signal import signal, SIGINT import ...

Does python have hooks into EXT3

We have several cron jobs that ftp proxy logs to a centralized server. These files can be rather large and take some time to transfer. Part of the requirement of this project is to provide a logging mechanism in which we log the success or failure of these transfers. This is simple enough. My question is, is there a way to check if a fi...

multiprocessing - share objects with file handle attribute between processes

hi ,i am a newbie here ! there is a question about shared resouce with file handle between processes. here are my test code: from multiprocessing import Process,Lock,freeze_support,Queue import tempfile #from cStringIO import StringIO class File(): def __init__(self): self.temp = tempfile.TemporaryFile() #print ...

Simplifying Data with a for loop (Python)

Hi, I was trying to simplify the code: header = [] header.append(header1) header.append(header2) header.append(header3) header.append(header4) header.append(header5) header.append(header6) where: header1 = str(input.head...

Using the AND and NOT Operator in Python

Here is my custom class that I have that represents a triangle. I'm trying to write code that checks to see if self.a, self.b, and self.c are greater than 0, which would mean that I have Angle, Angle, Angle. Below you will see the code that checks for A and B, however when I use just self.a != 0 then it works fine. I believe I'm not...

Working with foreign symbols in python

I'm parsing a JSON feed in Python and it contains this character, causing it not to validate. Is there a way to handle these symbols? Can they be converted or is they're a tidy way to remove them? I don't even know what this symbol is called or what causes them, otherwise I would research it myself. EDIT: Stackover Flow is strippin...

I want to parse a PAC file to get some Proxy information... just not in Explorer

Follow on from this question: I am working on a Python 2.4 app which will run on Windows XP. It needs to be able to download various resources from HTTP and it's got to work in all of our office locations which use "PAC" files to automatically select http proxies. Thanks to somebody who responded to my previous question I managed to fi...

.class file from jython with pydev

My first attempt at jython is a java/jython project I'm writing in eclipse with pydev. I created a java project and then made it a pydev project by the RightClick project >> pydev >> set as... you get the idea. I then added two source folders, one for java and one for jython, and each source folder has a package. And I set each folder a...

Extending Python with C/C++

Can anyone please give me tips on the tools or sofware to use to extend Python with C/C++? Thanks. ...