python-2.6

UnicodeEncodeError: 'ascii' codec can't encode character?

南笙酒味 提交于 2020-01-29 05:30:41
问题 I'm trying to pass big strings of random html through regular expressions and my Python 2.6 script is choking on this: UnicodeEncodeError: 'ascii' codec can't encode character I traced it back to a trademark superscript on the end of this word: Protection™ -- I do not need to capture the non-ascii stuff, but it is a nuisance and I expect to encounter it more in the future. Is there a module to process non-ascii characters? or, what is the best way to handle/escape non-ascii stuff in python?

Using matplotlib (for python 2.6) with Abaqus 6.12

我与影子孤独终老i 提交于 2020-01-13 18:05:29
问题 I'm wondering if any of you use matplotlib for your python codes that are coupled with ABAQUS. I really want to load matplotlib onto the abaqus-python interface. I'm using ABAQUS 6.12, which has python 2.6. Also, I'm using Windows 64 bit. However, when I download the matplotlib for python 2.6, it fails to install and says that "Python 2.6 required, which is not found in the Registry." Could anyone help me out? Does anyone know of a step-by-step way to install matplotlib such that it works for

Installing MySQLdb for Django on Mac OS X 10.6 Snow Leopard with MAMP

♀尐吖头ヾ 提交于 2020-01-13 03:49:28
问题 So I know this is not a new topic, but its one that nobody has seemed to be able to solve, at least not for Python 2.6 / Snow Leopard. (The Leopard fixes I've found aren't applicable to Snow Leopard.) Situation: I'm trying to get Django installed locally on my Mac OS X Snow Leopard laptop. (10.6.7) I have Python 2.6.1, which is what came preinstalled with Snow Leopard, MySQL-python 1.2.3, and MAMP 1.9.6. All are latest current versions. Without making any changes to the MySQLdb package, if I

Handling large dense matrices in python

自作多情 提交于 2020-01-12 02:38:11
问题 Basically, what is the best way to go about storing and using dense matrices in python? I have a project that generates similarity metrics between every item in an array. Each item is a custom class, and stores a pointer to the other class and a number representing it's "closeness" to that class. Right now, it works brilliantly up to about ~8000 items, after which it fails with a out-of-memory error. Basically, if you assume that each comparison uses ~30 (seems accurate based on testing)

How do I prevent my Python application from automatically closing once reaching the end of code? [duplicate]

本秂侑毒 提交于 2020-01-11 09:45:09
问题 This question already has answers here : How to keep a Python script output window open? (20 answers) Closed 5 years ago . I'm new to programming, especially Python. I'm trying to make an application that converts Fahrenheit to Celsius, but I don't know how to make the program stay open. Whenever it reaches the end of the code, it automatically closes before the user can see his or her results. I'm using Python 2.6. 回答1: Well, I guess you mean the terminal that Windows opens for you when you

Self Modifying Python? How can I redirect all print statements within a function without touching sys.stdout?

核能气质少年 提交于 2020-01-06 21:06:17
问题 I have a situation where I am attempting to port some big, complex python routines to a threaded environment. I want to be able to, on a per-call basis, redirect the output from the function's print statement somewhere else (a logging.Logger to be specific). I really don't want to modify the source for the code I am compiling, because I need to maintain backwards compatibility with other software that calls these modules (which is single threaded, and captures output by simply grabbing

changing axis labels in excel 2007 charts using python win32com

和自甴很熟 提交于 2020-01-05 05:02:46
问题 I have an excel sheet with some data in first two columns. I created a simple chart with this data. I am facing problem in adding axis labels to the chart. here is my script from win32com.client import Dispatch, constants excel = win32com.client.Dispatch('Excel.Application') wb = excel.Workbooks.Open( 'output_data.xls', False, True) excel.Visible = False ws1 = wb.Worksheets('sheet_1) ch = ws1.Shapes.AddChart( 73, 200, 50, 800, 500).Select() excel.ActiveChart.ApplyLayout(1) excel.ActiveChart

Print current UTC datetime with special format

≯℡__Kan透↙ 提交于 2020-01-03 17:09:09
问题 Pretty simple, but I'm a python newbie. I'm trying to print the current UTC date AND time with special format: Python 2.6.6 import datetime, time print time.strftime("%a %b %d %H:%M:%S %Z %Y", datetime.datetime.utcnow()) TypeError: argument must be 9-item sequence, not datetime.datetime 回答1: time.strftime() only takes time.struct_time-like time tuples, not datetime objects. Use the datetime.strftime() method instead: >>> import datetime >>> datetime.datetime.utcnow().strftime("%a %b %d %H:%M:

Difference between int() and long()

被刻印的时光 ゝ 提交于 2020-01-03 13:43:30
问题 What is the difference between int(x) and long(x) in python My understanding: long() will always return a long int() will return an int or a long (if its too big) so int() is sufficient to dynamically get a int/long based on its value So unless above (1) (2) (3) are incorrect, why do you need long()? when int() gets the job done? skipping long() for all number ranges will hurt me? Documentation refered: class int(x=0) Return an integer object constructed from a number or string x, or return 0

Python Subprocess Call with variables [duplicate]

为君一笑 提交于 2020-01-02 08:08:26
问题 This question already has answers here : OSError: [Errno 2] No such file or directory while using python subprocess in Django (3 answers) Closed 4 years ago . I am currently writing a script for a customer. This script reads from a config file. Some of these infos are then stores in variables. Afterwards I want to use subprocess.call to execute a mount command So I am using these variables to build the mount command call("mount -t cifs //%s/%s %s -o username=%s" % (shareServer, cifsShare,