Re: get a line of text from a socket...

2006-08-31 Thread KraftDiner
Sybren Stuvel wrote: KraftDiner enlightened us with: What makes asyncore.loop exit? Why ask questions about something you're unable to use, when I've given you something that does work? Who said it didn't work? Sybren -- The problem with the world is stupidity. Not saying there should

Re: get a line of text from a socket...

2006-08-28 Thread KraftDiner
Bryan Olson wrote: KraftDiner wrote: Thanks I can't seem to get this example to do anything except sit there http://docs.python.org/lib/asyncore-example.html Yeah, the example code, by itself, will just sit there. As an example, it should probably include the calls to make it do

get a line of text from a socket...

2006-08-25 Thread KraftDiner
If you don't know how long your input data is going to be how can you at least treat it a text line at a time... like looking for new line in the data... Right now recv blocks. Yes I could do a select, but the examples seem a bit complicated for a simple line oriented input... --

Re: get a line of text from a socket...

2006-08-25 Thread KraftDiner
Marc 'BlackJack' Rintsch wrote: In [EMAIL PROTECTED], KraftDiner wrote: If you don't know how long your input data is going to be how can you at least treat it a text line at a time... like looking for new line in the data... Right now recv blocks. Yes I could do a select

array tofile to a socket?

2006-08-24 Thread KraftDiner
Can pythons array.tofile method be used for a TCP/IP Socket? ie can the socket be a file object? -- http://mail.python.org/mailman/listinfo/python-list

range of int() type.

2006-08-23 Thread KraftDiner
What is the range of a variable of type int() eg: i = int() print i.max() # 0x print i.min() # 0x is it a signed 16 bit or 32 bit or is it unsigned 16 or 32... I've noticed that it can be incremented into a new class of type long... --

Re: range of int() type.

2006-08-23 Thread KraftDiner
Simon Forman wrote: KraftDiner wrote: What is the range of a variable of type int() eg: i = int() print i.max() # 0x print i.min() # 0x is it a signed 16 bit or 32 bit or is it unsigned 16 or 32... I've noticed that it can be incremented into a new class

Re: range of int() type.

2006-08-23 Thread KraftDiner
Terry Reedy wrote: KraftDiner [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] So what type / class should one use to represent a 16 bit integers (signed or unsigned)? For most purposes, Python just has integers, with 'small' ones (depending on the machine) handled more

key not found in dictionary

2006-08-22 Thread KraftDiner
I have a dictionary and sometime the lookup fails... it seems to raise an exception when this happens. What should I do to fix/catch this problem? desc = self.numericDict[k][2] KeyError: 589824 This is the error that is being produced, because there is no key 589824. --

Type conversion?

2006-08-18 Thread KraftDiner
I have the following code... import array len32 = array.array('L') len16 = array.array('H') len32.append(0) len16.append(0) y = len32[0] print y.__class__ type 'long' z = len16[0] print z.__class__ type 'int' how can I change Zs type to long? Or how how can I change an arrays type? --

Re: Type conversion?

2006-08-18 Thread KraftDiner
Rob Cowie wrote: KraftDiner wrote: I have the following code... import array len32 = array.array('L') len16 = array.array('H') len32.append(0) len16.append(0) y = len32[0] print y.__class__ type 'long' z = len16[0] print z.__class__ type 'int' how can I change

modify element of a list.

2006-08-17 Thread KraftDiner
Hi I have a list of Ojbects... I want to change one of the objects in the list for a new object How do I replace an existing object with a new one and maintain the list order.. This is what I have... def setAttribute(self, desc, value): n = anObject(desc, value) for o in self.Objects:

Re: inheritance?

2006-08-16 Thread KraftDiner
Steven D'Aprano wrote: On Tue, 15 Aug 2006 19:35:11 -0700, KraftDiner wrote: I have two classes: class implicitClass: def __init__(self): def isIVR(self): #This is a class private method. The convention is to flag classes as private with a leading underscore: def _isIVR

Re: inheritance?

2006-08-16 Thread KraftDiner
Steven D'Aprano wrote: On Tue, 15 Aug 2006 19:35:11 -0700, KraftDiner wrote: I have two classes: class implicitClass: def __init__(self): def isIVR(self): #This is a class private method. The convention is to flag classes as private with a leading underscore: def _isIVR

trouble understanding inheritance...

