Re: Password entering system
I actually decided to write my own, the thing I needed to know was the show option to entry. That was the key! -- http://mail.python.org/mailman/listinfo/python-list
Password entering system
I want to write a GUI program (Preferably in Tkinter) that will allow for the entering of passwords, stared out like a normal program does. Is that possible? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Password entering system
Thanks, that's exactly what I wanted! -- http://mail.python.org/mailman/listinfo/python-list
Re: AES encryption
Ere, I mean testing only symetrical keys, and symetrical messages, nothing more realistic. Sigh. Oh well. It works, and that's the important thing. I don't know if I'll put in support for the larger key sizes, but, I'll leave it be for now. -- http://mail.python.org/mailman/listinfo/python-list
Re: AES encryption
Okay, I figured out the problem. The problem was that my algorythm filed the numbers into the matrix as so: 1 2 3 4 5 6 7 8... While it should have been 1 5 9 13 2 6 10 14 ... When this was fixed, the program works great! That's what I get for testing only asymetrical keys... Oh well, thanks for the help in fixing the problem! -- http://mail.python.org/mailman/listinfo/python-list
Re: Cryptographically random numbers
I've actually done the tests on this one, it's actually faster to use the += than a list, odd as it may sound. I ran into this one a while back. The best way to do it is to build an array from scratch, fill the array, and then join it, but I didn't have time to do it that way... -- http://mail.python.org/mailman/listinfo/python-list
Re: Cryptographically random numbers
I will admit though, I have the same question as Paul, why do you want a random string of numbers, letters, and symbols? But, you asked for it, so, that'll do. -- http://mail.python.org/mailman/listinfo/python-list
Re: AES encryption
I don't know if it means anything, but the AES system that I have isn't set up to do anything other than 128 bit encryption at the moment, nor will it likely do so, mainly because most systems only explain how to get the 128 encryption, and not the larger sizes. I'm sure it's fairly easy to change, but... Well, I'll take a look at it, but I don't have the time at the moment... -- http://mail.python.org/mailman/listinfo/python-list
AES encryption
I have just finished a new function that will do AES128 encryption, which is the standard for private-key cryptology today. In fact, the NSA permitted AES to be used for classified documents in the USA, the first time a public algorithm has been given this honor (Secret and Top Secret documents can use AES as well, but must use a larger key (192 or 256 bits)) I've tested my function with a thousand random texts, it seems to return the same result as received every time. If you want to take a look, http://www.geocities.com/brp13/Python/index.html Note, I still wouldn't quite encrypt your credit card numbers, but, well, it does seem to be secure enough... I would like comments as to anything fairly simple I might be able to do to increase security. I've tested the algorithm about a thousand times, with no appearant failures, but, there still could be one that I haven't found yet, so... Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Cryptographically random numbers
from os import urandom def cstring(bytes): ret='' while(len(ret)'0' and c<'z': ret=ret+c return ret That should do it, though I bet there might be a more efficient way. I don't know if that's the set of characters you want to use, but... If you want a better answer, you'd have to be more specific. -- http://mail.python.org/mailman/listinfo/python-list
Re: Cryptographically random numbers
Thanks for the function Paul, it works alot nicer than the one I had in my program... Now, with all of this knowledge, I'm going to be brave and try out everything with AES. It seems to be working alright, I'll debug this more on my own than I did with my RSA code, which turned out to be full of bugs... I know the program sends the blocks in the reverse order that would be expected, but, well, I'll get there. Cryptology is fun:-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Cryptographically random numbers
Wow, that would have been nice to know... Oh well, I've already got the function, might as well use it... I'm starting to learn alot more of the standard libraries that exist for alot of the little functions. It seems like every project I have I build a misc.py file that contains several small, but useful functions, and quite often I discover there is a system library function to do just that. Oh well. Still, I've gone a long ways in my Python skills since I started 6 months ago:-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Cryptographically random numbers
Wait, I now see that there is a native base 2 log in python, so I will just do that rather than my adhoc way. The reason for adding one is to make sure there isn't any problems if the log is, for instance, 2.2. It will always round up. It's better to have to try twice to make sure the number can have the max range than never use the top half, as the first version did... That changes the function to: def cran_rand(min,max): range=int(log(abs(max-min),2))+1 num=max+1 if range%8==0: crange=range/8 else: crange=range/8+1 while(num>max): num=min+s2num(urandom(crange))%(2**range) return num As to the s2num(text), well, that looks really neat. Is there an easy way to do the reverse of that? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Cryptographically random numbers
Ahh, you are correct, that is a large bug... How about this one? def s2num(text): if(len(text)==1): return ord(text) else: return ord(text[0])+256*s2num(text[1:]) def cran_rand(min,max): range=int(log(abs(max-min))/log(2))+1 num=max+1 if range%8==0: crange=range/8 else: crange=range/8+1 while(num>max): num=min+s2num(urandom(crange))%(2**range) return num -- http://mail.python.org/mailman/listinfo/python-list
Re: Random Prime Generator/Modular Arithmetic
Actually, there was a small bug fix that I found, and I had a teacher who told me once that there was only 5 pseudoprimes. I realized that large numbers of prime numbers were returning false, and discovered the root of the problem, which was that my M-R test ended too late... But, it works now, thankfully. I may switch soon to an upgraded version of the code, to be more efficient. But for now, I'm just glad to have it work! -- http://mail.python.org/mailman/listinfo/python-list
Re: Random Prime Generator/Modular Arithmetic
Okay, now I get the correct number of 561 pseudoprimes, 5, so I can assume that it is indeed working right. Whew. Thanks for the help on that one. Now, I only wish I could change the answer to my last homework assignment... Oh well. -- http://mail.python.org/mailman/listinfo/python-list
Re: Random Prime Generator/Modular Arithmetic
Ahh, I see, I missed doing the last step in my M-R test. Hmmm. Well, got that one fixed now, time for a new release I guess. Sigh. I do seem to be going through them rather quickly... -- http://mail.python.org/mailman/listinfo/python-list
Re: Cryptographically random numbers
Good idea about the max and min values. Yes, urandom is os.urandom. s2num('blah') will convert the phrase blah to ascii, and treat them as if they were a big function. Anyone else whose still interested, I found another small bug, but it was in the modular (Again). It won't do much, but... I did test out the RSA from end to end, found another small bug (I imputed the text luke, and it decrypted to ekul), but it works good now. Hopefully there's nothing left gaping, thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
Re: Random Prime Generator/Modular Arithmetic
Bryan Olson wrote: > Tuvas wrote: > > Okay, I don't know if your farmiliar with the miller-rabin primality > > test, > > Paul is familiar with it. When he referred to your Miller-Rabin > test, he meant all the rounds. > > > but it's what's called a probabalistic test. Meaning that trying > > it out once can give fake results. > > In the sense that some composites will pass as prime for some > bases. > > > > For instance, if you use the number > > 31 to test if 561 is prime, you will see the results say that it isn't. > > That's not an instance of a fake result; Miller-Rabin has that > one right. When Miller-Rabin says a number is composite, it is > always correct. I mis-stated. If you try 31 in the Miller-Rabin test. >>>Mod(31,561).is_strong_pseudo_prime() True However, 561 is not prime, it is divisible by 3, 11, and 17. Actually, I did another test, and realized that it was indeed a bug in the code. Yikes. Oh well, thanks for the help in identifying it! An example that would be alot easier is this: >>>Mod(16,561).is_strong_pseudo_prime() True > > > Your current Miller-Rabin test, in > >http://www.geocities.com/brp13/Python/modular.html > > in method Mod.is_strong_pseudo_prime(), looks buggy. Obviously > you want "cut()" not "cut", and "if 1:" cannot fail. In my opinion, > the Mod class is not such a good idea; just use functions. > The reason for the modulos class, well, was more of a practice than anything else. I could indeed just use functions, but I needed the Mod class for a few other things, and figured it was just easier to program it once and use it for anything rather than anything else. > > Note that Python has modular exponentiation built in. > > pow(base, power, modulus) Nice to see that Python supports modular exponentiation. I'll have to remember that one. Probably the next time I do an update to the code, I'll just use it instead, it's probably faster than mine. > > with positive integer arguments will return base**power % modulus. > > > Finally, though most introductory crypto courses don't cover it, > RSA requires "padding" of the plaintext data. Google RSA + Padding > for more. Or ask on sci.crypt. > > > -- > --Bryan Overall, I guess another update is coming soon. Thanks for the help in debuging again! -- http://mail.python.org/mailman/listinfo/python-list
Re: Random Prime Generator/Modular Arithmetic
Although, I have to brag quickly, adding in this simple prime check speed up the algorithm to the point that it's actually faster to find a prime number with my program than to verify a number prime with GP/PARI, so, I feel good. -- http://mail.python.org/mailman/listinfo/python-list
Re: Random Prime Generator/Modular Arithmetic
Actually, it wasn't very nice, it returned composites instead of primes... There was alot of little bugs, I'm glad I checked it again. The new code once again is uploaded, the previews are on their way... I did set up a system to check for primality up to 1000, I think any more than that and it will become conter-productive. -- http://mail.python.org/mailman/listinfo/python-list
Re: Random Prime Generator/Modular Arithmetic
Yep, you guessed correctly about the s2num function, I knew I should have put a bit more.. It just converts an ascii string to a number, however many numbers that are nessicary. I could indeed check for all primes below a certain number, however, it still seems to run quite fast, at least to a 400 digit number. It's not something I'm going to use a ton, so optimizing it might not be worth it much more than it is. Perhaps I'll try all primes at least up to 100, that wouldn't be too bad... Maybe I'll have to modify my old prime string to output the python command to check all of them, it's a bit of a pain the whole if 0 in (n%2, n%3) stuff, and I can't think of a better way to do it without writing a new function to do so. I'm going to post the new code in just a minute, it's running quite nicely. I'm also posting my RSA function, which I believe should be secure enough. I'm uploading the code to them now, the HTML page'll be a few minutes... -- http://mail.python.org/mailman/listinfo/python-list
Re: Random Prime Generator/Modular Arithmetic
H. Well, I don't know what else I could do, except for to write a function that doesn't require recursion. Still, 300 digits isn't too bad... I have also realized that if you try is_prime(3) it will return false. I'll have to work on it... Thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
Re: A simple question
Ahh, that make sense! Thanks a ton! -- http://mail.python.org/mailman/listinfo/python-list
A simple question
I know the answer is probably really simple to this, and I feel bad to even ask, but I can't find the answer anywhere... Let me show what happened, then ask the question. >>> x=[[0]*2]*2 >>> x [[0, 0], [0, 0]] >>> x[0][1]=1 >>> x [[0, 1], [0, 1]] >>> The question now. Why is the output list [[0, 1], [0, 1]] and not [[0, 1], [0, 0]]? And how can I make it work right? I do know that x[0][1] will always give the value of that specific coordinate, but never before have I tried to manipulate rows like this, and I'm finding I need to. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Cryptographically random numbers
Okay, I'm working on devoloping a simple, cryptographically secure number, from a range of numbers (As one might do for finding large numbers, to test if they are prime). My function looks like this: def cran_rand(min,max): if(min>max): x=max max=min min=x range=round(log(max-min)/log(256)) if range==0: range=1 num=max+1 while(num>max): num=min+s2num(urandom(range)) return num Any comments on this? I think it should hold up to a test, it seems to work alright. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Random Prime Generator/Modular Arithmetic
Okay, I don't know if your farmiliar with the miller-rabin primality test, but it's what's called a probabalistic test. Meaning that trying it out once can give fake results. For instance, if you use the number 31 to test if 561 is prime, you will see the results say that it isn't. Mathematically, the most possible wrong answers is 1/4th of the numbers. Thus, one should try at least 10 times (A very standard value) in order to ensure that the number is not a psuedoprime, but indeed a real prime number. That was the intent of the loop of 10 without using the number. If this test fails, it will chose another random number to test. I could easily test with several small numbers, at least primes up to 20 would greatly reduce the number of miller-rabin tests to perform, and would speed up the process considerably. Might as well toss it in. Thanks for the tip on the urandom. I knew there had to be a better random number generator somewhere. I saw lots of stuff for os specific, but I'm trying to develop this as os independent. -- http://mail.python.org/mailman/listinfo/python-list
Re: Random Prime Generator/Modular Arithmetic
Okay, the bug in my code has been fixed, it should work alot better now... I thought I had tested the power function, but I appearently wasn't even close... But now it works just fine. I guess you are right, I will have to work on a better system to be cryptologically secure. But, at least I have a start. Thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
Re: Random Prime Generator/Modular Arithmetic
Well, the RSA element's never going to encrypt more than a small, 1 block system except under rare occasions, the primary encryption will be AES128. Thanks for the help though! -- http://mail.python.org/mailman/listinfo/python-list
Re: Random Prime Generator/Modular Arithmetic
I have discoved that the mod function isn't quite right in dealing with powers, but, I'll have it fixed shortly. -- 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
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
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
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
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
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
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
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
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: Thread imbalance
Adding that bit of code seems to have fixed the problem, thanks alot! -- 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
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
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: 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
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
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: 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
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 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?
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?
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?
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?
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?
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
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: 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
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
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
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: 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
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
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
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
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
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: 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, 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: Raw images
That will definatly help. Thanks! -- 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
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
Re: Browse type function
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: 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
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: 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
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
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: 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
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: 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
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: 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
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
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: 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
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
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
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
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
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: PIL-> Tkinter
That would be extremely useful.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: 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
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
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- checkbutton
That solved the problem. 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
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- checkbutton
Ere, ignore the mis-capped Checkbutton and the missed master call in it... -- 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