python

Optimizing find and replace over large files in Python

I am a complete beginner to Python or any serious programming language for that matter. I finally got a prototype code to work but I think it will be too slow. My goal is to find and replace some Chinese characters across all files (they are csv) in a directory with integers as per a csv file I have. The files are nicely numbered by yea...

Pythonic way to modify python path relative to current directory

I have a project that is structured like this (cut down a lot to give the gist)... State_Editor/ bin/ state_editor/ __init__.py main.py features/ __init__.py # .py files io/ __init__.py # .py files # etc. You get the idea. Now say for examp...

Line-by-line Remote Data Transmission in Python

I've been playing with the subprocess module to iteratively send each line in an input file to a process created by the following command. ssh -t -A $host 'remote_command' The remote_command expects a line in its STDIN, does some processing on the line and iterates the cycle until STDIN closes or reaches EOF. To achieve this, what I'...

Quickly getting the color of some pixels on the screen in Python on Windows 7

I need to get the color of some pixels on the screen or from the active window, and I need to do so quickly. I've tried using win32gui and ctypes/windll, but they're much too slow. Each of these programs gets the color of 100 pixels: import win32gui import time time.clock() for y in range(0, 100, 10): for x in range(0, 100, 10): ...

problem with QSqlTalbeModel . table is not showing

hello, i have a QsqlTableModel that is assigned to a table view . my problem is that it doesn't populate the table inside the table view . it's still empty and it says (Unable to find table shots) - when printing lastError.text() - the function retrieveShotResults..(check code below) is to test if there is a table called shots and yes...

Is this a Dictionary in an older Python version?

I'm new to Python and am reading a book that came out in 2009 and so uses Python 2.5 syntax. It does the following: _fields_ = [ ("cb", DWORD), ("lpReserved", LPTSTR), ... ] To me it looks like a list of tuples, but at the same time it feels like a Map/Dictionary. Was this the older syntax? ...

Qt: No border on buttons making them non-clickable?

I'm trying to set a style to a button so that it has no border, but it seems the lack of border then makes the button non-clickable. Is there a better way of getting no border? button = QtGui.QPushButton(todo, self) button.move(0, i * 32) button.setFixedSize(200,32) button.setCheckable(True) button.setStyleSheet("QPushButton { backgroun...

Differences in the input function in python (newbie question)

Hi, i'm new to python im self learning but i have a question that i'm afraid it would take years to find a solution for in google and it would be very easy for an expert. In a tutorial it says that there is a difference between input and raw_input i discovered that they changed the behavior of these functions in the latest version of py...

Python 2D image generation

Dear experts, What are some of the better libraries for image generation in Python? If I were to implement a GOTCHA (for example's sake), thereby having to manipulate an image on the pixel level, what would my options be? Ideally I would like to save resulting image as a low-resolution jpeg, but this is mere wishing, I'll settle for any...

Using python in android to interface to sql

I know you can use python and other scripting languages in android. But I haven't seen weather or not it was possible to use python as an interface to sqlite in android. Is this possible? This is the first android app where I've needed sqlite, and using the java api's is retarded. If this isn't possible, can someone point me to a good t...

Kindly review the python code to boost its performance

Hello, I'm doing an Information Retrieval task. I built a simple searchengine. The InvertedIndex is a python dictionary object which is serialized (pickled in python terminology) to a file. Size of this file is InvertedIndex is just 6.5MB. So, my Code just unpickles it and searches it for query & ranks the matching documents according ...

Is it possible to use GDB's reverse debugging with Python? How?

I am trying to use GDB's reverse debugging with a Django application. I get it running in GDB, but I can't make it run backwards. I stopped my Django app with Ctrl-Z and then entered reverse-next at the gdb prompt, getting the error message "Target multi-thread does not support this command." Am I doing it wrong? Isn't this possible?...

Python: any way to perform this "hybrid" split() on multi-lingual (e.g. Chinese & English) strings?

I have strings that are multi-lingual consist of both languages that use whitespace as word separator (English, French, etc) and languages that don't (Chinese, Japanese, Korean). Given such a string, I want to separate the English/French/etc part into words using whitespace as separator, and to separate the Chinese/Japanese/Korean part ...

Overriding a parent class's methods.

Something that I see people doing all the time is: class Man(object): def say_hi(self): print('Hello, World.') class ExcitingMan(Man): def say_hi(self): print('Wow!') super(ExcitingMan, self).say_hi() # Calling the parent version once done with custom stuff. Something that I never see peop...

run out of system resource (execute many programs in a shell script)

Hi guys I'm running a shell script on the university's server. In this shell script, I will execute java, c, c++, python and perl programs. Because every program will be executed many many times(I'm a teaching assistant and will test the students' programs with many different inputs). The server always gives me an error: "running out of...

python regex speed

Hi guys, regarding regex (specifically python re), if we ignore the way the expression is written, is the length of the text the only factor for the time required to process the document? Or are there other factors (like how the text is structured) that play important roles too? ...

How to create IPv6 socket at python? Why got the socket.error: (22, 'Invalid argument') ?

I want to ceate Ipv6 socket at python, I do it like this: #!/usr/bin/env python import sys import struct import socket host = 'fe80::225:b3ff:fe26:576' sa = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) sa.bind((host , 50000)) But it failed: socket.error: (22, 'Invalid argument') ? Can anyone help me? thanks! I redo it like t...

WTF moments in Python

Tell us your "WTF?" moments when lerning or experimenting with Python as well as reading someone else's Python code! ...

Querying in redis

Recently I am learning redis and honestly very impressed and dying to use it. One of the things that keep bothering me is "how do I query redis". To be specific I am trying to resolve following Say I have a millions of hashes stored as below usage:1 = {created: 20100521, quantity:9, resource:1033, user:1842, ...} usage:2 = {created: 20...

Is it possible to unpack a tuple in Python without creating unwanted variables?

Is there a way to write the following function so that my IDE doesn't complain that column is an unused variable? def get_selected_index(self): (path, column) = self._tree_view.get_cursor() return path[0] In this case I don't care about the second item in the tuple and just want to discard the reference to it when it is unpac...