2006-08-16 Thread KraftDiner
This is not working the way I think it should it would appear that fromfile and getName are calling the baseClass methods which are simple passes What have I done wrong? class baseClass: def __init__(self, type): if type == 'A': self =

Re: trouble understanding inheritance...

2006-08-16 Thread KraftDiner
Fredrik Lundh wrote: KraftDiner wrote: This is not working the way I think it should it would appear that fromfile and getName are calling the baseClass methods which are simple passes What have I done wrong? class baseClass: def __init__(self, type

Re: trouble understanding inheritance...

2006-08-16 Thread KraftDiner
Simon Forman wrote: KraftDiner wrote: Fredrik Lundh wrote: KraftDiner wrote: This is not working the way I think it should it would appear that fromfile and getName are calling the baseClass methods which are simple passes What have I done wrong? class

Re: trouble understanding inheritance...

2006-08-16 Thread KraftDiner
Simon Brunning wrote: On 16 Aug 2006 12:53:12 -0700, KraftDiner [EMAIL PROTECTED] wrote: I can see that this might work... c = [a, b] for c in [a,b]: c.getName() but when does baseClass ever get used? Why did i even have to define it? Well, quite. I agree... welll... quite

file object and eof

2006-08-15 Thread KraftDiner
I open a file in python by f = open('filename', mode='rb') how can I tell if I am at the end of file? f.eof() isn't implmented. How can I implement its functionallity? Thanks. B. -- http://mail.python.org/mailman/listinfo/python-list

How to tell machines endianism.

2006-08-15 Thread KraftDiner
How can you tell if the host processor is a big or little endian machine? -- http://mail.python.org/mailman/listinfo/python-list

Re: file object and eof

2006-08-15 Thread KraftDiner
Grant Edwards wrote: On 2006-08-15, KraftDiner [EMAIL PROTECTED] wrote: I open a file in python by f = open('filename', mode='rb') how can I tell if I am at the end of file? I don't believe you can unless you try to read from the file. f.eof() isn't implmented. How can I

include a python class in another python script.

2006-08-15 Thread KraftDiner
I have a class that is defined in a file called MyClass.py How do I use that class in another python script.. import MyClass ? (Does it need to be in a specific location?) -- http://mail.python.org/mailman/listinfo/python-list

Global Objects...

2006-08-15 Thread KraftDiner
I have a question.. myGlobalDictionary = dictionary() class someClass: def __init__(self): self.x = 0; def getValue(self, v) myGlobalDictionary.getVal(v) myGlobalDictionary doesn't seem to be visible to my someClass methods. Why? What should I do? --

inheritance?

2006-08-15 Thread KraftDiner
I have two classes: class implicitClass: def __init__(self): def isIVR(self): #This is a class private method. def fromfile(self, fileObj, byteOrder): def getVR(self): def getGroup(self): def getElement(self): def getSize(self): def getData(self): class explicitClass:

A little assistance with os.walk please.

2006-08-14 Thread KraftDiner
The os.walk function walks the operating systems directory tree. This seems to work, but I don't quite understand the tupple that is returned... Can someone explain please? for root, dirs, files in os.walk('/directory/'): print root # print dirs # print files --

Re: A little assistance with os.walk please.

2006-08-14 Thread KraftDiner
Larry Bates wrote: KraftDiner wrote: The os.walk function walks the operating systems directory tree. This seems to work, but I don't quite understand the tupple that is returned... Can someone explain please? for root, dirs, files in os.walk('/directory/'): print root

Re: A little assistance with os.walk please.

2006-08-14 Thread KraftDiner
Tim Chase wrote: 1) there seems to be an optional topdown flag. Is that passed to os.walk(path, topdownFlag) Yes. 2) I only want to process files that match *.txt for example... Does that mean I need to parse the list of files for the .txt extention or can I pass a wildcard in the

Recurse Directories and process files in directory

2006-08-12 Thread KraftDiner
Hi I need help writing a python script that traverses (recursivly) a directory and its sub directories and processes all files in the directory. So at each directory if there are files in it I must build a list of those files and process them by exectuing a system command (exec?) Can some one

Need help building boost python on mac os x.

2006-08-04 Thread KraftDiner
Could someone point me to step by step instructions on building boost python on mac os x? I have bjam running.. I have the boost source... but the tests are failing.. Probably something to do with environement variables... Anyone with time? -- http://mail.python.org/mailman/listinfo/python-list

