Python Case Insensitive Replace
What's the easiest way to do a case-insensitive str.replace in Python? ...
What's the easiest way to do a case-insensitive str.replace in Python? ...
I have been working on some code. My usual approach is to first solve all of the pieces of the problem, creating the loops and other pieces of code I need as I work through the problem and then if I expect to reuse the code I go back through it and group the parts of code together that I think should be grouped to create functions. I...
from PIL import ImageFile as PILImageFile p = PILImageFile.Parser() #Parser the data for chunk in content.chunks(): p.feed(chunk) try: image = p.close() except IOError: return None #Here the model is RGBA if image.mode != "RGB": image = image.convert("RGB") It always get stuck in here: ima...
I started working on a web application. This application needs lot of image handling. I started off with PHP as it was the easiest and cheapest to host. I have used the .NET framework for some of my previous applications and I'm very comfortable with Python. But I'm not at all comfortable using PHP now, so I have decided to use somethi...
I'd like to resize a ctypes array. As you can see, ctypes.resize doesn't work like it could. I can write a function to resize an array, but I wanted to know some other solutions to this. Maybe I'm missing some ctypes trick or maybe I simply used resize wrong. The name c_long_Array_0 seems to tell me this may not work with resize. >>> fr...
How do you serve Cheetah in production? Guys can you share the setup on how to precompile and serve cheetah in production Since we dont compile templates in webpy it is getting upstream time out errors. If you could share a good best practise it would help * Jeremy [email protected] wrote: For a production site, I use Cheet...
Hi guys, im wondering if there is any online service who provide API about the train timetables (arrivals, departure, etch..), at least for the european stations. I know www.bahn.de, who provide the accurated timetables for many european countries, but i didin't find any similar to a api service. My goal (well, just a future-project) i...
In a similar way to using varargs in C or C++: fn(a, b) fn(a, b, c, d, ...) ...
In a django application I am working on, I have just added the ability to archive a number of files (starting 50mb in total) to a zip file. Currently, i am doing it something like this: get files to zip zip all files send HTML response Obviously, this causes a big wait on line two where the files are being compressed. What can i do to...
I am starting to get a bit bored of programming little toys that I have been making recently, and I would love to starting programming and interacting with hardware. The only problem is that I am mostly a python guy who hasn't really learned or used any other language. Can I still interact with hardware with python? Also, what hardware...
I have a multi-threading Python program, and a utility function, writeLog(message), that writes out a timestamp followed by the message. Unfortunately, the resultant log file gives no indication of which thread is generating which message. I would like writeLog() to be able to add something to the message to identify which thread is ca...
I am working on a library that loads files (hfd5 - pytables) into an object structure. The actual classes being used for the structure is loaded as a string from the hdf5 file, and then loaded in this fashion: class NamespaceHolder(dict): # stmt is the source code holding all the class defs def execute(self, stmt): exec ...
I am just started out learning Python and also started looking into Django a little bit. So I copied this piece of code from the tutorial: # Create your models here. class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def __unicode__(self): return s...
We have a nasty problem where we see that the python logging module is behaving differently when running with mod_python on our servers. When executing the same code in the shell, or in django with the runserver command or with mod_wsgi, the behavior is correct: import logging logger = logging.getLogger('site-errors') logging.debug('log...
Hey i have a webpage for searching a database. i would like to be able to implement cookies using python to store what a user searches for and provide them with a recently searched field when they return. is there a way to implement this using the python Cookie library?? ...
import cgitb import Cookie, urllib2 from cookielib import FileCookieJar cgitb.enable() c = Cookie.SmartCookie() c['ini'] = 1 savedc = FileCookieJar() savedc.add_cookie_header(c.output()) savedc.save() shoulden't this save the cookie?... i've been reading over the python documentation like 1 million times, i just don't get it :( pleas...
Hi, Im currently finding problems in when should I use the While loop or the For loop in python. What looks like is that people prefer using the For loop (less code lines?), is there any specific situation wich I should use one or the other? Its a matter of personal preference? Or the codes I had read so far made me think wrong, and curr...
I've just introspected a pretty nasty schema from a CRM app with sqlalchemy. All of the tables have a deleted column on them and I wanted to auto filter all those entities and relations flagged as deleted. Here's what I came up with: class CustomizableQuery(Query): """An overridden sqlalchemy.orm.query.Query to filter entities ...
I'm working on plone 3.2.1 and I've made a formlib's form with a custom template: from Products.Five.formlib import formbase from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile ... class MyForm(formbase.PageForm): ... template = ViewPageTemplateFile('myform.pt') I want to make a simple change to the stand...
I've been playing around with the email module in python but I want to be able to know how to embed images which are included in the html. So for example if the body is something like <img src="../path/image.png"></img> I would like to embed image.png into the email, and the src attribute should be replaced with a content-id. Does an...