python

Next question about russian encoding, mssql and python.

Next question about russian encoding, mssql and python. I have this simple code: import pymssql import codecs conn=pymssql.connect(host='localhost:1433', user='sa', password='password', database='TvPgms') cur = conn.cursor() cur.execute('SELECT TOP 5 CAST( Name AS nvarchar(400) ), CONVERT(nvarchar(400), idProgram) FROM dbo.Programs') ...

How to remove values from item list.

Hi, I am new to python. I have a item list looks like this: rank_item = [ (9, 0.99999999745996648), (8, 0.99999996796861101), (1, 0.99999996796861101), (10, 0.0) ] The question is how do i remove the item list with value 0.0 and return [(9, 0.99999999745996648), (8, 0.99999996796861101), (1, 0.99999996796861101)]...

How to synchronize the output of Python subprocess

Hi all, I think I'm having issues to synchronize the output of two Popen running concurrently. It seems that the output from these two different command lines are interleaved with one another. I also tried using RLock to prevent this from happening but it didn't work. A sample output would be: cmd1 cmd1 cmd2 cmd2 cmd2 cmd2 cmd1 cmd2 ...

How do I compare Rpm versions in python

I'm trying to find out how I can compare 2 lists of RPMS (Currently installed) and (Available in local repository) and see which RPMS are out of date. I've been tinkering with regex but there are so many different naming standards for RPMS that i can't get a good list to work with. I don't have the actual RPMS on my drive so i can't do r...

matplotlib. How do I switch between subplots, rather than replotting them from scratch?

I create a figure and fill it with a couple of subplots. As new data arrives, I'd like to draw it on a given subplot. How do I switch between subplots so that I don't have to create new subplot objects each time? Example: from matplotlib.pyplot import figure, figure() subplot(2,1,1) subplot(2,1,2) # now go back and plot something o...

Passing html to template

I'm building an admin for Flask and SQLAlchemy, and I want to pass the html for the different inputs to my view using render_template. The templating framework seems to escape the html automatically, so all <"'> are converted to html entities. How can I disable that so that the html renders correctly? ...

Email to HTML in Python

I am looking for a library which can take a raw email message and convert it to appropriate html in python. help will be appreciated ...

Semantics of python loops and strings

Consider: args = ['-sdfkj'] print args for arg in args: print arg.replace("-", '') arg = arg.replace("-", '') print args This yields: ['-sdfkj'] sdfkj ['-sdfkj'] Where I expected it to be ['sdfkj']. Is arg in the loop a copy? It behaves as if it is a copy (or perhaps an immutable thingie, but then I expect an error would ...

Python library for rich html text rendering

I am looking for a library which can create rich html (appropriately colored text etc.) in python idea would be invoke the library with inputs like renderRich(code_snippet) and the output will be a colored output in html like we get in rich text editors like vim ...

Cannot concatenate 'str' and 'list' objects

Hello - I'm getting a TypeError: cannot concatenate 'str' and 'list' objects. I'm trying to pass an object from a list to create a new variable by concatenating it with another variable. Example: I want to take the value from the group list and concatenate it with "All.dbf" so it will do something with that file for each value in my li...

Sending data through a socket from another thread does not work in Python

This is my 'game server'. It's nothing serious, I thought this was a nice way of learning a few things about python and sockets. First the server class initialized the server. Then, when someone connects, we create a client thread. In this thread we continually listen on our socket. Once a certain command comes in (I12345001001, for ex...

DTML: How to prevent formatting loss

I have a DTML document which only contains: <dtml-var public_blast_results> and displays when i view it as: YP_001336283 100.00 345 0 0 23 367 23 367 0.0 688 When I edit the DTML page for example just adding a header like: <h3>Header</h3> <dtml-var public_blast_results> The "public_blast_results"...

Using Python to scrape DataSet and Query data from RDL

I set out today with the intent to parse an SSRS RDL file (XML) using Python in order to gather the DataSet and Query data. A recent project has me back tracking on a variety of reports and data sources with the intention of consolidating and cleaning up what we have published. I was able to use this script to create a CSV file with th...

Detect Caps Lock in Python curses

For such a basic question, I'm surprised I couldn't find anything by searching... Anyways, I made a curses app in Python that assists in solving puzzles of a certain DSiWare game. With it, you can take a puzzle and inspect the components of it individually. The keys qweasdzx are used to paint tiles (the keys are arranged in some sort ...

how do i set my python path for success with my import statements?

I'm trying to install djangobb and when running manage.py syncdb it returns with Traceback (most recent call last): File "manage.py", line 2, in <module> from django.core.management import execute_manage ImportError: No module named django.core.management I know that deep in my python installation there is django/core/managemen...

How to check if a library is 32bit/64bit built on Mac OS X?

I'm having some trouble in using PyQt/SIP. I guess the SIP is compiled into 64bit, but Python has some problem with finding it. File "qtdemo.py", line 46, in import sip ImportError: dlopen(/Library/Python/2.6/site-packages/sip.so, 2): no suitable image found. Did find: /Library/Python/2.6/site-packages/sip.so: mach-o,...

how to list all files of a directory in python

how to list all files of a directory in python, and add it to a list? ...

Caching the results of a function with two parameters in Python

I have a method with two parameters that does some complex computation. It is called very often with the same parameters, so I am using a dictionary for caching. Currently this looks something like this: def foo(self, a, b): params = frozenset([a, b]) if not params in self._cache: self._cache[params] = self._calculate(a,...

How to force using 64 bit python on Mac OS X?

I got the following error when compiling sip with --arch x86_64 option. prosseek:siplib smcho$ python -c 'import sip; print sip' Traceback (most recent call last): File "", line 1, in ImportError: dlopen(./sip.so, 2): no suitable image found. Did find: ./sip.so: mach-o, but wrong architecture I found that the prebuilt Ma...

"self" inside plain function?

I've got a bunch of functions (outside of any class) where I've set attributes on them, like funcname.fields = 'xxx'. I was hoping I could then access these variables from inside the function with self.fields, but of course it tells me: global name 'self' is not defined So... what can I do? Is there some magic variable I can access...