python

reverse mapping of dictionary with Python

If I have a dictionary named ref as follows ref = {} ref["abc"] = "def" I can get "def" from "abc" def mapper(from): return ref[from] But, how can I get from "def" from "abc"? def revmapper(to): ??? ...

Specifying number of decimal places in Python

When accepting user input with a decimal in Python I'm using: #will input meal subtotal def input_meal(): mealPrice = input('Enter the meal subtotal: $') mealPrice = float (mealPrice) return mealPrice which returns exactly what is entered - say $43.45 but when using that value to calculate and display tax I'm u...

Python Threading String Arguments

I have a problem with Python threading and sending a string in the arguments. def processLine(line) : print "hello"; return; . dRecieved = connFile.readline(); processThread = threading.Thread(target=processLine, args=(dRecieved)); processThread.start(); Where dRecieved is the string of one line read by a connection. It cal...

Since Django 1.2.1 'prepopulated_fields' won't prepopulate in the admin.

Since Django 1.2.1 'prepopulated_fields' won't prepopulate in the admin. prepopulated_fields = {'slug': ('title',)} doesn't seem to work since uploading to a Django 1.2.1 server after developing on a 1.1.1. What changed? I read http://code.djangoproject.com/wiki/NewformsAdminBranch#Changedprepopulate_fromtobedefinedintheAdminclassnot...

How big can variable be, in python?

I get an response in Python program from SQL server. How big can this response be? What is the maximum? Coult it be as much as about 100 mb? ...

How to debug a Jquery Dialog

I have a fairly basic dialog maker for jquery that works in 2 out of 3 places. In the 3rd instance where I try to use it, the fields in the form are disabled once the dialog is displayed. The general concept behind the code is that the form is on a different page of the website, and for convenience, when javascript is enabled, you can ...

Why are session methods unbound in sqlalchemy using sqlite?

Code replicating the error: from sqlalchemy import create_engine, Table, Column, Integer from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker Base = declarative_base() class Message(Base): __tablename__ = 'messages' id = Column(Integer, primary_key=True) message = Column(Integer)...

How can I find the first occurrence of a sub-string in a python string?

So if my string is "the dude is a cool dude". I'd like to find the first index of 'dude': mystring.findfirstindex('dude') # should return 4 What is the python command for this? Thanks. ...

Is it possible to get widget settings in Tkinter?

It'd be awesome if I could get something like the below. Pseudo Code: U = widget1.SettingsGet() Print U Upon printing U something like this would be returned: widget1(background='green',foreground='grey',boarderwidth=10, relief='flat') It would be really useful to be able to get a widgets settings. So that I can manipulate other ...

Soaplib Client Server Example causing an error

Error I am getting: Traceback (most recent call last): File "client.py", line 11, in print client.say_hello("Dave",5) AttributeError: 'ServiceClient' object has no attribute 'say_hello' Server Code: #!/usr/bin/env python from soaplib.wsgi_soap import SimpleWSGISoapApp from soaplib.service import soapmethod from soaplib.seriali...

What is the simplest way to make tooltips in Tkinter?

For those that don't know, tooltips are those little bits of text that popup when the mouse hovers over a widget for a certain durration of time. I'm using Windows 7 if it makes a difference. ...

Google wave authentication login on 3rd party website

Hey, im trying to figure out how to make a user authenticate with my web app using google accounts and be recognized as an active session with google wave. Currently when i use google accounts login, everything works fine but embedded google wave widgets dont recognize the users session and asks him to relogin. The only way i found aro...

whats the best way to parser csv using python ?

I need to develop a script, with input csv file, this file contains multiple headers [headers are language(fr,en,...) specific] and between headers there will be specific data - you can say we've have a well defined CSV template, which will be parsed and will be converted to a specific pydict-dictionary and then this dictionary will be ...

What's the best way to dump a MYSQL table to CSV?

Possible Duplicate: Dump a mysql database to a plaintext (CSV) backup from the command line. I prefer python, but if mysqldump works...then how can I do that? ...

Simulating C#'s sbyte (8 bit signed integer) casting in Python

In C#, I can cast things to 8bit signed ints like so: (sbyte)arg1; which when arg1 = 2, the cast returns 2 also. However, obviously casting 128 will return -128. More specifically casting 251 will return -5. What's the best way to emulate this behavior? Edit: Found a duplicate question: http://stackoverflow.com/questions/385572/need...

Python 2.6: Class inside a Class?

Hey everyone, my problem is that im trying to figure out how to get a class INSIDE another class. What I am doing is I have a class for an Airplane with all its statistics as to how fast it can fly, how far it can go, fuel consumption, and so on. Then I have a Flight Class which is all the details about the flight: Distance, starting lo...

Python2.7 Active Console to Prevent Deadlock?

I noticed an interesting behavior for my system on Windows XP To debug my system, I used cmd console to start the server xProcess = subprocess.Popen(args='Python.exe ClntMgrSvrFact.py', creationflags=CreationFlags|win32con.CREATE_NEW_CONSOLE) For each client(MSExcel) connected via TCP/IP, server factory will spawn a new process using...

How to render HTML form from schema using formencode?

I'm using formencode for validating and submitting forms in my Pylons application. The documentation says that it can be used also for generating forms, but there is no any example. I even found the old topic which says it can be done with form = HTMLForm(form_template, FormSchema) form.render() but for the latest version of formenco...

Why is Python 3.1 slower than 2.6 for this code?

Consider the following code (from here, with the number of tests increased): from timeit import Timer def find_invpow(x,n): """Finds the integer component of the n'th root of x, an integer such that y ** n <= x < (y + 1) ** n. """ high = 1 while high ** n < x: high *= 2 low = high/2 while low < high:...

General guidelines for developing a web application

As a programmer used to developing native applications, I'm expanding my horizons and developing my first web app. I'm intermediate to expert with Linux and C, intermediate with Python and HTML and beginner to intermediate with MySQL and Java. I'm developing a web app that is more or less a resource allocator for a friend of mine. To pu...