python

Python dictionaries: changing the order of nesting

I have a dictionary, with 300 key value pairs, where each of the keys are integers and the values are dictionaries with three key value pairs. The inner dictionaries all have the same keys, but different values. The whole thing looks pretty much like this: nested_dicts = {1: {'name1':88.4, 'name2':22.1, 'name3':115.7}, 2: {'...

How to split a dos path into its components in Python

I have a string variable which represents a dos path e.g: var = "d:\stuff\morestuff\furtherdown\THEFILE.txt" I want to split this string into: [ "d", "stuff", "morestuff", "furtherdown", "THEFILE.txt" ] I have tried using split() and replace() but they either only process the first backslash or they insert hex numbers into the string...

Rename a computer programmatically

I need to automate the changing of the hostname of a computer, but I can't figure out how to do it inside a program. My options are open; I would be happy with a solution in any of the following: Command line Java Python C# (would prefer one of the other 3, but this is ok) It would be helpful to learn how to do this on both Linux and W...

How often does python flush to a file?

I was wondering how often python flushes to a file. Also wondering how often python flushes to stdout. I believe python flushes to stdout after every new line but that being said, if you overload stdout to be to a file does it flush as often as stdout or how often it flushes to a file? Anyways thanks! And sorry for the pretty simple que...

django ORM: make query

Hi. I'm studying django. In my project I'm having trouble with making a query with django ORM: SELECT MIN( id ) AS id, domain, COUNT( * ) AS cnt FROM app_competition WHERE word_id = 1545 GROUP BY domain Help me please make this query ...

Picking a front-end/interpreter for a scientific code.

The simulation tool I have developed over the past couple of years, is written in C++ and currently has a tcl interpreted front-end. It was written such that it can be run either in an interactive shell, or by passing an input file. Either way, the input file is written in tcl (with many additional simulation-specific commands I have a...

Complex HTML parsing with Python

I am already aware of tag based HTML parsing in Python using BeautifulSoup, htmllib etc. However, I want a powerful engine which can do complex tasks like read html tables, lists etc. and present these as simple to use objects within code. Does python have such powerful libraries? ...

Change Django ModelChoiceField to show users' full names rather than usernames

I have a form in my Django app (not in admin) that allows staff members to select a user from a dropdown. forms.ModelChoiceField(queryset = User.objects.filter(is_staff=False), required = False) The problem is that the dropdown shows users by usernames whereas I'd rather it show their full name from user.get_full_name() and use userna...

one field with diferent datatypes [SQLAlchemy]

i have a value that can be integer, float or string, and i create diferent columns: #declarative class MyClass(Base): #id and other Columns _value_str = Column(String(100)) _value_int = Column(Integer) _value_float = Column(Float) def __init__(self,...,value): self._value_str = value if isinstance(value,(...

Programmatically interrupting raw_input

Is there a way to programmatically interrupt Python's raw_input? Specifically, I would like to present a prompt to the user, but also listen on a socket descriptor (using select, for instance) and interrupt the prompt, output something, and redisplay the prompt if data comes in on the socket. The reason for using raw_input rather than s...

Printing on default Printer from Blender Game Engine via Python(pywin32/win32api), Windows7

Hello People, i'm new here and i'm a beginner, i got this adress from a friend, who told me, this is a great site to get problems solved. The Problem: I have a working code, wich simlpy prints out a PDF on the default printer: path = "C://EWZdef/PDF/" + str(ob['OBcontrol']['scanned']) +".pdf" def PRINT(): import win32api wi...

Getting computer's utc offset in Python

Hopefully a simple question, but I've been searching and searching with no luck: In Python, is there a way to figure out what utc time offset the computer is set to? ...

How can I open a website with urllib via proxy? [Python]

Hello there I have this program that check a website, and I want to know how can I check it via proxy in Python... this is the code, just for example while True: try: h = urllib.urlopen(website) break except: print '['+time.strftime('%Y/%m/%d %H:%M:%S')+'] '+'ERROR. Trying again in a...

Python import question

Hi. Consider I have a directory called root that has two directories: x and y. I have a module file that resides in x, let us call that test.py. Now in y, I have a module that needs to call test.py I am doing a simple: from x import test And it works. I was wondering, how this works? EDIT: How it works, as in there was no __init__...

how to show a html page in a js file on google app engine .

$('#upload').click(function(){ $('#main .right').html("{% extends 'a.html' %}") }) but this is error , how to make this code running . thanks ...

how to extends the parent html page on google app engine

templates | ....a.html |.....admin |..... index.html |..... b.html in google app engine templates, i can use this to extends b.html in index.html: {% extends 'b.html' %} but how to extends a.html in index.html. thanks ...

Python fast string parsing, manipulation

I am using python to parse the incoming comma separated string. I want to do some calculation afterwards on the data. The length of the string is: 800 characters with 120 comma separated fields. There such 1.2 million strings to process. for v in item.values(): l.extend(get_fields(v.split(','))) #process l get_fields use...

Python parsing files

I need to know the best approach for the following scenario lets say we have some huge file which logs the output of the compilation and there are couple of error patterns which I want to test against this file, for eg. error patterns could be - : error: - : error [A-Z]*[\d ]* - [A-Z]*[\d]* [E\e|rror: - " Cannot open include file ...

How to debug socket error

Hi! I've this code: 1 upload_odl function import os import urllib2_files import urllib2 user = 'patrick' password = 'mypass' url = 'http://localhost:8000/api/odl/' password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() password_manager.add_password( None, url, user, password ) auth_handler = urllib2.HTTPBasicAuthHandler(p...

Help with cPickle in Python 2.6

I tried the following code I python. This is my first attempt at pickling. import Tkinter import cPickle root = Tkinter.Tk() root.sclX = Tkinter.Scale(root, from_=0, to=1500, orient='horizontal', resolution=1) root.sclX.pack(ipadx=75) root.resizable(False,False) root.title('Scale') with open('myconfig.pk', 'wb') as f: cPick...