python

How to get full path of current directory in Python?

I want get the full directory path of current file. I tried os.path.abspath(__file__) But it return the full path including the file. C:\\python27\\test.py Where as I just need C:\\python27\\ ...

Django CMS 2.1.0 App Extension NoReverseMatch TemplateSyntaxError

I'm writing a custom app for Django CMS, but get the following error when trying to view a published entry in the admin: TemplateSyntaxError at /admin/cmsplugin_publisher/entry/ Caught NoReverseMatch while rendering: Reverse for 'cmsplugin_publisher_entry_detail' with arguments '()' and keyword arguments '{'slug': u'test-german'...

Django update table

obj = Info(name= sub,question=response_dict["question"]) obj.save() After saving the data how to update another field of the same table obj.err_flag=1 obj.update()//Will this work ...

Using Django settings in templates

Hi, I want to be able to put certain configuration information in my settings.py file - things like the site name, site url, etc. If I do this, how can I then access those settings in templates? Thanks ...

How to detect HTTP Request in python + twisted?

I am learning network programming using twisted 10 in python. In below code is there any way to detect HTTP Request when data recieved? also retrieve Domain name, Sub Domain, Port values from this? Discard it if its not http data? from twisted.internet import stdio, reactor, protocol from twisted.protocols import basic import re c...

is json package included in Python for Windows?

is json package included in Python for Windows? ...

MVC Webframeworks

Possible Duplicate: Choosing a Java Web Framework now? I know that Ruby-on-Rails and Django are 2 MVC oriented webframeworks, in Ruby and Python respectively. Are there any other MVC frameworks ? Any MVC frameworks that use Java ? ...

Socket permissions when running Django with FastCGI

I am running Django fcgi with standard line: exec setuidgid $USERID $VENVBIN/python $WEBAPP/manage.py runfcgi daemonize=false socket=$FCGISOCKET Problem is that only group is shared between fastcgi process and webserver, not user - however group do not have write permissions by default (hotfix is running chmod g+w manually). How to f...

python - multiprocessing queue put nowait blocking question

hi.. got a test function, used by a worker process. the nextqueue has been set to have a size of 1, for a single element.. foo1 can be invoked mutiple times on the 1st time through, the queue gets set correctly all other times.. it appears that the function blacks/gets stuck on the put_nowait the queue is created by importing the m...

Bibtex on a webpage?

Are there any python packages to parse a Bibtex file, and output the result using html/xhtml format, with a customizable styles? Preferably, I would like to use python, otherwise what are the most used in PHP? ...

files getting wrongly cached by the web server while using standard python file operations (Django)

I have a Django app, which populates content from a text file, and populates them using the initial option in a standard form. The file gets updated on the server, but when the form gets refreshed, it picks up content from the a previously saved version, or the version before the Apache WebServer was reloaded. This means that the file i...

Launch default image viewer from pygtk program

Hi there! I'm writing a PyGTK GUI application in Ubuntu to browse some images, and I'd like to open an image in the default image viewer application when it is double-clicked (like when it is opened in Nautilus). How can I do it? ...

wxPython: Highlight item in GidSizer upon mouse click

I have a Panel with a bunch of pictures placed on it in a GridSizer layout. How can I draw a highlighted color around the edge of an image or its border to show that it has been selected upon a mouse click event? ...

Stop SQL query in python

Is there a way to let the user stop the execution of a sql query in python if it takes some long time? I am thinking of using a progress bar with a cancel button, but I wonder if there is a way to stop it in a clean way instead of killing abruptly the associated thread? (I am using both pysqlite2 and MySQLdb packages) ...

How to get unpickling to work with iPython?

Hello, I'm trying to load pickled objects in iPython. The error I'm getting is: AttributeError: 'FakeModule' object has no attribute 'World' Anybody know how to get it to work, or at least a workaround for loading objects in iPython in order to interactively browse them? Thanks edited to add: I have a script called world.py th...

What code can I use to check if Python is running in IDLE?

Just as the title says. I want to write a script that behaves differently depending on whether it's running inside a console window or in IDLE. Is there an object that exists only when running in IDLE that I can check for? An environment variable? I'm using Python 2.6.5 and 2.7 on Windows. Edit: The answers given so far work. But I'm ...

How do I write only certain lines to a file in Python?

I have a file that looks like this(have to put in code box so it resembles file): text (starts with parentheses) tabbed info text (starts with parentheses) tabbed info ...repeat I want to grab only "text" lines from the file(or every fourth line) and copy them to another file. This is the code I have, but it copies ...

Creating functions in a loop

I'm trying to create functions inside of a loop and storing them in a dictionary. The problem is that all entries in the dictionary seem end up mapping to the last created function. The code goes like this: d = {} def test(**kwargs): for k in kwargs: def f(): print k, kwargs[k] d[k] = f f() test...

Generating custom forms from DB schema

Hi, I am a current web2py user, but find I still go back to Django once in a while (where I started). Specifically when working on projects where I want to make use of some specific django apps/plugins/extensions that don't yet exist in web2py. One thing that I can't live without in web2py, which I am looking for a solution for in Dja...

Python: Generating a MD5 checksum of a file?

Is there any simple way of generating (and checking) MD5 checksums of a list of files in Python? (I have a small program I'm working on, and I'd like to confirm the checksums of the files). ...