Re: Getting the "dir" from the other ancestor ?
On 28 Apr, 15:01, Stef Mientki wrote: > hello, > > I have a class, derived from some user defined class > (User_Defined_Ancestor) and some basic class (Basic_Ancestor). > > One of the major tasks of the Basic_Ancestor, > is to hide all kinds of implementation details for the user, > so the user can concentrate on the functional design. > > One of things I need to know are the methods and attributes of the > Basic_Ancestor. > Both classes are dynamic, i.e. attributes are added during run time. > > class Master ( User_Defined_Ancestor, Basic_Ancestor ) : > def __init__ ( self, *args, **kwargs ) : > Basic_Ancestor.__init__ ( self, *args, **kwargs ) > . > > class Basic_Ancestor ( object ) : > def __init__ ( self, ) : > self.other = dir ( User_Defined_Ancestor ) > > def Get_Attributes ( self ) : > return dir ( self ) - dir ( self.other ) > > Now the problem is, I don't know "User_Defined_Ancestor" in Basic_Ancestor. > I can't pass it through the parameter list, because I use "*args, **kwargs" > I possibly could use some global variable, but that's not my preference. > > Any other suggestions ? > > thanks, > Stef Mientki In anytime, if you do dir() in a class B, that extends a class A, you have all fields of A also. Example: >>> class A: ...def a(self): ...return 0 >>> class B(A): ...def b(self): ...return 5 >>> dir(A) [., 'a'] >>> dir(B) [.., 'a', 'b'] Hi. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to locate the bit in bits string?
On 28 Apr, 16:36, Li Wang wrote: > Hi: > > If I use an integer to represent bits: > e.g. 99 represents '1100011' > > How can I locate, say the second bit of 99(i.e. '1')? > > Although bin(99)[4] could be used to locate it, this transform cost > too much memory (99 only needs 2Bytes, while string '1100011' needs > 7Bytes). > > Anyone knows how to locate the second bit without using bin() function? > > Thank you very much:D > > -- > Li > -- > Time is all we have > and you may find one day > you have less than you think If we consider 8 bit, a solution may be the follow: >>> a = 99 # bin(a) = 0b1100011 >>> 0b1101 & a 97 >>> 0b1110 & a 99 as you view, you set the nth bit to 0, and view if the result is same as 'a'. If is same then the nth bit doesn't set. If you write the above code in a loop, you can test which bit you want. Hi. -- http://mail.python.org/mailman/listinfo/python-list
Re: Third Party Modules
On 28 Apr, 17:02, Brock wrote: > Hi Everyone, > > I know this is most likely a basic question and you will roll your > eyes, but I am just starting out with Python (hobbyist) and I see many > tutorials on the web referring to the use of external modules. > > However, when I locate them, they often come as a zipped folder with a > number of files. How do I install them? In addition, is there an > easy way to manage external modules? Some I see require additional > modules not included. > > Where I am coming from is R, which has a point-and-click way of > getting packages not distributed with the version of the software, so > that is my point of reference. > > Many thanks! > > - Brock If you are on Unix-like machine, unzip the archive in a some directory, do cd into the new directory and, from command line, do: python ./setup.py build (verify there is the script setup.py), and then python ./setup.py install (with root's permissions). On Win32 usually there are an automatic installer. Hi. -- http://mail.python.org/mailman/listinfo/python-list
Re: What do you think of ShowMeDo
On 28 Apr, 17:09, Astley Le Jasper wrote: > Hi, > > I've just stumbled over this (http://showmedo.com/) and being the very > visual person I am, it seems like it could be a good way to learn > about python. However, before I smack down $60, I wondered if anyone > had any opinions on it. My gut feel is that it could be pretty good. > > ALJ It can be useful, but there are many free howtos and tutorial ... and the programming can't be learned with video, but with books! Hi. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to locate the bit in bits string?
On 28 Apr, 17:24, Li Wang wrote: > 2009/4/29 Tim Chase : > > > Li Wang wrote: > > >> Hi: > > >> If I use an integer to represent bits: > >> e.g. 99 represents '1100011' > > >> How can I locate, say the second bit of 99(i.e. '1')? > > >> Although bin(99)[4] could be used to locate it, this transform cost > >> too much memory (99 only needs 2Bytes, while string '1100011' needs > >> 7Bytes). > > >> Anyone knows how to locate the second bit without using bin() function? > > > You mean > > > def get_bit(number, bit): > > return (number >> bit) & 1 > > > ? > > Hummm, I have tried this method too, the problem is its time > complexity. If the length of my bits is n, then the time complexity is > O(n). When I tried to implement this in practice, it did consume a lot > of time. > > So do you know how could I locate the bit in O(1) time? Transform it > into a string is a method, but takes too much space (when I try to > process a 2M file, it used more than 100M memory.). > > Thank you very much. > > > -tkc > > -- > Li > -- > Time is all we have > and you may find one day > you have less than you think The my solution is good, but the Tim's solution is better, and it is O (1) in time and space. What is you search? I dont'know you general problem, but search the value of a bit in a 2M file ... is strange . Hi. -- http://mail.python.org/mailman/listinfo/python-list
A question of style .....
If I have to write an extension module with many objects, how can I organizing the code? I think: every object in a separate file, and a last file with the PyInit_. function. But is unmenageable . Solutions? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
