python

How to know when you are in a symbolic link

How to know, in Python, that the directory you are in is inside a symbolic link ? I have a directory /tmp/foo/kiwi I create a symlink /tmp/bar pointing to /tmp/foo I enter into /tmp/bar/kiwi the linux command pwd tells me I'm in /tmp/bar/kiwi, which is correct. The python command prompt tells me I'm in /tmp/foo/kiwi: Python 2.5.1 (...

cascading forms in Django/else using any Pythonic framework

Can anyone point to an example written in Python (django preferred) with ajax for cascading forms? Cascading Forms is basically forms whose field values change if and when another field value changes. Example Choose Country, and then States will change... ...

How to properly interact with a process using subprocess module

I'm having problems redirecting stdio of another program using subprocess module. Just reading from stdout results in hanging, and Popen.communicate() works but it closes pipes after reading/writing. What's the easiest way to implement this? I was playing around with this on windows: import subprocess proc = subprocess.Popen('python -c...

_lsprof.c profiler behaviour towards python multi-threading

Hello! This is a question about Python native c file _lsprof. How does _lsprof.profile() profiler counts total time spent on a function f in a multi-threaded program if the execution of f is interrupted by another thread? For example: def f(): linef1 linef2 linef3 def g(): lineg1 lineg2 And at the execution we have, f...

Jython, Query multiple columns dynamically

Hey all, I am working with a oracle database and Jython. I can get data pulled from the database no problem. results = statement.executeQuery("select %s from %s where column_id = '%s'", % (column, table, id)) This works fine if I want to pull one column of data. Say I wanted to loop threw a list like this: columns = ['column1', 'c...

Why does Paramiko hang if you use it while loading a module?!

Put the following into a file hello.py (and easy_install paramiko if you haven't got it): hostname,username,password='fill','these','in' import paramiko c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(hostname=hostname, username=username, password=password) i,o,e = c.exec_command('ls /') print(...

Django template ifequal comparison of decimals

So, I have a decimalfield that can be 3 different values. In my view, I pass in a dictionary of values that contains the appropriate decimal values as keys. {% for item in booklist %} {% for key, value in numvec.items %} {{item.number}} {% ifequals item.number {{key}} %} {{value}} {% end...

Addressing instance name string in __init__(self) in Python.

I am doing something like this: class Class(object): def __init__(self): self.var=#new instance name string# How do I make the __ init __ method of my instance to use the instance name string for 'c'? Say in case: c=Class() I want c.var equal to 'c'. Thanks for your replies, I am implementing persistence and Class is p...

python, index errors

I've got some code which draws data from an xml file but it seems to have randomly starting throwing; Traceback (most recent call last): File "C:\Users\mike\Documents\python\arl xml\turn 24 reader", line 52, in <module> unitCount = getText(evoNode.getElementsByTagName("count")[0].childNodes) IndexError: list index out of range ...

Python: Callbacks, Delegates, ... ? What is common?

Hi! Just want to know what's the common way to react on events in python. There are several ways in other languages like callback functions, delegates, listener-structures and so on. Is there a common way? Which default language concepts or additional modules are there and which can you recommend? ...

Why don't Django admin "Today" and "Now" buttons show up in Safari?

I'm developing a Django application that contains a model with a date/time field. On my local copy of the application, the admin page for that particular model shows this for the date/time field: This is as expected. However, when I deploy to my webserver and use the application from there, I get this: The application on the server...

How to create python bytes object from long hex string?

I have a long sequence of hex digits in a string, such as 000000000000484240FA063DE5D0B744ADBED63A81FAEA390000C8428640A43D5005BD44 only much longer, several kilobytes. Is there a builtin way to convert this to a bytes object in python 2.6/3? ...

python - readable list of objects

This is probably a kinda commonly asked question but I could do with help on this. I have a list of class objects and I'm trying to figure out how to make it print an item from that class but rather than desplaying in the; <__main__.evolutions instance at 0x01B8EA08> but instead to show a selected attribute of a chosen object of the c...

How do I find out the path of the currently executing script?

Duplicate of: In Python, how do I get the path and name of the file that is currently executing? I would like to find out the path to the currently executing script. I have tried os.getcwd() but that only returns the directory I ran the script from not the actual directory the script is stored. ...

sqlalchemy, turning a list of IDs to a list of objects

I have sequence of IDs I want to retrieve. It's simple: session.query(Record).filter(Record.id.in_(seq)).all() Is there a better way to do it? ...

How are debug consoles implemented in Python?

I've seen a couple of Python IDE's (e.g. PyDev Extensions, WingIDE) that provide a debug console - an interactive terminal that runs in the context of the method where the breakpoint is. This lets you print members, call other methods and see the results, and redefine methods to try to fix bugs. Cool. Can anyone tell me how this is impl...

convert a string of bytes into an int (python)

How can I convert a string of bytes into an int in python? Say like this: 'y\xcc\xa6\xbb' I came up with a clever/stupid way of doing it: sum(ord(c) << (i * 8) for i, c in enumerate('y\xcc\xa6\xbb'[::-1])) I know there has to be something builtin or in the standard library that does this more simply... This is different from conve...

How to make a wx Toolbar buttons larger?

I've got a wx.Toolbar and I'd like to make the buttons larger. I've searched and can't seem to find any concrete documentation on how to do this. I'm also wondering how well this will translate across platforms; what will happen to the buttons and icons on OSX? ...

Cleanest way to run/debug python programs in windows

Python for Windows by default comes with IDLE, which is the barest-bones IDE I've ever encountered. For editing files, I'll stick to emacs, thank you very much. However, I want to run programs in some other shell than the crappy windows command prompt, which can't be widened to more than 80 characters. IDLE lets me run programs in i...

Regular Expression in Python - Parsing html

I need to search through an html doc, find all of the spans and delete the spans and everything between them. What would a regular expression look like that would match everything between ? ...