python-2.6

How to install python2.6-devel package under CentOs 5

五迷三道 提交于 2019-11-30 08:38:56
问题 I need to install mysql-python under python2.6. mysql-python package needs python2.6-devel package that depends on the libpython2.6.so.1.0(64bit) I found on the net some python2.6-devel packages, but can't find libpython2.6 Server architecture is x86_64. Maybe someone have this lib, or know where i can find it. Thanks for help) 回答1: I have the same issue and this wonderful link solved it for me... http://blog.milford.io/2010/08/new-method-for-installing-python-2-6-4-with-mysql-python-on

In a Python object, how can I see a list of properties that have been defined with the @property decorator?

假如想象 提交于 2019-11-30 08:27:07
I can see first-class member variables using self.__dict__ , but I'd like also to see a dictionary of properties, as defined with the @property decorator. How can I do this? You could add a function to your class that looks something like this: def properties(self): class_items = self.__class__.__dict__.iteritems() return dict((k, getattr(self, k)) for k, v in class_items if isinstance(v, property)) This looks for any properties in the class and then creates a dictionary with an entry for each property with the current instance's value. The properties are part of the class, not the instance.

Recursively convert python object graph to dictionary

╄→гoц情女王★ 提交于 2019-11-30 06:16:19
问题 I'm trying to convert the data from a simple object graph into a dictionary. I don't need type information or methods and I don't need to be able to convert it back to an object again. I found this question about creating a dictionary from an object's fields, but it doesn't do it recursively. Being relatively new to python, I'm concerned that my solution may be ugly, or unpythonic, or broken in some obscure way, or just plain old NIH. My first attempt appeared to work until I tried it with

Parse custom URIs with urlparse (Python)

旧街凉风 提交于 2019-11-30 04:59:50
My application creates custom URIs (or URLs?) to identify objects and resolve them. The problem is that Python's urlparse module refuses to parse unknown URL schemes like it parses http. If I do not adjust urlparse's uses_* lists I get this: >>> urlparse.urlparse("qqqq://base/id#hint") ('qqqq', '', '//base/id#hint', '', '', '') >>> urlparse.urlparse("http://base/id#hint") ('http', 'base', '/id', '', '', 'hint') Here is what I do, and I wonder if there is a better way to do it: import urlparse SCHEME = "qqqq" # One would hope that there was a better way to do this urlparse.uses_netloc.append

What difference between subprocess.call() and subprocess.Popen() makes PIPE less secure for the former?

别来无恙 提交于 2019-11-30 04:56:28
I've had a look at the documentation for both of them. This question is prompted by J.F.'s comment here: Retrieving the output of subprocess.call() The current Python documentation for subprocess.call() says the following about using PIPE for subprocess.call() : Note Do not use stdout=PIPE or stderr=PIPE with this function. The child process will block if it generates enough output to a pipe to fill up the OS pipe buffer as the pipes are not being read from. Python 2.7 subprocess.call() : Note Do not use stdout=PIPE or stderr=PIPE with this function as that can deadlock based on the child

How to stop Python parse_qs from parsing single values into lists?

空扰寡人 提交于 2019-11-30 03:07:34
In python 2.6, the following code: import urlparse qsdata = "test=test&test2=test2&test2=test3" qs = urlparse.parse_qs(qsdata) print qs Gives the following output: {'test': ['test'], 'test2': ['test2', 'test3']} Which means that even though there is only one value for test, it is still being parsed into a list. Is there a way to ensure that if there's only one value, it is not parsed into a list, so that the result would look like this? {'test': 'test', 'test2': ['test2', 'test3']} You could fix it afterwards... import urlparse qsdata = "test=test&test2=test2&test2=test3" qs = dict( (k, v if

Python os.stat(file_name).st_size versus os.path.getsize(file_name)

大城市里の小女人 提交于 2019-11-30 03:00:12
问题 I've got two pieces of code that are both meant to do the same thing -- sit in a loop until a file is done being written to. They are both mainly used for files coming in via FTP/SCP. One version of the code does it using os.stat()[stat.ST_SIZE] : size1,size2 = 1,0 while size1 != size2: size1 = os.stat(file_name)[stat.ST_SIZE] time.sleep(300) size2 = os.stat(file_name)[stat.ST_SIZE] Another version does it with os.path.getsize() : size1,size2 = 0,0 while True: size2 = os.path.getsize(file

Extract time from datetime and determine if time (not date) falls within range?

落爺英雄遲暮 提交于 2019-11-30 00:37:56
问题 The problem is that I want it to ignore the date and only factor in the time. Here is what I have: import time from time import mktime from datetime import datetime def getTimeCat(Datetime): # extract time categories str_time = datetime.strptime(Datetime, "%m/%j/%y %H:%M") ts = datetime.fromtimestamp(mktime(str_time)) # --> Morning = 0400-1000 mornStart = datetime.time(4, 0, 1) mornEnd = datetime.time(10, 0, 0) # --> Midday = 1000-1600 midStart = datetime.time(10, 0, 1) midEnd = datetime.time

pyodbc insert into sql

假如想象 提交于 2019-11-29 23:56:49
I use a MS SQL express db. I can connect and fetch data. But inserting data does not work: cursor.execute("insert into [mydb].[dbo].[ConvertToolLog] ([Message]) values('test')") I get no error but nothing is inserted into the table. Directly after I fetch the data the inserted row is fetched. But nothing is saved. In MS SQL Server Management Studio the insertion does work. You need to commit the data. Each SQL command is in a transaction and the transaction must be committed to write the transaction to the SQL Server so that it can be read by other SQL commands. Under MS SQL Server Management

Is there a way to perform “if” in python's lambda

烂漫一生 提交于 2019-11-29 18:33:26
In python 2.6 , I want to do: f = lambda x: if x==2 print x else raise Exception() f(2) #should print "2" f(3) #should throw an exception This clearly isn't the syntax. Is it possible to perform an if in lambda and if so how to do it? thanks The syntax you're looking for: lambda x: True if x % 2 == 0 else False But you can't use print or raise in a lambda. why don't you just define a function? def f(x): if x == 2: print(x) else: raise ValueError there really is no justification to use lambda in this case. You can easily raise an exception in a lambda, if that's what you really want to do. def