python

django urlencode filter

I have a problem with encoding urls using build-in django urlencode filter. When I use it on default django server everything is fine. But on apache2 it doesn`t work, ie. i have a tag called C#. On localhost my url is encoded to ...tags/C%23/ but on apache2 it is tags/C/ What should I do? ...

python url fetch help - regex

I have a web site where there are links like <a href="http://www.example.com?read.php=123"&gt; Can anybody show me how to get all the numbers (123, in this case) in such links using python? I don't know how to construct a regex. Thanks in advance. ...

PyLint "Unable to import" error - how to set PYTHONPATH?

I'm running PyLint from inside Wing IDE on Windows. I have a sub-directory (package) in my project and inside the package I import a module from the top level, ie. __init__.py myapp.py one.py subdir\ __init__.py two.py Inside two.py I have import one and this works fine at runtime, because the top-level directory (from which m...

Design pattern help

Hello I have some algorithms to do that are very similar in very aspects but are all different. I'll try to give an example of what I mean. Let's assume I have a Robot class. This class should be the "base" of all classes. It provides basic mechanisms to make the robot work in its environment. It might or not have to work by itself (...

Python urllib proxy

I'm trying to fetch some urls via urllib and mechanize through my proxy. With mechanize I try the following: from mechanize import Browser import re br = Browser() br.set_proxies({"http": "MYUSERNAME:*******@itmalsproxy.italy.local:8080"}) br.open("http://www.example.com/") I get the following error: httperror_seek_wrapper: HTTP Er...

Python: Amount of wall time a process has been running

I want to do something like this: try: pid = int(file(lock_file, "r").read()) print "%s exists with pid: %s" % (lock_file, pid) if not check_pid(pid): print "%s not running. Phantom lock file? Continuing anyways" % pid elif wall_time(pid) > 60 * 5: print "%s has been running for more than 5 minutes. Killi...

python instancemethod attributes inside wrapper

Possible Duplicate: Python decorator makes function forget that it belongs to a class Is there a way to know that wrapped method belongs to particular class? In code below: def guessname(func): def this(*args, **kwargs): print "myname = %s" % func.__name__ return func(*args, **kwargs) return this class...

Why is SQLAlchemy/associationproxy duplicating my tags?

I'm trying to use association proxy for tags, in a very similar scenario to the example in the docs. Here is a subset of my schema (it's a blog), using declarative: class Tag(Base): __tablename__ = 'tags' id = Column(Integer, primary_key=True) tag = Column(Unicode(255), unique=True, nullable=False) clas...

[GAE]How to set `inline` if in template

Hi, Coming from PHP world, I used to create select box like this: <select> <?php foreach($arrField as $idx=>$val){?> <option <?php echo ($fieldVal == $idx ? "selected='selected'" : ''); ?>><?php echo $val; ?></option> <?php } ?> </select> However, I can't do that in python. Here's my snippet: <select name='type'> <option value...

How to access a builtin module in Python when there is a local module with the same name?

How can a built-in module (say math) be accessed when a file prog.py is placed in the same directory as a local module with the same name (math.py)? I'm asking this question because I would like to create a package uncertainties that one can use as import uncertainties from uncertainties.math import * Thus, there is a local math modu...

What's a neater, more pythonic way to do the following enumeration?

for row, instrument in enumerate(instruments): for col, value in enumerate(instrument): self.table.SetValue(row, col, value) ...

Is there a function that gives me a file name without path?

I want to turn C:\abc.bmp into abc.bmp, or even better, if possible, in abc. That is easy to do with .NET as there are functions for both goals. Is there anything similar in python? ...

Compile a string to Ruby bytecode for better performance -- like compile() in Python

I have a string (authenticated, trusted, etc.) containing source code intended to run within a Ruby loop, quickly. In Python, I would compile the string into an abstract syntax tree and eval() or exec() it later: # Python 3 example given_code = 'n % 2 == 1' pred = compile(given_code, '<given>', 'eval') print("Passed:", [n for n in rang...

How to have `pip install --editable` to run sdist instead of develop?

This http://stackoverflow.com/questions/1033897/python-package-install-using-pip-or-easyinstall-from-repos points out a very interesting features of pip. However, sometimes you just want it to install the source distribution; this is particularly true when you are running in a virtualenv (so you don't care about messing up the python ...

Transitioning from desktop app written in C++ to a web-based app

We have a mature Windows desktop application written in C++. The application's GUI sits on top of a windows DLL that does most of the work for the GUI (it's kind of the engine). It, too, is written in C++. We are considering transitioning the Windows app to be a web-based app for various reasons. What I would like to avoid is having...

Write variable to file, including name

Let's say I have the following dictionary in a small application. dict = {'one': 1, 'two': 2} What if I would like to write the exact code line, with the dict name and all, to a file. Is there a function in python that let me do it? Or do I have to convert it to a string first? Not a problem to convert it, but maybe there is an easie...

How to avoid multiple instances of a program?

I need to find a right way to prevent two running instances of my (Python) program. I am currently using the following method. On Windows, os.popen('wmic process get caption,processid | findstr `programname.exe`') On Linux, os.popen('ps x | grep `programname`') It seems to work fine for now. Is this method correct? Can someone sug...

Calling Python from JavaScript

Is there a simple way to call Python libraries from JavaScript? Especially from the inside of a Firefox extension. A good option to compile a pure Python library would also be great. I looked at Pyjamas, but it seems to offer only partial support for Python. ...

How do I install Plone with gp.recipe.pip?

I would like to install Plone with buildout and gp.recipe.pip. Is this a good idea? How should I convert my "standard" Plone buildout to use pip? ...

How to select many rows from a dictionary (executemany select)

Hi everyone! I'm using Python and its MySQLdb module, is it possible to do a "selectmany"-like from a tuple/dictionary/list in the condition something like this: cursor.executemany("""SELECT * FROM customers WHERE name= %(name)s""",[d.__dict__ for d in data]) selected_rows = cursor.fecthall() doing a delete/update/insert works fin...