python

Regular Expression 'Split' function

Hi, I'm new to this site, and new to Python. So I'm learning about Regular Expressions and I was working through Google's expamples here. I was doing one of the 'Search' examples but I changed the 'Search' to 'Split' and changed the search pattern a bit just to play with it, here's the line print re.split(r'i', 'piiig') (notice th...

Console colors (Windows)

Is it possible to print out things in different colors in Python for Windows? I already enabled ANSI.sys, but this does not seam to work. I want to be able to print one line in red, and the next in green, etc. ...

handling python string or list dynamically

Hi, i have a variable, numberofrow, its value is dynamically set in form field. now since numberofrow is in multiple tables, when i receive that variable from form, if only one numerofrow, its a String, for ex. numberofrow = 01 if more than one numberofrow, its a list, for ex. numberofrow = [01, 02, 04] Now how do i differentiate...

Can deleting a django Model with a ManyToManyField create orphaned database rows?

If I have two classes A and B with a many to many relationship and I want to delete an instance of A, do I need to remove all of its related Bs first or will Django sort that out for me? I obviously don't want to leave orphaned rows in the join table. Does it make any difference if the ManyToMany field is declared on class A or B? Doe...

How to connect to internet & load html using python/urllib in ubuntu?

I am new to programming, i had some problem with the code.. Here i have posted the code below. Actually after running the program its shows some error... ERROR: It shows some traceback error import urllib proxies = {'http' : 'http://proxy:80'} urlopener = urllib.FancyURLopener(proxies) htmlpage = urlopener.open('http://www.google.com'...

Edit Windows 7 Registry in Python?

I have run into another problem with my current project. The program needs to values and keys periodically while running. Each time I attempt to edit the value, I get a code 5, Access Denied. How would I go about doing this so the values can be editied, but the user doesn't have to enter admin credentials to run the application? I am us...

Getting list of all strings from a Django app

Eclipse has a function called Externalise all Strings, which will move all strings to an properties file. Is there such a solution available for Django/Python? Basically I have a large project with number of views/models/templates, and going through all of them, and putting string -> _("string") etc is a big pain, so is there a way to...

Python socket client-server application

I wrote two applictions which comunicate by socket. This is the code: Server: import socket server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.bind(("",9999)) server_socket.listen(5) video = True power = True print "TCPServer Waiting for client on port 9999" while 1: client_socket,address = server_s...

python log manager

Hello I have several python programs that runs in parallel. I want to write a python program which will manage the programs logs, which mean that the other programs will sent log message to this program and the program will write it to the log file. Another important feature is that if one of the programs will crash, the 'manage log prog...

Can an API tell Pylint not to complain in the client code?

I have some code in a reusable class that modifies some types. Here's a simplified version. class Foo: def __init__(self): self.count = 0 def increment(self): self.count += 1 # Add another method outside of the class definition. # Pylint doesn't care about this, and rates this file 10/10. Foo.__dict__["current...

Passing subclasses to imported library

I have library which returns collections of some semi-abstract objects. class Item1(object): pass class Item2(object): pass class Collection1(object): pass class Provider(object): def retrieve_collection(self): col = Collection1() col.add(Item1()) col.add(Item2()) return col It just po...

Python: Slice a 2d array into tiles

Hi I have a raw data file which I read into a byte buffer (a python string). Each data value represents an 8bit pixel of a 2d array representing an image. I know the width and height of this image. I would like to split the image into tiles so that each tiles area must be larger than a 'min tile area' (eg 1024 bytes) and smaller than '...

django grappelli, filebrowser and Tiny MCE insert image dialog

So, I found django admin interface called 'grappelli'. Looked at the screenshots and decided that I like it. Went to sources page and checked out trunk. Set it up and noticed that it looks nothing like screenshots. No dashboard, no side panel, different colors of the elements and model item lists are very narrow. From that point I'm won...

Can't scroll to the end of TreeView PyGTK / GTK

When I try to scroll down to the end of my TreeView, which is inside a ScrolledWindow, it doesn't scroll where it should but one or two lines before. I tried several methods and they all provide the same behavior : self.wTree.get_widget("tree_last_log").scroll_to_cell((self.number_results-1,)) # or self.wTree.get_widget("tree_last_log...

Why does python libs (eg imaplib) does not use logging but use sys.stderr.write ?

I'm not sure if it's because sys.stderr.write is faster. ...

What does %d mean in struct.pack?

I reading though a library of python code, and I'm stumped by this statement: struct.pack( "<ii%ds"%len(value), ParameterTypes.String, len(value), value.encode("UTF8") ) I understand everything but%d, and I'm not sure why the length of value is being packed in twice. As I understand it, the structure will have little endian encoding ...

How to remove list of words from a list of strings

Sorry if the question is bit confusing. This is similar to this question I think this the above question is close to what I want, but in Clojure. There is another question I need something like this but instead of '[br]' in that question, there is a list of strings that need to be searched and removed. Hope I made myself clear. I...

AttributeError: 'module' object has no attribute 'QtString'

Hi My development eviroment: os: windows xp python: python-3.1.2.msi pyqt: PyQt-Py3.1-gpl-4.7.4-1.exe code: import sys from PyQt4 import QtCore, QtGui app = QtGui.QApplication(sys.argv) s = QtCore.QtString() sys.exit(app.exec_()) It always show me in 'module' s = QtCore.QtString() Attribu...

want to find all possible values for given number.(in C language)

my output should appear as (ex- input is 4) [(1,1,1,1),(1,2,1),(2,2),(1,3),4] ...

Factory pattern in Python

Hi, I'm currently implementing the Factory design pattern in Python and I have a few questions. Is there any way to prevent the direct instantiation of the actual concrete classes? For example, if I have a VehicleFactory that spawns Vehicles, I want users to just use that factory, and prevent anyone from accidentally instantiating Car...