Python and Boost.

2006-07-25 Thread KraftDiner
Hi, I'm trying to call a C++ class from python. I've looked around and the solution would appear to be boost. I'm not sure but maybe I've downloaded and installed the entire boost library, when there is probably a separate tar ball for python / C++ integration. Can someone please point me to a tar

Python and C++

2006-07-25 Thread KraftDiner
What ways can I call my C++ classes from within Python. I've looked at boost but it would appear that there is little support or knowledge on boost in the python community. -- http://mail.python.org/mailman/listinfo/python-list

reshape an array?

2006-03-08 Thread KraftDiner
I have a 2D array. Say it is 10x10 and I want a 1D Array of 100 elements... What is the syntax? oneD = reshape(twoD, (100,1)) or oneD = reshape(twoD, (1,100)) One I guess is the transpose of the other but both seem to be arrays of arrays... help?! --

a question about zip...

2006-03-08 Thread KraftDiner
I had a structure that looked like this ((0,1), (2, 3), (4, 5), (6,7) I changed my code slightly and now I do this: odd = (1,3,5,7) even = (0,2,4,6) all = zip(even, odd) however the zip produces: [(0, 1), (2, 3), (4, 5), (6, 7)] Which is a list of tuples.. I wanted a tuple of tuples... --

Re: reshape a list?

2006-03-07 Thread KraftDiner
I'm wondering if your solution fits my requirements I need to be able to pass these objects which are python lists to a pyObjC (on MAC OS X) framework. At the moment the framework is expecting NSArray or NSData as input and this works for 'generic' python lists I don't know about numpy

Reading binary from a file...

2006-03-07 Thread KraftDiner
Hi! In python I'm able to read in binary data from a file. data = file.read() # Reads in an entire file. However the data is 16bits per sample and python is storing the data in a string. How do I convert that 8bit data into a list of 16 bit integers? Note: I want generic python lists or tupels

Need help initializing a list or tuple.

2006-03-06 Thread KraftDiner
I need a matrix of 256 x 256 unsigned short values... The matrix can be implemented as a list of lists or a tuple... So for example: [[1][2][3], [4][5][6], [7][8][9]] or ((1,2,3),(4,5,6), (7,8,9)) This is what I have so far but its not working... a = [][] for i in range(0,256): for j in

Re: Need help initializing a list or tuple.

2006-03-06 Thread KraftDiner
Thank you that worked great! a = [[None] * 256] * 256 for i in range(0,256): for j in range(0,256): a[i][j] = i**2 Now.. Can I change this quickly into a 1 dimensional list of length 65536? -- http://mail.python.org/mailman/listinfo/python-list

Re: Need help initializing a list or tuple.

2006-03-06 Thread KraftDiner
Strange behaviour... a = [[None] * 256] * 256 for i in range(0,256): for j in range(0,256): a[i][j] = i**2 a = sum(a, []) print a[0] print a[65535] Prints: 65025 65025 -- http://mail.python.org/mailman/listinfo/python-list

Re: Need help initializing a list or tuple.

2006-03-06 Thread KraftDiner
Yes I missed the fine print that said that the code had 'side effects' So: a = [None]*256 for i in range(256): a[i] = [None] * 256 for i in range(0,256): for j in range(0,256): a[i][j] = i**2 a = sum(a, []) print a[0] print a[65535] --

Re: Need help initializing a list or tuple.

2006-03-06 Thread KraftDiner
Oh by the way the b = sum(a, []) worked well to convert the two dimensional array to a 1D array... Is there a way to bring that 1D array back to a 2D array? -- http://mail.python.org/mailman/listinfo/python-list

Re: Need help initializing a list or tuple.

2006-03-06 Thread KraftDiner
nope.. sorry its not... I meant x = [[1,2,3],[3,4,5],[5,6,7]] -- http://mail.python.org/mailman/listinfo/python-list

reshape a list?

2006-03-06 Thread KraftDiner
I have a list that starts out as a two dimensional list I convert it to a 1D list by: b = sum(a, []) any idea how I can take be and convert it back to a 2D list? -- http://mail.python.org/mailman/listinfo/python-list

nDimensional sparse histogram in python.

2006-02-01 Thread KraftDiner
Hi, I wrote a C++ class that implements an n dimensional histogram in C++, using stl maps and vectors. I want to code this up now in Python and would like some input from this group. The C++ class was VERY simple.. std::mapstd::vectorunsigned short, unsigned long histo; Say for example

Re: nDimensional sparse histogram in python.

2006-02-01 Thread KraftDiner
Cool. Ok so my histogram class had two methods 1) To increment a point and 2) to get the point. def class histo: def __init__(self): histo = {} def update(point): '''searches the dictionary for point and if it exists increment the value. if it doesn't exist set the value to 1'''

