CRC16
Anyone know a module that does CRC16 for Python? I have an aplication that I need to run it, and am not having alot of sucess. I have a program in C that uses a CRC16 according to CCITT standards, but need to get a program that tests it with python as well. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: CRC16
I should probably have mentioned that my code is just 6 bytes long, we send an 8 byte data packet with 2 bytes CRC. There's a CRC poly of 0x1021. Still having a bit of problems, but it's coming, thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
The ^ operator
What exactly does the ^ operator do? I've seen, for example, that 3^4=7, 3^5=8. but 3^3=0. Is it just adding them together if they are not equal, and if they are equal, outputs 0, or what? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: The ^ operator
Thanks alot! That sure makes lots of sense! -- http://mail.python.org/mailman/listinfo/python-list
ASCII
Is there a function that will take a char. and return the ascii value? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: ASCII
Thanks alot! -- http://mail.python.org/mailman/listinfo/python-list
Extending Python
I am looking for a good tutorial on how to extend python with C code. I have an application built in C that I need to be able to use in Python. I have searched through various sources, starting of course with the Python site itself, and others, but I felt a bit lacking from the Python site, it seems it was only made for those who installed the source distribution, as for the other people... Anyways, thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
Re: Extending Python
Perhaps it would be nice if they could include in the python documents a link to download a sample code, the one that they were building in the whole program, or at least a page that puts it all together? I get a much better idea of how thing work when they are all put together personally, and then explained individually. That would be the simpliest thing that would help, and perhaps the files that are included in the source distribution. Perhaps I might be the only python user that didn't install the source code that wants to use extended C applications, but I doubt it. Thanks for all of the help! -- http://mail.python.org/mailman/listinfo/python-list
Library functions
I am writing a program that mimics a program written in C, but using Python-supiorior techniques. The C program calles a library function, non-open source, I only know that it sends it a command LINUX_CAN_Open() as for a few others as well. Is there a way I can call this function from Python without opening the code, as the library is not open sourced (I know, a rarity with Linux libraries, but, well, it appears not to be...)? Perhaps write a C function that acts as a wrapper, is there a way to do it directly? Any help is much appreciated! Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Library functions
How exactly do you do that? Just to get some kind of an idea, perhaps you could share bits of code? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Mutual module imports
The trick is via something called Extending. Pyrex just makes extending a bit easier, but, depending on the complexity of the function, it might be easier just to extend it yourself. Basically you make a function that translates python into C. There are some instructions on the Python website, http://www.python.org . Look around, and you'll find lots of cool stuff on it. -- http://mail.python.org/mailman/listinfo/python-list
Extention Module/ list of chars-> string
I am currently writing an extention module that needs to recieve a list of characters that might vary in size from 0 to 8. This is written as a list of characters rather than a string because it's easier to manipulate. However, when I pass this list of characters into the extention module, it keeps giving errors. Is there a way to do one of the following? A. Change a list of chars to a single string or B. Read a list of chars in an extention module Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Extention Woes
I am in the process of writing an extention module, and am coming up with lots of problems. Perhaps someone could be of use. I keep getting data that isn't what I'm sending the program. Let me give the line of C code and Python Code and output to illistrate the problem. write_can(can_han,0x0140,'abcd') if (PyArg_ParseTuple(args("iiz#",&can_han,&com,&data,&len) return NULL; Okay, so I put in a print statement to print out the variables can_han, com, data, and length. The results were more or less this (I don't have copy/paste at the moment, so... 1357 com->0 len->4 str->,/p. Anways, the variable can_han was correct, the length is correct, but the com and the string are garbage. Any ideas as to why this may be? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Extention Woes
I tried Ctypes, but it was giving me tons of problems in the install phase, and so I decided it'd just be better to use an extention module. It's the type of stuff that could be perfectly done with ctypes, but... Oh well. Also, I've done all but this last little piece with extentions, might as well finish it. Exact stuff. C Code (Just parsing and printing) if(!PyArg_ParseTuple(args,"iiz#",&can_han,&com,&dat,&len)) return NULL;//This command will translate python data to C data printf("%i com->%i len->%i string->%s\n",can_han,com,len,dat); Python (Just command to this function) print write_can(can_han,0x0140,'abcd') Output 135769704 com->0 len->4 string->t=Ø· Output expected values for length and the number, not for the string nor com. Ideas? -- http://mail.python.org/mailman/listinfo/python-list
Re: Extention Woes
Forgot, var declartions int can_han; int com; char len; char dat[8]; -- http://mail.python.org/mailman/listinfo/python-list
Re: Extention Woes
Well, the point of declaring it as a char was to have it as an 8 bit integer, as is requested later on in the program. Anyways, I tried making the changes, similar results. The len value was always right, the problem seems to be in this com value. BTW, it doesn't give me one single warning, so I don't think it's a casting problem... I did a full check, and this can_han variable is right. Hmmm... Other ideas? -- http://mail.python.org/mailman/listinfo/python-list
Re: Extention Module/ list of chars-> string
Thanks for the help, I actually ended up writing my own simple charlist2string function, I realized it was only about 4 lines of code, but, appreciate the help! -- http://mail.python.org/mailman/listinfo/python-list
Re: Extention Woes
Never mind, problem solved. The other problem I was having was I forgot to put the .so at the end of a file, so it didn't change anything. Thanks for all of the help! -- http://mail.python.org/mailman/listinfo/python-list
Extention String returning
I have been writing a program that is designed to return an 8 byte string from C to Python. Occasionally one or more of these bytes will be null, but the size of it will always be known. How can I write an extention module that will return the correct bytes, and not just until the null? I would think there would be a fairly easy way to do this, but, well... Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Extention String returning
Thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
Jpg
I am building a GUI interface at the moment, and would like to have support for displaying a jpg file, and a FITS file if possible. Is there any way to do this? My interface has been written in Tkinter at the moment, especially because of it's great portability, I wouldn't have to install the other interface software on every computer that I use (At the moment it is 3, and will signifigantly increase). I'd prefer to only use built-in functions, but if it can't be done, I'm willing to look for something else. Is there any way I can do this? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Tkinter Frame Size
I'm tyring to set the size of the window that is opened when you open a Tkinter window, without much sucess. I have tried changing the heigth and width atributes, but it doesn't do anything. I tried using the grid_propagate command that I saw to use, but made the window even smaller... What can I do? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter Frame Size
Okay. I have alot of items that are put on the basic frame already, using a grid method. Will this change anything? -- http://mail.python.org/mailman/listinfo/python-list
Threading
I am trying to write a thread that will execute a function every 2 seconds until the program is close, in which case it will stop. I can write the program easy enough to execute the command every 2 seconds, the problem comes when I try to close the program. It won't close the thread. Any ideas as to what I can do? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Threading
That helps alot with the Daemon and recipe! Thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
Threading-> Stopping
Is there a way to stop a thread with some command like t.stop()? Or any other neat way to get around it? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Threading-> Stopping
Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Tkinter- checkbutton
I want to have a checkbutton that when it is pushed will do a function depending on if it was pushed before or not. Ei: b=checkbutton(command=check) b.grid(row=0,column=0) def check(): if (b.value==0): do_stuff_here() elif(b.value==1) do_other_stuff_here() However, I keep running into problems with reading the data. How do I make this work? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter- checkbutton
Ere, ignore the mis-capped Checkbutton and the missed master call in it... -- http://mail.python.org/mailman/listinfo/python-list
Tkinter- New Window
Is there a way to make a new window pop up using Tkinter? I have some functions that require more data in my interface than I have space for, and would like to be able to pop up a new window to request this information. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter- New Window
Okay, never mind about my first question, I got that answer by using Toplevel. However, there' s still a question to be answered. I popped up this new window with the intent to have something like this: "what is your question" Ei, there's a question popped up, a label that gathers information, and a button that will close it. However, I can't get the button to close it, it keeps saying that the variable isn't defined. I haven't even tried to get it to read the value of the label, but I think that it will be a similar type problem. Any nice ways around this problem? I do want these values only to be called when the function is called. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter- checkbutton
That solved the problem. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Tkinter- Building a message box
I've been trying to build a fairly simple message box in tkinter, that when a button is pushed, will pop up a box, that has a line of text, an entry widget, and a button, that when the button is pushed, will return the value in the line of text. However, while I can read the value of the button, I want to wait till the button is pushed to return the value. Any ideas of how I could do this? -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter- Building a message box
Do you have any info on dialogs? I've been trying to find some, without alot of success... -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter- Building a message box
Thanks alot, that helped TONS! Just had to modify it slightly, but, well, it works great now. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
PIL-> Tkinter
Is there a way to put an image loaded from PIL into a TKinter GUI? Without converting the image to a .bmp, and using a canvas? If that's the only way it'll work, I'll take it, but... It would be nice otherwise... -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL-> Tkinter
That would be extremely useful.Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Floating numbers and str
I would like to limit a floating variable to 4 signifigant digits, when running thorugh a str command. Ei, x=.13241414515 y=str(x)+" something here" But somehow limiting that to 4 sign. digits. I know that if you use the print statement, you can do something like %.4d, but how can I do this with converting the number to a string? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Floating numbers and str
Yep, I was thinking in C, not python. Thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
Re: Floating numbers and str
Wait, one more question. If the number is something like: 1.32042 It is like "1.32 stuff" I would like it's size to remain constant. Any way around this? -- http://mail.python.org/mailman/listinfo/python-list
LARGE numbers
I've been thinking about writing a program to generate the world's largest prime numbers, just for the fun of it. This would require being able to hold an 800 digit number into memory (25 megabits, or a little over 3 megs of memory for just one variable...) I would also need several smaller variables. This came about as I optimised a prime number generator more and more, until I came with the idea to try to find the largest ever, using python. Any ideas? I'll probably try to run this on a mainframe eventually, although they might not like it very much... I'll run it on my home computer to first test it. Anyways, let me know if there's a way to make python support numbers so high. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
PIL- error message- cannot open libtiff.so.3
Okay, so I've been getting this error message when trying to use PIL to open a JPEG, that there isn't a library by the name of libtiff.so.3 . I've been searching the documentation, there isn't any reference to this library. Also, I don't know why it's doing this as I'm trying to open a JPEG, and not a tiff. I tried with a .bmp with similar results. Any ideas? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: LARGE numbers
Well, as I'll be doing lots of multiplication, guess that GMPY is the way to go. I'll use DecInt only for converting to strings if I find anything interesting. This is all just kind of a theoretical aproach, but, it can be lots of fun. Who knows if Python'll help find the largest prime number ever? That would sure be cool. Thanks for all of your help. -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL- error message- cannot open libtiff.so.3
I got it from the PIL website, version 1.1.5. I guess it's possible that there's another library Image on the computer that it could be confusing? I'm looking for new things. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL- error message- cannot open libtiff.so.3
Oddly enough, that seems to have solved the problem. Duh. Take the simple solution first. Thanks for the wake up call! -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL- error message- cannot open libtiff.so.3
Well, it seems to have resolved the problem. Don't know what was causing it to begin with, but I'll take it... -- http://mail.python.org/mailman/listinfo/python-list
Tkinter Images
I've been trying to use a canvas to display different pictures on a Tkinter interface. However, it doesn't seem to update the information. Ei, I have something like this. canvas=Canvas(master,blah...) canvas.pack() def change_pic(path): global pic image=Image() #I'm using PIL to use the images, but I don't think it's depended... This code's not the important one... canvas.create_image(1,1,image=image, anchor=NW) change_pic("test1.jpg") I have written a simple scipt that just displays an image, without any problems. However, when I try to change the image dynamically, it doesn't work. If needed I can put the real code, however, it's a bit complicated to do so, this computer doesn't support copying from the terminal to the web browser. Thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter Images
Update: I can put the image in, but it spits out errors, adding this to it: canvas.insert(pic) BTW, I noted that my code was written incorectly The function should be as follows: def change_pic(path): global pic image=Image() #I'm using PIL to use the images, but I don't think it's depended... This code's not the important one... pic=canvas.create_image(1,1,image=image, anchor=NW) Note, add the first line above and it works. The question, how do I get it to work without the error messages? -- http://mail.python.org/mailman/listinfo/python-list
Quene
I am trying to write a function that holds a variable-length quene. The quene has 2 bits of information. At some point, I would like to remove bits of this quene, when they are completed. Is there a way to do this with something as follows? quene=[] quene.append((4,2)) quene.append((3,6)) if(4 in quene):#Shows false, what's the correct syntax to show true? remove 4 from quene #(Not python code, not sure how to do this...) So, how can I make this work? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: My Python Website
Thanks for the suggestions, I've put them on the page already. I used .zips so as not to confuse anyone that it's some kind of a file, but, I have used the formentioned sourcecode 2 HTML colorizer to put up nice web previews, as well as commenting the code a bit more. Thanks for your help! -- http://mail.python.org/mailman/listinfo/python-list
Python GUIs
I have a program that I am devoloping, that uses python as a GUI interface for a camera that we am building. Our camera is controlled using an 8 byte control squence, depending on the command, will have several configurations for each byte. I need to be able to have some way to manage all 8 bytes without interferance with the other. As the commands we have developed are in hex, that would make life even easier if I can somehow controll them using hex. The output is in a similar manner. Any help that you could give me on how to go about doing this would be greatly appreciated. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Python GUIs
As a bit more of an update, I have decided to create a list of strings, but am having a problem. To illistrate this in a simple manner. B='\x12','\x32' B[0]='\x12' I cannot get this to work, and I need to get it to work somehow. How can I make it happen? Is there a function that I should use, a special trick, etc? Or is there just no way to make it work? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Python GUIs
Thank you very much! That managed to fix the problem! -- http://mail.python.org/mailman/listinfo/python-list
IsString
I need a function that will tell if a given variable is a character or a number. Is there a way to do this? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: IsString
LOL. As to me being a newbie to programming, well, I've been programming to some extent for the last 10 years, although never professionally. The first few questions were enough to help me solve the problem that I had. And I've been programming Python for 4 months or so, but it's been pretty intense, my current code is about 1000 lines or so for the program that I am doing. The reason I had this need is basically trying to correct a mistake that I had made, sometime I passed a function characters, other times I passed it numbers, and I needed to have one uniform system. But, after a while, I found that I really didn't need this uniformed system, so I was alright. But, thanks for all of our help! -- http://mail.python.org/mailman/listinfo/python-list
Re: IsString
I don't know if I can help with this much, I'm still somewhat new to python, but it is my understanding that "simple" variable, ei, strings, ints, etc, although they don't have such names, behave like variables, ei, if you pass them to a function, the function will copy them into a new spot. However, if you use lists, then it only passes a pointer, or tuples as well. Ei, I just ran this through the python IDE. >>> x="Test" >>> def modstring(var): var="Blah" >>> modstring(x) >>> print x Test This seems to indicate that the variable is copied, as the value didn't change. Weither or not Python keeps the variables as pointers internally, it doesn't really matter. Actually, all languages do such things, except assembly. I just ran the test on lists and tuples, it was the same results, nothing moved. Other than this, I basically see a fight on terminology, and that's that. -- http://mail.python.org/mailman/listinfo/python-list
Tuples
Let's say I make a program something like follows: x=[] x.append([1,2,3]) x.append([4,5,6]) print x print x[0] print x[0][1] x[0][1]=5 Okay, everything works here as expected except the last line. Why won't this work? Thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
Re: Tuples
Never mind, I just realized that my code was actually a list inside of a tuple, and not a tuple inside of a tuple, thus giving the confusion that it had. Thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
Browse type function
I am building a GUI interface with Tkinter. I need to have a way to open and save files. Is there a nice GUI that can do that for me, ei, show what files are avaliable, a choose file type function? If it matters any, I am planning on running this on both windows and linux. Thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
Re: Browse type function
Thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
tkinter canvas tag stuff
I'm trying to display a picture on a Tkinter Canvas. It seems to work fine the first time that it is displayed. However, subsequent times running shows an error like this: TCLerror: Wrong # args: should be ".-1211472948 .-1211470996 addtag tag searchCommand ?arg arg ...? My code works like this: if (pic): canvas.delete(pic) im=Image.open(path) image=ImageTk.PhotoImage(im) pic=canvas.create_image(1,1,anchor="nw", image=image) canvas.addtag(pic) Note that path is a path selected outside of the function. What happens is the image is displayed, but with the error message. I think I should either have to put in some kind of argument into the addtag, which isn't documented well, or use a similar but different function. Thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
Raw images
I have an image that is in a "raw" format, ei, no place markers to tell the dimensions, just a big group of numbers. I happen to know the dimension of this array from a different source. I would like to be able to display it. Is there a way to do this easily? I know that several libraries use a "raw" function, but I have little doubt that this differs somewhat from program to program. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Raw images
That will definatly help. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Raw images
Well, the numbers are in a string of variable length. My camera can read specific parts of it's display, so an image of 1024x1024 is just as likely to happen as one of 16x342. Well, not really, but they both could happen. The data is passed by giving the dimentions via a seperate protocol, and then passing the numbers. I've converted the passed numbers to a list of integers. Each is a 16 bit number, BTW. I just needed to display that in a fixed size box, and the answer that was giving using PIL will work perfectly. -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter canvas tag stuff
It's funny, I can put in more variables than needed, it doesn't even call the function, and yet, magically, the picture appears. Odd... Just wish I could solve the problem... -- http://mail.python.org/mailman/listinfo/python-list
Re: Raw images
Well, it's a custum-built camera, so it's not standard by any means. That being the case, I know it's exact format, which is as follows. It is a stream of 16 bit numbers, each representing a point on a grid. The grid is define in a seporate way, outside of the format, but is given a number of rows and columns. From these, an image is defined. I simply need to take this stream, which I converted to a giant string, and display it in the form of a picture. What I've tried to do is as follows: 1. Read string 2. Form an array by combining 2 chars together. 3. Divide by 256 so as to have a 8 bit number, which PIL likes alot better than a 16 bit number. The string is called data. 4. Use im = Image.fromstring('L', (xsize, ysize), data) to create image 5.Use im.thumbnail((700,700)) image=ImageTk.BitmapImage(im) pic=canvas.create_image(1,1,anchor="nw",image=image,tag="pic") canvas.addtag_withtag("pic",pic) There seems to be a problem with the last line, but no picture is displayed without it. That isn't related to the problem I'm having, but I also need to fix it. The problem is it won't display the image, it seems to display nothing. Any ideas as to why? I've tried using PhotoImage, with the same result. Perhaps it's the thumbnail command, I don't know if it has problems if you try to make a thumbnail larger than the picture, but I would presume there's a way around this. Ideas? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Raw images
That did the trick, I can now remove the bad tag statement, and it all works just nicely. Thank you very much! -- http://mail.python.org/mailman/listinfo/python-list
Resizing of PIL images
I am seeking a way to resize a PIL image, even if the original is a smaller dimention than the new size. Resizing seems to only make an image smaller, and not larger. I have a 700x700 sized picture, sometimes that will display an image larger and other times smaller. Is there an easy way to do this, a command that I am missing from the library? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Tk not displaying correctly
I am building a TK interface, that has several threads. If all threads are running actively, including the main one, the interface doesn't update. For example, I have something like this, although more complex import time, threading master=Tk() def thread: global x x=0 while(TRUE): x=x+1 Label(master,text=x).grid(row=0,column=0) time.sleep(1) but=Button(master,command=command,text="hit me") but.grid(row=0,column=0) def command: while(x<100): time.sleep(1) x=0 t=threading.Thread(target=thread) t.setDaemon(1) t.start() master.mainloop() What (I think) will happen is when you hit the button, until x=100, the display will stop updating, and when the command has left it's thread, it will return to updating again. Is there a way to make it so it always will update, irreguardless if it's in a seporate thread, perhaps calling a new thread that calls mainloop? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Resizing of PIL images
I used thumbnail originally, and am using resize now. Perhaps it has to do with the image type (That is based on strings), but the resize function just didn't do it for me. No idea why... Oh well, probably just a problem for me, but, I've found a way around it, for the time being. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tk not displaying correctly
Any way you could provide a fairly simple example, or a website that shows it? I understand that I must create a thread for mainloop, however, I can't see how to make that work, every time I do, it ends the program only a few seconds late. Will I have to make an even for all buttons, etc that are on the GUI? Wow, sounds like lots of work... Anyways, thanks! -- http://mail.python.org/mailman/listinfo/python-list
Oddities of Tkinter
I am building a tkinter program. A part of this program is to read data from an incoming interface, and depending on the data, will display a bit of text on the tk dialog, it decodes this data, so to speak. If one command is sent, everything's just fine. When multiple are sent, the program will stop responding, and will only continue to respond after one types -c. The statement at fault is something like this. e1=StringVar() Label (master,textvariable=e1, width=32).grid(row=44, column=4) def disp_mes1(text): e1.set(text) It's the line 31.set(text) that takes so long when there's other processes running. I've ran this program sucessfully many times on another computer, however, when transfering to another with the same OS, this problem was created. Any ideas as to what I might be able to do to fix this problem? My main code is hopelessly complex to post the entire thing, and I can't recreated the same structure with smaller ammounts of code. Thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
Re: Oddities of Tkinter
Nope, that's the oddest thing about it all... Perhaps the statement is called twice or something along those lines, but there again, I can't see how it would be... -- http://mail.python.org/mailman/listinfo/python-list
Re: Oddities of Tkinter
Only 1 process initiated Tkinter.Tk. I guess this'll just be a tough bug hunt... It drives me nuts that it should work, it just doesn't for some reason... I guess I can try various things to make it work, but, well, I would rather that it just works to start out with... -- http://mail.python.org/mailman/listinfo/python-list
Re: Oddities of Tkinter
I thought I mentioned that I'm running in linux, and yes, there are threads involved. I just don't know why on one machine that it would run so differently than another. As to re-writing my whole code, well, I've got around 2500 lines of code, and while re-writing would be faster I'm sure, I still don't want to invest in the long hours to do such a thing. Especially since 90% of the time that it will be running on the one machine that works, only a small percentage on the other, and it will never be publically used. It's an interface for a custom-built astronamical camera, it'd be useless to anyone who doesn't have the very camera that we have, except to get an idea as to how some things work. -- http://mail.python.org/mailman/listinfo/python-list
Possible memory leak?
I have a function in a program that works something like this. def load_pic_data(width,heigth,inpdat, filt=TRUE): data='' total=0 tnum=0 size=100 for y in range(0,heigth): row='' for x in range(0,width): index=2*(x+y*width) num=ord(inpdat[index+1])*256+ord(inpdat[index]) if(vfilter.get() and d_filter and filt): num=round((num-(d_filter[index/2]))) if(num<0): num=0 if(num>255*64): num=255*64 row=row+chr(num/64) data=data+row The purpose of this part of a program is to take a 14 bit numerical representation and convert it to an 8 bit representation. This will later be displayed as an image. However, I've noticed the following about this code. I was noticing when I took a small picture, it went really fast, but a larger picture took forever to run through. I added a print statement to the y portion of the code to see where it was getting hung up. I noticed that it appears to be running slower as time goes on. I did a time.time() timestamp to verify this, and had it confirmed. Any ideas as to what I could do to make it run faster? Note that if this process is repeated, it runs equally slow.What can I do to make it run faster? I suspect if I somehow dealocate the row statement after it's done, that it will run faster, and the data variable when it's done, but I just don't know how to do so.Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Possible memory leak?
Hmm. The problem is that the required form for the image is as a string of characters to convert with the tkimage interface, at least, as I understood it. Perhaps an array would work, I'll try that when I get ahold of the computer in question (One thing required is a linux only library, and I don't have access to a linux machine at the moment...) However, I would like to make a few more statements. The max image size is 1024x1024. The length of time it takes to do the row statement increased fairly substationally every time it was ran, in the order of ~.5%. That seems small, but when you run it 1M times, the last operation will take 5000 times longer than the original, or about ~1sec. And that's just for one row, the entire process would take an eternity... And the real kicker, when doing this with smaller images, ei, about 128x128, the second image starts of at the same point of slowness as the first one. EI, the last operation of the first image took .01 seconds to complete (It started, let's say, around .005), for instance, the next one would start at that length of time, and end at .02 or so, the third picture would be taking that long for each row, and so on. It only does this on one particular computer (I've only had the chance to run it on 2 machines to date, BTW.) There is a reason why the rows are pieced together as is, I must say, but it's a tad bit complicated... I'll just defend it without giving a real reason. Thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
Re: Possible memory leak?
Oh, I should also mention, I used a memory monitor and saw the amount of memory being used go up with time, even when the function ended, meaning I did the 10 128x128 pictures, never was any memory dealocated until I exited the program. -- http://mail.python.org/mailman/listinfo/python-list
Re: Possible memory leak?
FYI, to all who asked, I was indeed just simply monitering the system memory. I changed my approach to one that uses arrays and simply joins the statements together at the end, it seems to have improved the speed. However, for some reason it still takes a small eternity to process on one computer, and not the other. The oddest thing of all is that the one that is taking longer is on a better computer. I have been using Linux, running Python 2.4. The modified version of my code is now as follows: (Note, a few small changes have been made to simplify things, however, these things don't apply to a full-scale picture, so the shouldn't slow anything down in the slightest.) def load_pic_data(width,heigth,inpdat, filt=TRUE): ldata=[] total=0 tnum=0 size=100 array=[] for y in range(0,heigth): row=[] ts=time.time() for x in range(0,width): index=2*(x+y*width) num=ord(inpdat[index+1])*256+ord(inpdat[index]) if(vfilter.get() and d_filter and filt): num=round((num-(d_filter[index/2]))) if(num<0): num=0 if(num>255*64): num=255*64 tba=chr(num/64) row.append(tba) srow=''.join(row) ldata.append(srow) print y,time.time()-ts data=''.join(ldata) There is considerable more to the function, however, I've traced the slowest part to this one. Note the statement "print y, time.time()-ts". A few of the outputs are as follows, with the 1024x1024 image. 1 .0633 2. .07005 3. .06698 20 .07925 30 .08410 100 .16255 200 .270895 500 .59182 900 1.06439 Note that at the time I wrote this, 900 was the highest avaliable. Note that the value seems to be consistant when a few close ones are observed, but over time, it increases, until the program is running very slowly. For some reason it does this on one computer, and not another, and I believe the 2 computers have identical python configuration, ei, same libraries, version, etc. Both are the same type of linux as well. I no longer am joining the strings one at a time, but only at the end. What could be the source of such an odd problem? I understand that the large image will take longer to process, but I would think that the relationship should be more or less linear with the size, and not exponential. Thanks for all of the help till now! -- http://mail.python.org/mailman/listinfo/python-list
Re: Possible memory leak?
Very interesting results with the last test. I guess I go back to my other code then, even if it is only a hair faster, it's still faster... It's odd, I just ran another test. There's 2 ways I can call my load_pic function, first of all, through taking a picture, secondly by loading a picture. For some reason, the exact same function takes the same amount of time when the load picture function is used, but not when called from the take picture function. Odd, isn't it... I don't know why the time would increase for one, but not for the other. The data is passed in exactly the same format, it's just really odd... Oh well, I'll get something figured out... -- http://mail.python.org/mailman/listinfo/python-list
Re: Possible memory leak?
Fredrik Lundh wrote: > Giovanni Bajo wrote: > > > --- foo.py - > > def iters(n): > > s = '' > > for i in xrange(n): > > s += chr(i%64) > > return s > > > > def iters2(n): > > L = [] > > for i in xrange(n): > > L.append(chr(i%64)) > > return "".join(L) > > --- foo.py - > > > > So, look, it's even faster than the solution you're proposing. > > since you know the length, you can preallocate the list > > def iters3(n): > L = [None]*n > for i in xrange(n): > L[i] = chr(i%64) > return "".join(L) > > or use a preallocated array > > def iters4(n): > L = array.array("B", [0])*n > for i in xrange(n): > L[i] = i%64 > return L.tostring() > > on my machine, the last one is twice as fast as your "even faster" > solution under 2.4. in earlier versions, it's just under 5 times faster. > > for the OP's problem, a PIL-based solution would probably be ~100 > times faster than the array solution, but that's another story. > What do you mean by a PIL based solution? The reason I need to get the data into the string list is so I can pump it into PIL to give me my image... If PIL has a way to make it easier, I do not know it, but would like to know it. > -- http://mail.python.org/mailman/listinfo/python-list
Re: Possible memory leak?
The times that I posted was the time that it took to perform ONE row iteration. As you can see, the time was going up, fairly dramatically. Why on earth could it be doing this? I understand the the time will fluctuate somewhat depending upon what else the CPU is doing, but, why is the base time increasing so much for one machine doing something one way, and not for another machine appearently identically configured doing the same operation? That is the great question I have. Still, it seems as though it cannot be solved as to why its doing this. The only thing I can think of that might be different is perhaps these results came off of a slightly newer version of python. One great problem is the data is read in streamlining, ei, the data enters this function as a list (Or tuple, I always mix those two up, but the one that uses []'s. not ()'s). Oh well, the solution will come, eventually. Thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
Re: Possible memory leak?
I have made one confirmation. The only identifiable difference that I have seen is that one runs on python 2.4.2, and the other 2.4.1. Oddly enough, it's the first one that's the one that is having more problems than the second... Why that is, I don't know. It still could be something else, but... -- http://mail.python.org/mailman/listinfo/python-list
Re: Possible memory leak?
The reason it's done in width and heigth is that there is some other non-related processing functions that were going on in the mean time with the problem. I found the source of the slow-down, when 2 non-important lines of code were commented out, the program worked perfectly. if(vfilter.get() and d_filter and filt): num=round((num-(d_filter[index/2]))) I don't know why these lines of code are causing a slow-down, but, it is for some reason. What I will do is just simply combine these 3 variables (Which won't move image to image) into one variable, that will not have the problem that I've seen. But, thanks for all of your help! -- http://mail.python.org/mailman/listinfo/python-list
determinant
I am trying to find a nice function that quickly determines the determanant in python. Anyone have any recommendations? I've heard about numpy, but I can't get it to work (It doesn't seem to like the import Matrix statement...). Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: determinant
I am using Windows, using Python 2.4. Perhaps I just did the import statement wrong? I've never installed a library in Windows before, perhaps I did something wrong there too.. But anyways, it just doesn't seem to work. The import statements were: import Matrix, LinearAlgebra Neither seem to work. Thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
Re: determinant
Never mind, I realized I was using a bit of code way too old. I just needed to change the import statements to: import numpy.matrix import numpy.linalg Thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
Thread imbalance
I have a program running several threads. One of them must be done every (Specified time, usually 1 second). The whole point to having a thread is do this. However, I've noticed the following. When there is another part of the program that is active, this thread slips into disuse, ei, it's only ran about once every 4-5 seconds, or perhaps it waits for a lul in the computing process. How can I ensure that this does not happen? This thread uses little processing power, so it could be set to a high priority, if there is a way to do this. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread imbalance
The stuff that it runs aren't heavily processor intensive, but rather consistant. It's looking to read incoming data. For some reason when it does this, it won't execute other threads until it's done. Hmmm. Perhaps I'll just have to work on a custom read function that doesn't depend so much on processing power. -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread imbalance
The read function used actually is from a library in C, for use over a CAN interface. The same library appears to work perfectly find over C. I wrote an extention module for it. The function t_config is the threaded function that will call a function called config once per second. Note the time.time() timer def t_config(): while (TRUE): if(can_send_config): config() ts=time.time() time.sleep(1) if time.time()-ts>1.5: print "Long time detected else: time.sleep(.1) When nothing is happening, the thread runs pretty consistantly at 1 second. However, when it is doing IO through this C function or whatever, the length of time increases, for the time.sleep() function. Kind of strange, isn't it? I can explain in more detail if it's needed, but I don't know how much it'll help... -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread imbalance
Adding that bit of code seems to have fixed the problem, thanks alot! -- http://mail.python.org/mailman/listinfo/python-list
Canvas clicking stuff
I have a picture that is being displayed on a canvas interface, that I want to do the following. When a mouse button is clicked on the canvas, I want to pass to a function the X and Y coordinates of where this mouse button was pushed. Futhermore, and I don't know if this is possible, I would like to have a function that passes the same data without a mouse button being clicked, or perhaps differentiating between left and right clicks. Thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
Re: Canvas clicking stuff
I guess I should have mentioned that the canvas is a Tkinter canvas, but, well, I guess that could be infered. -- http://mail.python.org/mailman/listinfo/python-list
Re: Canvas clicking stuff
Ahh, exactly what I was looking for. Thanks for the help! Fredrik Lundh wrote: > Tuvas wrote: > > > I have a picture that is being displayed on a canvas interface, that I > > want to do the following. When a mouse button is clicked on the canvas, > > I want to pass to a function the X and Y coordinates of where this > > mouse button was pushed. > > use event bindings: > > http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm > > -- http://mail.python.org/mailman/listinfo/python-list
Tkinter Event Binding Double-click
I am trying to execute a function with a tkinter event binding double click. With 2 mouse clicks done quickly, the function should happen, otherwise, it should not. However, I am noticing that the time that the event binding of a double-click is quite long, on the order of a second or so. I am double-clicking twice in a second, and the function is being executed 3 times, and not just 2. I want to know, is this controlled by the OS, or by Tkinter? And if by tkinter, is there a way to change it, and how so? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Module question
I know this is probably a very simple question, but I am building a program that is now at about 2400 lines of code in the main module. I need to break it up, however, there are certain variables that I would like to use among all of them, namely the TKinter background. It's build using tkinter, so, to do anything useful requires having the master=Tk() variable portable in every interface. I can't just pass this variable, the real way to do it is to have a global variable. How can I do this? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Module question
Could I just do this then? from foo import x? One more question now that I've tried this. In my main function, I have alot of init code. I don't want this code to be re-ran when the second module imports the first. Is there any way around this? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Module question
Most of these are indeed independed of Tkinter, except for a status report message that is often sent in response. I' have a few small files already that do this, however, I would ike to be able to put several that do in fact need to post status messages as well. There are about 2400 lines of code in the main module right now, and about 1000 in smaller modules, but I would like to move some more, the problem is, most of the function in my tkinter function use somehow the master tk() variable. I don't know if there's any way around it or not, just trying to find a way. Mine is a somewhat unusual program wherein that the majority of the funcionality is in fact as a GUI, it mostly runs programs from other mediums, it controls an external device, so there isn't much in the line of real gruntwork that the program does. Thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
Re: Module question
Ahhh. Actually, I realized my problem was the fact that not everything had been loaded yet. Circular loading can be a bit difficult I can see... I guess I need to import the new module after x has been declared? Ei, I need this. Mod1.py x=1 from mod2.py import * = Mod2.py from mod1.py import x Will this work right? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Random Prime Generator/Modular Arithmetic
I have made and recently posted a libary I made to do Modular Arithmetic and Prime numbers on my website at http://www.geocities.com/brp13/Python/index.html . I am currently in a crypotology class, and am working on building a RSA public key cryptology system for a class project. I am building the librarys just to get the experience to do so. However, I would ask if any of you know of any gaping security holes that can easily be seen from my selection of random prime numbers, ei, are they somehow predictable? Just wanting to make sure. For simpler than going to the website, I used the ranint function to pick a random prime number, then ran it through the miller rabin primality test. It's a probabalistic test, which means it isn't full proof, but there's still less than 1 in a million of giving a false reading. Thanks! And if you should so want for some reason, feel free to use it! -- http://mail.python.org/mailman/listinfo/python-list