python-2.5

Python dictionary creation error

做~自己de王妃 提交于 2019-12-01 17:31:02
问题 I am trying to create a Python dictionary from a stored list. This first method works >>> myList = [] >>> myList.append('Prop1') >>> myList.append('Prop2') >>> myDict = dict([myList]) However, the following method does not work >>> myList2 = ['Prop1','Prop2','Prop3','Prop4'] >>> myDict2 = dict([myList2]) ValueError: dictionary update sequence element #0 has length 3; 2 is required So I am wondering why the first method using append works but the second method doesn't work? Is there a

What encoding do I need to display a GBP sign (pound sign) using python on cygwin in Windows XP?

不打扰是莪最后的温柔 提交于 2019-12-01 15:15:38
问题 I have a python (2.5.4) script which I run in cygwin (in a DOS box on Windows XP). I want to include a pound sign (£) in the output. If I do so, I get this error: SyntaxError: Non-ASCII character '\xa3' in file dbscan.py on line 253, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details OK. So I looked at that PEP, and now tried adding this to the beginning of my script: # coding=cp437 That stopped the error, but the output shows ú where it should show £. I've

Can I use Python 3 super() in Python 2.5.6?

坚强是说给别人听的谎言 提交于 2019-12-01 15:07:18
Can I use clean Python 3 super() syntax in Python 2.5.6? Maybe with some kind of __future__ import? donkopotamus You cannot use a bare super() call that contains no type/class. Nor can you implement a replacement for it that will work. Python 3.x contains special support to enable bare super() calls (it places a __class__ cell variable in all functions defined within a class - see PEP 3135 Update As of Python 2.6+, bare super() calls can be used via the future Python package. See posita's answer for an explanation. posita I realize this question is old, and the selected answer may have been

How to check class equality in Python 2.5?

余生颓废 提交于 2019-12-01 10:41:22
问题 I've looked through Python 2.5 documentation and I couldn't find an answer to this: How do I check if an object is the same class as another object? def IsClass(obj1, obj2): return obj1.class == obj2.class #doesn't work 回答1: You can use type(obj1) is type(obj2) Note that you usually try to avoid type checking in Python, but rather rely on duck typing. 回答2: I think what you want to do is use type(obj). :) -EDIT- Looks like he beat me to it. And he's right about the Duck Typing. 来源: https:/

Python 2.5 convert string to binary

两盒软妹~` 提交于 2019-11-30 23:09:27
I know this is easily possible in python 2.6. But what is the easiest way to do this in Python 2.5? x = "This is my string" b = to_bytes(x) # I could do this easily in 2.7 using bin/ord 3+ could use b"my string" print b Any suggestions? I want to take the x and turn it into 00100010010101000110100001101001011100110010000001101001011100110010000001101101011110010010000001110011011101000111001001101001011011100110011100100010 This one-line works: >>> ''.join(['%08d'%int(bin(ord(i))[2:]) for i in 'This is my string'])

Python 2.5 convert string to binary

让人想犯罪 __ 提交于 2019-11-30 18:10:56
问题 I know this is easily possible in python 2.6. But what is the easiest way to do this in Python 2.5? x = "This is my string" b = to_bytes(x) # I could do this easily in 2.7 using bin/ord 3+ could use b"my string" print b Any suggestions? I want to take the x and turn it into 00100010010101000110100001101001011100110010000001101001011100110010000001101101011110010010000001110011011101000111001001101001011011100110011100100010 回答1: This one-line works: >>> ''.join(['%08d'%int(bin(ord(i))[2:])

How to check if a string contains only characters from a given set in python

泄露秘密 提交于 2019-11-30 14:15:00
I have a a user-inputted polynomial and I only want to use it if it only has characters in the string 1234567890^-+x . How can I check if it does or not without using external packages? I only want to use built-in Python 2.5 functions. I am writing a program that runs on any Mac without needing external packages. Here are some odd ;-) ways to do it: good = set('1234567890^-+x') if set(input_string) <= good: # it's good else: # it's bad or if input_string.strip('1234567890^-+x'): # it's bad! else: # it's good Use a regular expression: import re if re.match('^[-0-9^+x]*$', text): # Valid input

Error importing a .pyd file (as a python module) from a .pyo file

末鹿安然 提交于 2019-11-30 08:29:01
I am running pygame (for Python) on Windows. I have some .pyo files and some .pyd files. I have another script for somewhere else that is trying to import one of the .pyd files as a module but I keep getting the error that no such module exists. Do .pyo files have issues importing .pyd files as modules? What can I do to solve this issue? It's typically because of one or more of the following: The .pyd is not in your current path (you said it was in the same folder so that should not be the problem) A DLL the .pyd depends on is not in your current path. Locate the missing DLL's using depends

Access to errno from Python?

╄→гoц情女王★ 提交于 2019-11-30 04:43:28
I am stuck with a fairly complex Python module that does not return useful error codes (it actually fails disturbingly silently). However, the underlying C library it calls sets errno. Normally errno comes in over OSError attributes, but since I don't have an exception, I can't get at it. Using ctypes, libc.errno doesn't work because errno is a macro in GNU libc. Python 2.6 has some affordances but Debian still uses Python 2.5. Inserting a C module into my pure Python program just to read errno disgusts me. Is there some way to access errno? A Linux-only solution is fine, since the library

Error importing a .pyd file (as a python module) from a .pyo file

人盡茶涼 提交于 2019-11-29 11:50:19
问题 I am running pygame (for Python) on Windows. I have some .pyo files and some .pyd files. I have another script for somewhere else that is trying to import one of the .pyd files as a module but I keep getting the error that no such module exists. Do .pyo files have issues importing .pyd files as modules? What can I do to solve this issue? 回答1: It's typically because of one or more of the following: The .pyd is not in your current path (you said it was in the same folder so that should not be