python-2.x
implement singleton with metaclass
the code below is how i implement singleton with metaclass, and it works well class Test_MetaClass(type):[详细]
2023-03-25 12:36 分类:问答list[-1] yields "list index out of range" error in python program
I\'m trying to build a markov generator that takes an arbitrary length for the chain of words as a programming exercise, but开发者_运维技巧 I\'ve found a bug I just can\'t quite seem to fix.When I run[详细]
2023-03-25 05:26 分类:问答Help me make my Python 2 code work in Python 3
import math,sys,time;i=0 while 1: sys.stdout.write(\"\\r\"+\':(__)\'[:3+int(round(math.sin(i)))]+\'n\'+\':(__)\'[3+int(round(math.sin(i))):]);sys.stdout.flush();time.sleep(.15);i+=0.5*math.p[详细]
2023-03-24 14:38 分类:问答Python old-style class __getattr__: "TypeError: 'NoneType' object is not callable"
I\'m implementing a simple class to represent a 2D vector. Here\'s are the relevant bits: class Vector:[详细]
2023-03-24 07:44 分类:问答What type of line breaks does a Python script normally have?
My boss keeps getting annoyed at me for having Windows line breaks in my Python scripts, but I can\'t for the life of me work out how they are causing him a problem.[详细]
2023-03-24 05:49 分类:问答Buffers and Memoryview Objects explained for the non-C programmer
Python 2.7 has introduced a new API f开发者_JS百科or buffers and memoryview objects. I read the documentation on them and I think I got the basic concept (accessing the internal data of an object in[详细]
2023-03-21 07:23 分类:问答Python name of class in class body
Is it possible to get the class name within the body of a class definition? For example, class Foo(): x = magic() # x should now be \'Foo\'[详细]
2023-03-21 02:04 分类:问答Detect charset and convert to utf-8 in Python? [duplicate]
This question already has answers here: How to determine the encoding of text 开发者_如何学C (16 answers)[详细]
2023-03-21 00:39 分类:问答Unicode literals that work in python 3 and 2
So I have a python script that I\'d prefer worked on python 3.2 a开发者_运维知识库nd 2.7 just for convenience.[详细]
2023-03-18 02:16 分类:问答How to find out the location of a doctest file when running nose?
I am using python nose to run a bunch of doctests in subdirectories. The calling script is nose.cmd: nosetests --with-doctest --doctest-extension=rst[详细]
2023-03-17 01:51 分类:问答