python

python saving unicode into file

Hi all, i'm having some trouble figuring out how to save unicode into a file in python. I have the following code, and if i run it in a script test.py, it should create a new file called priceinfo.txt, and write what's in price_info to the file. But i do not see the file, can anyone enlighten me on what could be the problem? Thanks a lo...

Multiple regression in Python

Hello, I am currently using scipy's linregress function for single regression. I am unable to find if the same library, or another, is able to do multiple regression, that is, one dependent variable and more than one independent variable. I'd like to avoid R if possible. If you're wondering, I am doing FX market analysis with the goal ...

Accessing Reuters data in Python

Hello, I am currently successfully downloading live Bloomberg market prices, as well as historical series, using the service's COM API and win32com. Does anyone have any experience doing the same for Reuters live and historical data into Python? I know that live feeds are available for both services in Excel, so Reuters must also have...

How to get Python syntax highlighting for Visual Studio?

Visual Studio 2008 is great as text editor, but it lacks Python syntax highlighting, can I get this as an add-on? Where can I find it? ...

Equivalent of NotImplementedError for fields in Python

In Python 2.x when you want to mark a method as abstract, you can define it like so: class Base: def foo(self): raise NotImplementedError("Subclasses should implement this!") Then if you forget to override it, you get a nice reminder exception. Is there an equivalent way to mark a field as abstract? Or is stating it in the...

Mechanize not being installed by easy_install?

I am in the process of migrating from an old Win2K machine to a new and much more powerful Vista 64 bit PC. Most of the migration has gone fairly smoothly - but I did find that I needed to reinstall ALL of my Python related tools. I've downloaded the mechanize-0.1.11.tar.gz file and ran easy_install to install it. This produced C:\Pytho...

Error on connecting to Oracle from py2exe'd program: Unable to acquire Oracle environment handle

My python program (Python 2.6) works fine when I run it using the Python interpreter, it connects to the Oracle database (10g XE) without error. However, when I compile it using py2exe, the executable version fails with "Unable to acquire Oracle environment handle" at the call to cx_Oracle.connect(). I've tried the following with no joy...

Python hashable dicts

As an exercise, and mostly for my own amusement, I'm implementing a backtracking packrat parser. The inspiration for this is i'd like to have a better idea about how hygenic macros would work in an algol-like language (as apposed to the syntax free lisp dialects you normally find them in). Because of this, different passes through the ...

tkMessageBox

Hello, Can anybody help me out in how to activate 'close' button of askquestion() of tkMessageBox?? ...

How can I perform a ping or traceroute using native python?

I would like to be able to perform a ping and traceroute from within Python without having to execute the corresponding shell commands so I'd prefer a native python solution. ...

Where and how is django Model objects attribute defined?

Dear all, I'm trying to get my head around Django ORM. I've been reading django.db.models.base.py source code but still could understand how does the Model.objects attributes in our Model object gets defined. Does anybody know how does django adds that objects attribute into our Model object? Thanks in advance ...

How can I perform a ping or traceroute in python, accessing the output as it is produced?

Earlier, I asked this question: How can I perform a ping or traceroute using native python? However because python is not running as root it doens't have the ability to open the raw ICMP sockets needed to perform the ping/traceroute in native python. This brings me back to using the system's ping/traceroute shell commands. This quest...

Dropdown sorting in django-admin

I'd like to know how can I sort values in the Django admin dropdowns. For example, I have a model called Article with a foreign key pointing to the Users model, smth like: class Article(models.Model): title = models.CharField(_('Title'), max_length=200) slug = models.SlugField(_('Slug'), unique_for_date='pub...

Python Printing StdOut As It Recieved.

I'm trying to run wrap a simple (windows) command line tool up in a PyQt GUI app that I am writing. The problem I have is that the command line tool throws it's progress out to stdout (it's a server reset command so you get "Attempting to stop" and "Restarting" type output. What I am trying to do is capture the output so I can display ...

Python iterators – how to dynamically assign self.next within a new style class?

As part of some WSGI middleware I want to write a python class that wraps an iterator to implement a close method on the iterator. This works fine when I try it with an old-style class, but throws a TypeError when I try it with a new-style class. What do I need to do to get this working with a new-style class? Example: class Iterator...

Alternative to the `match = re.match(); if match: ...` idiom?

If you want to check if something matches a regex, if so, print the first group, you do.. import re match = re.match("(\d+)g", "123g") if match is not None: print match.group(1) This is completely pedantic, but the intermediate match variable is a bit annoying.. Languages like Perl do this by creating new $1..$9 variables for mat...

django documentation locally setting up

Hi Guys , I was trying to setup django . I do have Django-1.1-alpha-1. I was trying to make the documentation which is located at Django-1.1-alpha-1/doc using make utility. But I am getting some error saying > C:\django\Django-1.1-alpha-1\docs>C:\cygwin\bin\make.exe html mkdir -p _build/html _build/doctrees sphinx-build -b html -d ...

close window in Tkinter message box

Hello, link text How to handle the "End Now" error in the below code: import Tkinter from Tkconstants import * import tkMessageBox tk = Tkinter.Tk() class MyApp: def __init__(self,parent): self.myparent = parent self.frame = Tkinter.Frame(tk,relief=RIDGE,borderwidth=2) self.frame.pack() self.m...

Is it better to use an exception or a return code in Python?

You may know this recommendation from Microsoft about the use of exceptions in .NET: Performance Considerations ... Throw exceptions only for extraordinary conditions, ... In addition, do not throw an exception when a return code is sufficient... (See the whole text at http://msdn.microsoft.com/en-us/library/sys...

memcache entities without ReferenceProperty

I have a list of entities which I want to store in the memcache. The problem is that I have large Models referenced by their ReferenceProperty which are automatically also stored in the memcache. As a result I'm exceeding the size limit for objects stored in memcache. Is there any possibility to prevent the ReferenceProperties from...