python

What is better in python, a Dictionary or Mysql ?

What would be faster ? Query mysql to see if the piece of information i need is there, OR load a python dictionary with all the information then just check if the id is there If python is faster, then whats the best what to check if the id exists? Im using python 2.4.3 Im searching for data which is tagged to a square on a board, im s...

Installing rpy2 -2.1.5 on Mac OS X 10.5.8 fails

Hello, I've searched far and wide, read a previous question in stackoverflow but cant seem to solve the problem of installing rpy2 on my Mac with OS X 10.5.8. I have Xcode 3.1.4 installed and R 2.1.11. when I run: sudo python setup.py build install I get this: running build running build_py running build_ext building 'rpy2.rinterfac...

Python - question about factory functions

I have a series of classes that I'll be registering as services to a higher level abstraction class. The high-level class will have a function that gets the lower level class based on init args, etc. Does this sound berserk? Also, what is this called? I call it factory function/class, but I really have no idea (which makes it harder to G...

workaround: fullscreen over multiple monitors in windows 7

python 3: from ctypes import windll windowName = 'Adobe Flash Player 10' width = 2560 height = 1024 menuHeight = 20 GWL_STYLE = -16 WS_CAPTION = 0x00C00000 WS_THICKFRAME = 0x00040000 HWND_TOP = 0 SWP_FRAMECHANGED = 0x0020 hwnd = windll.user32.FindWindowW(None, windowName) ws = windll.user32.GetWindowLongW(hwnd, GWL_STYLE) & ~(WS_CAPT...

Python+Celery: Chaining jobs?

The Celery documentation suggests that it's a bad idea to have tasks wait on the results of other tasks… But the suggested solution (see “good” heading) leaves a something to be desired. Specifically, there's no clear way of getting the subtask's result back to the caller (also, it's kind of ugly). So, is there any way of “chaining” job...

Performance comparison of immutable string concatenation between Java and Python

UPDATES: thanks a lot to Gabe and Glenn for the detailed explanation. The test is wrote not for language comparison benchmark, just for my studying on VM optimization technologies. I did a simple test to understand the performance of string concatenation between Java and Python. The test is target for the default immutable String obj...

Difference between "if x" and "if x is not None"

It appears that "if x" is almost like short-hand for the longer "if x is not None" syntax. Are they functionally identical or are there cases where for a given value of x the two would evaluate differently? I would assume the behavior should also be identical across Python implementations - but if there are subtle differences it would b...

Following the result of pressing a submit button in Python Mechanize

So I have an authenticated site that I want to access via the mechanize module. I'm able to log in, and then go to the page I want. However, because the page recognizes that mechanize doesn't have javascript enabled, it wants me to click a submit button to get redirected to a non javascript part of the site. How can I simply click the bu...

Edit regex in python script

The following python script allows me to scrape email addresses from a given file using regular expressions. I'm trying to add phone numbers to the regular expression also. I created this regex and seems to work on 7 and 10 digit numbers: (\d{3}[-\.\s]??\d{3}[-\.\s]??\d{4}|\(\d{3}\)\s*\d{3}[-\.\s]??\d{4}|\d{3}[-\.\s]??\d{4}) Can this...

how reduce the number of points of a waveform?

I have this, f = audiolab.Sndfile('test.wav', 'r') data = f.read_frames(f.nframes, dtype=numpy.int16) pyplot.rcParams['figure.figsize'] = 10, 2 pyplot.plot(data) pyplot.xticks([]) pyplot.yticks([]) pyplot.show() but the ploting is slow and freeze the pc, hoy I can reduce the numbers of points or how can I increase the performance...

Python - Write a function that takes a string as an argument and displays the letters backward, one per line.

This is an exercise from "How to think like a Computer Scientist". I am learning Python/programming and I'm not sure how to do accomplish this task. Here is an example in the book that displays the letters forwards, I can't figure out how to get the opposite effect. Has to use a while-loop. fruit = 'banana' index = 0 while index > ...

How to support recursive include when parsing xml

I'm defining an xml schema of my own which supports the additional tag "insert_tag", which when reached should insert the text file at that point in the stream and then continue the parsing: Here is an example: my.xml: <xml> Something <insert_file name="foo.html"/> or another </xml> I'm using xmlreader as follows: class HtmlH...

I'm new to python, and trying to program a sales tax button for a calculator.

Hello, I just started programming in python not long ago, and I'm having trouble figuring out the rounding issue when it comes to tax and money. I can't seem to get decimals to always round up to the nearest hundredths place. for instance, in our state, sales takes is 9.5%, so a purchase of 5 dollars would make tax $.48, but in realit...

Characters not making it from a master to a slave pseudo-terminal

Hello, I am currently trying to send binary data out through pexpect. For some reason, the data gets through just find except for a 0x04, which is just skipped over. I tracked down the pexpect call to determine that all thats happening is an os.write() call to a file descriptor opened from a pty.fork() command. Any ideas? (example...

Why thread is interrupted before the changes are complete.

I'm attempting to create python module for getting MAC adresses by IP addresses. def getMACs(addressesList): def _processArp(pkt): spa = _inet_ntoa(pkt.spa) if pkt.op == dpkt.arp.ARP_OP_REPLY and spa in _cache.macTable: lock.acquire() try: _cache.macTable[spa] = _packedToMacSt...

PyQt QTableWidget keyboard events while editing

I want to navigate QTableWidget in a similar way to MS Excel. e.g. When the user presses the right arrow key while editing a cell, the editing will finish and the next cell to the right will be selected. I have searched the Qt docs, but can't seem to find out how. Can anyone hep? Thanks. ...

What are methods of programmatically detecting many-to-many relationships in a RDMBS?

Hello stackoverflow, I'm currently busy making a Python ORM which gets all of its information from a RDBMS via introspection (I would go with XRecord if I was happy with it in other respects) — meaning, the end-user only tells which tables/views to look at, and the ORM does everything else automatically (if it makes you actually write s...

Is it possible for SymPy to render LaTeX for use in a GUI?

Hello all, I am hoping to use PyQt to produce an application that will display an equation entered by the user. I had considered matplotlib, but this seems like overkill as I would only be using it to render the latex. I need to use SymPy anyway, so I was hoping there would be a way to use it to do the rendering also, preferably produc...

Finding combination in Python without importing itertools

Hi everyone, I want following task to be done in Python without importing any modules. My Code consists Two List --------- list1=['aun','2ab','acd','3aa'] list2=['ca3','ba2','dca','aa3'] Function --------- Where it will: Generates 2 items combination from list1 Generates 2 items combination from list2 Generates 2 items combinatio...

Calling C# object from IronPython

I have the following C# code to compile it into MyMath.dll assembly. namespace MyMath { public class Arith { public Arith() {} public int Add(int x, int y) { return x + y; } } } And I have the following IronPython code to use this object. import clr clr.AddReferenceToFile("MyMath.dll") imp...