python

How to mimic vb's control array in python for win32com ?

I need to dynamically create com objects from an activex dll and each of the objects can raise events which should be handled with event handlers. I can do this easily with win32com.client.Dispatch and win32com.client.WithEvents and associate a "separate" class of event handlers with each of the objects. Like so: class evt_1: def O...

Datetime problem at start of month in Python

Hello, I have a function that removes a file after a certain amount of time. The problem is that it works at later parts of the month, but when I try and remove 7 days from the start of the month it will not substract into the previous month. Does anyone know how to get this to work? The code is below that works out the date and removes...

Replace string in a specific line using python

I'm writing a python script to replace strings from a each text file in a directory with a specific extension (.seq). The strings replaced should only be from the second line of each file, and the output is a new subdirectory (call it clean) with the same file names as the original files, but with a *.clean suffix. The output file contai...

Python's Regular Expression Source String Length

In Python Regular Expressions, re.compile("x"*50000) gives me OverflowError: regular expression code size limit exceeded but following one does not get any error, but it hits 100% CPU, and took 1 minute in my PC >>> re.compile(".*?.*?.*?.*?.*?.*?.*?.*?.*?.*?"*50000) <_sre.SRE_Pattern object at 0x03FB0020> Is that normal? Should ...

Wrong encoding of text, in Django?

"query" = джазовыми For some reason...when I display it via: {{ query|safe }} I get this: %u0434%u0436%u0430%u0437%u043E%u0432%u044B%u043C%u0438 ...

Parsing XML with SAX/Python + no validation

Hi all, Hi, I am new to python and I'm trying to parse a XML file with SAX without validating it. The head of my xml file is: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE n:document SYSTEM "schema.dtd"> <n:document.... and I've tried to parse it with python 2.5.2: from xml.sax import make_parser, handler import sys parser = mak...

Streaming the result of a command back to the browser using Twisted and Comet

I'm writing an application that streams the output (by this I mean both sys.stdout and sys.stderr) of a python script excited on the server, in real time to the browser. The users on the site will be allowed to select the script to run, excite and kill their chosen script, and change some parameters, so I will need a different thread p...

wiki/docbook/latex documentation template system

Hi. I'm searching for a documentation template system or rather will be creating one. It should support the following features: Create output in PDF and HTML Support for large & complicated (LaTeX) formulas References between documents Bibliographies Templates will be filled by a Python script I've tried LaTeX with various TeX-to-HTM...

sqlalchemy cascade and association objects

My database structure is something like this (I'm using declarative style): class Character(Base): __tablename__="characters" id = Column(Integer, primary_key=True) name = Column(String) player = Column(String) inventory = relation(Inventory) class Item(Base): __tablename__="items" id = Column(Integer, prima...

Why does it print funny characters? unicode problem?

The user entered the word éclair into the search box. Showing results 1 - 10 of about 140 for �air. Why does it show the weird question mark? I'm using Django to display it: Showing results 1 - 10 of about 140 for {{query|safe}} ...

How do i use Django and UTF-8 content-type for template?

When I do: return render_to_response() in Django. How do I set the content-type to UTF-8? So that everything displayed is UTF-8? ...

Determine where documents differ with Python

I have been using the Python difflib library to find where 2 documents differ. The Differ().compare() method does this, but it is very slow - atleast 100x slower for large HTML documents compared to the diff command. How can I efficiently determine where 2 documents differ in Python? (Ideally I am after the positions rather the actual t...

understanding while loop

Hi all, I am a newb in python, I can understand what does for loop do, but cant really understand while loop do, I knew it does repeat something while the condition is true, easy to say, but really hard to use as far as I think. say a example here: while 1: rate(100) #what does this rate(100) do? try: 'something' except: ...

Create single python executable module

Guys, I have much python code in modules which are resides in several python packages and now I need to create single python executable module or file which will include all these files, so it will be working on windows and on linux servers. What are possible solutions and how this can be done? ...

Calling a variable from another function Python

Hello, I am trying to call a variable for use in another function. The variable is only in the other function and not declared as a global variable. Does anyone know how to call the other variable. The code below shows the 'retval' variable being used but it is declared in the other function. def email_results(): if make.retval > ...

How do I add content before </body> in extended page? (KID templates)

I've got master.kid (simplified): <html> <head py:match="item.tag == 'head'"> <title>My Site</title> </head> <body py:match="item.tag == 'body'"> <h1>My Site</h1> <div py:replace="item[:]"></div> <p id="footer">Copyright Blixt 2010</p> </body> </html> And mypage.kid: <html> <head></head> <body> <p>Hello World!</p> </body> <...

How to move my cursor to the last record in MySQL using Python?

I'm using MySQLdb library to connect to MySQL within my Python script. (Ref: http://mysql-python.sourceforge.net/MySQLdb.html ). I would like to learn if there is a way to jump to the last record in a resultset using Python? In other words, I would like to move my cursor to the last record in the resultset. ...

Creating equivalent classes in Python?

I played around with overloading or masking classes in Python. Do the following code examples create equivalent classes? class CustASample(object): def __init__(self): self.__class__.__name__ = "Sample" def doSomething(self): dummy = 1 and class Sample(object): def doSomething(self): dummy = 1 ...

media conversion library

I am building a mobile website were users can upload/download videos and am looking for a library that can convert the media files from mpeg, 3gp, mov depending on what the user wants to download. thanks in advance. ...

Find the type of an attribute in a class

I want determine the type of an attribute in a class. I am using setattr to set the value, and I would like to check the type that is expected, so that I can properly convert a string value before calling setattr. How do you do this in python? EDIT 1- Some additional information based on the answers so far: I only know the name of th...