Re: nDimensional sparse histogram in python.

2006-02-01 Thread KraftDiner
The dictionary is sorted by the point key. Is there a way to sort the dictionary by the value? Seems to me this goes against the purpose of a dictionary but thats what I need to do.. -- http://mail.python.org/mailman/listinfo/python-list

Re: nDimensional sparse histogram in python.

2006-02-01 Thread KraftDiner
Ok so this is nice.. Just one thing.. When you try to get a value from a dictionary and it isn't found in the dictionary things go bad... Take this for example: class histogram(object): def __init__(self): self.histo = {} def update(self, point):

Re: nDimensional sparse histogram in python.

2006-02-01 Thread KraftDiner
Many thanks everyone. One last quick question... The dictionary, I believe, is sorted by the key. Is there a way to sort it by the value? Say I wanted to put out a list of the frequency sorted by highest to lowest? -- http://mail.python.org/mailman/listinfo/python-list

Inheritance problem?

2006-01-06 Thread KraftDiner
I have a class class MyClass(MyBaseClass) def __init__(self) super(self.__class__, self).__init__() self.type = MyClassType return self It has a few methods... I have another class and the only difference is the __init__ method.. I tried this: class MySpecialClass(MyClass)

Spelling mistakes!

2006-01-06 Thread KraftDiner
I've spent hours trying to find a bug that was a simple spelling mistake. in an init method I declare a variable self.someLongName later in a different method of the class I use self.sumLongName Now I really meant self.someLongName. In fact I don't want a variable called sumLongName. Frankly

Re: Spelling mistakes!

2006-01-06 Thread KraftDiner
try this: class x(object): def __init__(self): self.someName = hello def someMethod(self): self.sumName = bye find that bug. -- http://mail.python.org/mailman/listinfo/python-list

Copy an Object (Again?)

2006-01-06 Thread KraftDiner
I'm having trouble getting a copy of and object... (a deep copy) I'm writing a method that creates a mirror image of an object (on screen) In order to do this i need to get a copy of the object and then modify some of its attributes. I tried: objs = myListOfObjects for obj in objs: if

Re: Inheritance problem?

2006-01-06 Thread KraftDiner
So ok I've written a piece of code that demonstrates the problem. Can you suggest how I change the Square class init? class Shape(object): def __init__(self): print 'MyBaseClass __init__' class Rectangle(Shape): def __init__(self):

Is 'everything' a refrence or isn't it?

2006-01-04 Thread KraftDiner
I was under the assumption that everything in python was a refrence... so if I code this: lst = [1,2,3] for i in lst: if i==2: i = 4 print lst I though the contents of lst would be modified.. (After reading that 'everything' is a refrence.) so it seems that in order to do this I need to

Translate this to python?

2006-01-03 Thread KraftDiner
I'm porting a routing from C++ to python. There is a complex for loop that I don't know how to code in python for (i = nPoints-1, j = 0; j nPoints; i = j, j++) Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: Translate this to python?

2006-01-03 Thread KraftDiner
Thanks all! -- http://mail.python.org/mailman/listinfo/python-list

Simple question on Parameters...

2005-12-28 Thread KraftDiner
I have defined a method as follows: def renderABezierPath(self, path, closePath=True, r=1.0, g=1.0, b=1.0, a=1.0, fr=0.0, fg=0.0, fb=0.0, fa=.25): Now wouldn't it be simpler if it was: def renderABezierPath(self, path, closePath=True, outlineColor, fillColor): But how do you set default vaules

Re: Simple question on Parameters...

2005-12-28 Thread KraftDiner
I guess its all good... I just am not crazy about using fillColor[0] id rather use fillColor.r So is that a structure I need to define or a class... I'm kind of new to python what would that class or structure look like? and then do the default parameters still work? --

Re: Simple question on Parameters...

2005-12-28 Thread KraftDiner
NICE! :) -- http://mail.python.org/mailman/listinfo/python-list

Is this a refrence issue?

2005-12-28 Thread KraftDiner
I understand that everything in python is a refrence I have a small problem.. I have a list and want to make a copy of it and add an element to the end of the new list, but keep the original intact so: tmp = myList tmp.append(something) print tmp, myList should be different... --

zip unzip?

2005-12-28 Thread KraftDiner
I have two lists... a=[1,2,3] b=[4,5,6] n=0 for i in a: print i, b[n] n=n+1 how can i have two iterators on my for loop? rather than have to use the counter n? like: for i,j in a,b: print i, j Do you know what I mean? -- http://mail.python.org/mailman/listinfo/python-list

Re: What is unique about Python?

2005-12-23 Thread KraftDiner
I like python.. Its ok.. One thing that I find a bit dangerous it the use of the tab character for indentation.. I've had copy and pasts loose indentation on me and its theoretically impossible to really figure out what the indentation should be. I think for the extra effort it would have taken

A simple list question.

2005-12-22 Thread KraftDiner
Is there a cleaner way to implement this code? if len(self.listOfObjects) == 0: self.listOfObjects.append(self.currentObject) elif: self.listOfObjects[self.currentSlice] =

Re: A simple list question.

2005-12-22 Thread KraftDiner
I am trying to implement a two dimensional array. mylist = [[a,b,c],[d,e,f,c],[g,h,i]] So the array is of length 3 here... So how do I initialize this array and then set each object? At some point in my code I know there will be 3 lists in the list. So how do I initialize this list such that I

How do I sort these?

2005-10-28 Thread KraftDiner
I have two lists. I want to sort by a value in the first list and have the second list sorted as well... Any suggestions on how I should/could do this? -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I sort these?

2005-10-28 Thread KraftDiner
yes... Thats the idea... -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I sort these?

2005-10-28 Thread KraftDiner
In C++ you can specify a comparision method, how can I do this with python... Say for instance the first list was a dictionary and I wanted to sort on one of the keys in the dictionary? -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I sort these?

2005-10-28 Thread KraftDiner
unzip doesn't seem to work for me... -- http://mail.python.org/mailman/listinfo/python-list

Question about inheritance...

2005-10-22 Thread KraftDiner
I have a base class called Shape And then classes like Circle, Square, Triangle etc, that inherit from Shape: My quesiton is can a method of the Shape class call a method in Circle, or Square etc...? -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about inheritance...

2005-10-22 Thread KraftDiner
Well here is a rough sketch of my code... This is giving my two problems. 1) TypeError: super() argument 1 must be type, not classobj 2) I want to be sure the the draw code calls the inherited classes outline and not its own... class Shape: def __init__(self): pass

Re: Question about inheritance...

2005-10-22 Thread KraftDiner
This is what I've got so far: class Shape(object): def __init__(self): pass def render(self): print 'Shape render' self.outline() def outline(self): pass class Rect(Shape): def __init__(self):

Having trouble deleting objects from a list...

2005-10-19 Thread KraftDiner
I have a list, and within it, objects are marked for deletion. However when I iterate through the list to remove objects not all the marked objects are deleted.. here is a code portion: i = 0 for obj in self.objList:

destroy your self????

2005-10-19 Thread KraftDiner
if I create an object like... obj = None ... obj = anObject() can obj set itself to none in some method of the class? -- http://mail.python.org/mailman/listinfo/python-list

Re: destroy your self????

2005-10-19 Thread KraftDiner
Well I guess what I'm trying to achive is the invalidate the instance of the object. I have been using None to denote an invalide or uninitialized instance of an object. There is a degenerate case in my code where a polygon has less than 3 points and I want to class to flag this instance of the

Inheritance...

2005-10-14 Thread KraftDiner
I have a base class class geometry(object): def __init__(self): self.blue = 1 self.red = 2 def render(self): pass class square(geometry): def __init__(self): super(square, self).__init__() def render(self) print 'square' class circle(geometry):

Inheritance...

2005-10-14 Thread KraftDiner
I have a base class class geometry(object): def __init__(self): self.blue = 1 self.red = 2 def render(self): pass class square(geometry): def __init__(self): super(square, self).__init__() def render(self) print 'square' class circle(geometry):