Re: recursion depth problem
Yes, you should use a for loop in this situation. Certain functional languages, such as Scheme and various LISP dialects allow for what is called tail recursion which effectively eliminates this problem by internally converting recursion to iteration. Python isn't really cut out for heavy recursive work, and the Pythonic way of doing things is through the lovely for loop. -- http://mail.python.org/mailman/listinfo/python-list
Re: How can i compare a string which is non null and empty
str != returns true if str is NOT the empty string. str is not None returns true if str is null (or None as it's called in python). To check to make sure a string is nonnull and nonempty, do: str is not None and str != -- http://mail.python.org/mailman/listinfo/python-list
Re: problem at installing phyton on windows
On Mar 25, 1:06 pm, gslm [EMAIL PROTECTED] wrote: Hi! I'm too new on phyton.I have installed phyton.But when I write phyton command, unfortunately, i can't run.I suppose that it is bacause of setting path.But i can't solve. Can you help? You need to set what is called your PATH environment variable. See: http://www.computerhope.com/issues/ch000549.htm and add C:\python\ (or wherever your python package is installed) to your PATH. Another thing is, when i double click the .py file, there are the project form and the command line.How can i provide to view only the project? I don't quite understand what you're asking here. -- http://mail.python.org/mailman/listinfo/python-list
Re: is it possible to remove the ':' symbol in the end of lines starting with 'if', 'while' etc?
Tip: don't try learning perl. I agree the colon is largely redundant, but it's not unreasonable. -- http://mail.python.org/mailman/listinfo/python-list
arrow keys don't work
I've noticed that in Python 2.5, the interactive prompt does not support intelligent use of arrow keys like 2.4 did (up/down for previous/next statement, left/right for moving the cursor). What exactly is the reason for this and is there an easier fix than downgradinig to 2.4? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: arrow keys don't work
Robert Kern wrote: tac-tics wrote: I've noticed that in Python 2.5, the interactive prompt does not support intelligent use of arrow keys like 2.4 did (up/down for previous/next statement, left/right for moving the cursor). What exactly is the reason for this and is there an easier fix than downgradinig to 2.4? Thanks. Your installation of 2.4 probably had the readline module installed while your installation of 2.5 doesn't. What platform are you on? Actually, I should have posted this a while ago. I've noticed it on Ubuntu Linux, Mac OSX, and earlier today on Sun Solaris. What do I need to do to install / configure readline? -- http://mail.python.org/mailman/listinfo/python-list
Re: arrow keys don't work
Have you changed your terminal (either the program itself or its config) so that it is no longer sending the correct codes? I doubt this is the case. Everything works for the bash shell and common lisp. It's just python acting up. When you hit the arrow key, what happens? Do you just get nothing at all, or do you get control characters appearing? e.g. ^Z or similar. udlr yields ^[[A^[[B^[[C^[[D in the interactive python interpreter, but like I said, works like it should outside the Python interpreter. -- http://mail.python.org/mailman/listinfo/python-list
Re: arrow keys don't work
It looks like I got readline working. Thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about compiling.
That's not the whole truth. :) The whole truth is that from a developer's POV, .pyc files are unimportant. -- http://mail.python.org/mailman/listinfo/python-list
Re: Slowdown in Jython
Jython is a Java application That was the intellectual leap I needed to solve the problem. I forgot that I have total access to Java memory management. It turns out at the point of slowdown, Java was continually running full GC, causing the awful loss of performance. I figured out that I was not releasing a very large chunk of memory right before the script, so I effectively had a duplicate of every record in memory. I'm still not sure why my memory usage is increasing during the script, but with the removal of the duplicates in memory, it runs just fine now. Problem solved for now. -- http://mail.python.org/mailman/listinfo/python-list
Slowdown in Jython
I have an application written in jython which has to process a number of records. It runs fine until it gets to about 666 records (and maybe that's a sign), and then, it's performance and responsiveness goes down the toilet. It looks like it's running out of memory and is being forced to use extended memory, but I do not know enough about the language to figure out where this is happening. It will eventually finish the task, but the window stops responding, and it ends up taking several hours (as opposed to several minutes as it should). I really just wish I had a tool for polling the amount of memory Jython was using at any given moment. Does anyone have any strategy or advice for me? -- http://mail.python.org/mailman/listinfo/python-list
Superclass for Errors?
I have a program which has a GUI front-end which that runs a separate thread to handle all the important stuff. However, if there is a problem with the important stuff, I want the GUI to raise a MessageBox alert to indicate this. For exceptions, I can simply use a catch-all except statement like: try: ... except Exception, error: JOptionPane.showMessageDialog(self, Error: %s % error) Only, I want it to catch Errors as well. Right now, I'm using: try: ... except (Exception, TypeError, NameError, RuntimeError, AttributeError), error: JOptionPane.showMessageDialog(self, Error: %s % error) I was wondering if there is a superclass for TypeError, NameError, RuntimeError, AttributeError, etc. Normally, I could simply use a regular except: but then I don't have access to the error message. So what's the best solution to this problem? -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie: what is a usefull IDE for Python on Windows ?
On Dec 26, 8:53 am, Larry Bates [EMAIL PROTECTED] wrote: Osiris wrote: what is a usefull IDE for Python on Windows ? I am a happy user of jEDIT. -- http://mail.python.org/mailman/listinfo/python-list
Re: skip last line in loops
Try: afile = open(filename) lines = afile.readlines()[:-1] # assigns all except the last element to a list lines for line in lines: print line -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
I use 'French units' instead of the term 'metric system' because the latter means 'measurement system,' and of course could validly be applied to _any_ system.Now we know how one contractor ended up using English units when the other was using French units and an entire Mars mission was lost: they were both using the metric system. LISP is better than Python, because it does not have a American Empirical Measurements library, preventing horrible spaceborne disasters. -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
In musical terms, Python is like a Beatles song, very popular and easy to sway and dance to. Lisp is like a Bach fugue. Very nice analogy. -- http://mail.python.org/mailman/listinfo/python-list
Re: len() and PEP 3000
__len__ is not very special and the property len eliminates the redundant parentheses. One might say the current syntax eliminates the redundant dot. -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
I think the lesson here is that LISP is the language you use when you want mathematical elegance and perfection and Python is the language you use if you want to actually program stuff. -- http://mail.python.org/mailman/listinfo/python-list
pdb question
In the Python debugger (pdb), how do you designate breakpoints at the start of methods? I've tried: break methodName break class.methodName break object.methodName but none of these seem to work. What is the trick? -- http://mail.python.org/mailman/listinfo/python-list
Re: pdb question
Strange. It seems to be working just fine now. Maybe I wasn't waiting for all the symbols to be defined before setting my breakpoint. On Nov 26, 2:41 pm, Fredrik Lundh [EMAIL PROTECTED] wrote: tac-tics wrote: In the Python debugger (pdb), how do you designate breakpoints at the start of methods? I've tried: break methodName break class.methodName break object.methodName but none of these seem to work. What is the trick?define seem to work. the className.methodName and object.methodName forms seem to work just fine to me (assuming that the class or object has been defined, of course). if nothing else works, you can use the line or file:line syntax. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Static Variables in Python?
Michael Yanowitz wrote: Is it possible to have a static variable in Python - a local variable in a function that retains its value. For example, suppose I have: def set_bit (bit_index, bit_value): static bits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] bits [bit_index] = bit_value print \tBit Array: int i while (i len(bits): print bits[i], print '\n' I realize this can be implemented by making bits global, but can this be done by making it private only internal to set_bit()? I don't want bits to be reinitialized each time. It must retain the set values for the next time it is called. If you declare bits in set_bit() as global bits = ..., it will create it as a global variable without you having to declare it outside of the function. Just be careful about name conflicts. -- http://mail.python.org/mailman/listinfo/python-list
Re: Static Variables in Python?
But of course: def fun(): global x = 10 SyntaxError: invalid syntax global x x = 10 Close enough ^^; -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL - transparent ImageDraw.text()
aljosa wrote: is it possible to create transparent text (~50% transparency) on image? i'm using the following code to draw text on image: font = ImageFont.truetype(str(self.font_family)+.ttf, self.font_size) draw = ImageDraw.Draw(img) draw.text((10, 10), self.text, font=font,fill=(255,255,255)) url with example would be nice 8-) Aljosa Mohorovic Create a new image filled with transparency (either palletted or alpha). Draw your text to that image instead. Then, paste the transparent image onto your main image. I don't know of any examples online, as I learned this through the sweat and pain of trial and error =-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python linker
[EMAIL PROTECTED] wrote: I love python - I use it as a utility language to complement my C# programming every day. However, the reason I do not use it as my primary language is - surprise, surprise - not its lack of static type checking, but the size of standalone executes (which embed the python runtime). Would it be possible to link only the used functions into your resulting executable? After all, a typical application might only use 20% of everything that is in the Python .dlls. The same applies to wxPython - it would be great if you could only link in what you need. Would it be possible to write such linkers at all (maybe based on GCC)? For your distribution, just move your DLLs to the appropriate system folder. That's what DLLs do. You throw them in system32, forget they were there in the first place, and the Linker Troll does the rest for you. -- http://mail.python.org/mailman/listinfo/python-list
Re: question about what lamda does
[EMAIL PROTECTED] wrote: Hey there, i have been learning python for the past few months, but i can seem to get what exactly a lamda is for. What would i use a lamda for that i could not or would not use a def for ? Is there a notable difference ? I only ask because i see it in code samples on the internet and in books. Lambda is just as powerful as a function, but totally useless =-P Lambda used to be handy before the introduction of list comprehensions. Now, though, there primary use is obfuscating your code. -- http://mail.python.org/mailman/listinfo/python-list
Re: range() is not the best way to check range?
Simon Forman wrote: To me, and perhaps others, T = set(xrange(0, 1, 23)) and n in T are somewhat easier to read and write than not n % 23 and 0 = n 1, YMMV. Eh? How is the first easier to read than the second?? You have a nested function call in the first! Regardless, testing if a member is part of a ranged set is always going to be slower. It's the nature of what you're doing. Building a set and then searching it takes much longer than a single modulus and subtraction (which is all an integer comparison is). -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding exe file
Bayazee wrote: hi,ThanX but i dont want to save the exe file in temp file and run it . i want to run it directly from python . maybe such this : exec(file(test.exe,rw).read())) i want write a cd lock with python tp protect an binary file . and so i dont want save it in other temp file fom max security - Iranian python community -- www.python.ir If your users can run it, they can steal it. You can't keep your code secure if you run it on their systems. -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding style
Or even just: lst = [] ;-) Indeed. I'd say the second one. Empty lists are not false. They are empty. Long live dedicated boolean data types. -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding style
dwelch91 wrote: tac-tics wrote: I'd say the second one. Empty lists are not false. They are empty. Long live dedicated boolean data types. Uh, no, empty lists are False in a boolean context: http://docs.python.org/lib/truth.html -Don Perhaps I should have specified it like this: empty_list = [] empty_list is not False True I'm well aware that both of these snippets does the same thing. I'm just spouting my opinion that lists and integers are not tests, and in an ideal world (Java??? X-) if statements support only boolean types. DISCLAIMER: I do not promote the use of Java. -- http://mail.python.org/mailman/listinfo/python-list
Re: range() is not the best way to check range?
Grant Edwards wrote: for pete's sake use the comparison operator like god intended. if 0 = i = 1: I'm assuming you used Python's compound comparison as opposed to the C-style of and'ing two comparisons together to emphasize the fact it is god's chosen way of doing this ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: {} for set notation
Nick Vatamaniuc wrote: I really like the set notation idea. Now that sets are first class citizens along with dicts, lists and tuples I think they should be used when it makes sense to use them In actual usage, though, how often is it strictly required one uses a set over a list? It is similar to how queue and stack are not in the default namespace. Unless you really need to ensure no one is allowed to make random access changes to your data, a list with push and pop is really all you need. I beleive the same applies in regards to sets. -- http://mail.python.org/mailman/listinfo/python-list
Full splitting of a file's pathname
I know about os.path.split(), but Is there any standard function for fully splitting a file's pathname? A function that is the opposite of the os.path.join() function? For example: ret = myster_function(./foo/bar/moo/lar/myfile.txt) print ret ['.', 'foo', 'bar', 'moo', 'lar', 'myfile.txt'] In the meanwhile, I'll do this by hand. I'm just curious if there is a standard way to do this. -- http://mail.python.org/mailman/listinfo/python-list
Re: function that modifies a string
Diez B. Roggisch wrote: Of course, another right way would be to have mutable strings in Python. I understand why strings need to be immutable in order to work with dicts, but is there any reason why (hypothetical) mutable strings should be avoided in situations where they aren't needed as dictionary keys? Python has mutable lists and immutable tuples, mutable sets and immutable frozen sets, but no mutable string type. What's wrong about arrays of chars? Arrays of chars are dangerous. If you insist, use Python lists of Python chars (strings of length 1). If you really want a mutable string type, there's nothing in python that keeps you from writting one yourself. You just have to be more careful than you would be in C++, because your MutableString type would always be passed by reference to functions, and so you'd have to be very careful to copy it unless you want weird, unfindable bugs to crop up in your program. -- http://mail.python.org/mailman/listinfo/python-list
PIL - Transparency Nightmares
I'm trying to make a simple script which attaches watermarks to every image in one directory and saves the output image to another. However, while I understand (in theory at least) what I need to be doing, I can't figure out where to go from here. First of all, I have a watermark image and a list of small images around 120px squared. The watermark uses alpha transparency, so the background is transparent and the anti-aliased text is partially transparent. For each image, I crop the watermark to the same size as the image. Now all I need to do is paste the watermark over the old image with respect to its transparency. I've tried Image.blend(), Image.composite(), and im.paste(), but none of them seem to do exactly what I want. What am I missing here? -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL - Transparency Nightmares
I RTFM harder, and found that paste with an image mask (using the watermark as the mask) does the trick. -- http://mail.python.org/mailman/listinfo/python-list
Re: function that modifies a string
What's wrong about arrays of chars? Arrays of chars are dangerous. If you insist, use Python lists of Python chars (strings of length 1). Why are they more dangerous than a self-written mutable string? I didn't say that. I meant that arrays in the C++ sense are dangerous. If you really want a mutable string type, there's nothing in python that keeps you from writting one yourself. You just have to be more careful than you would be in C++, because your MutableString type would always be passed by reference to functions, and so you'd have to be very careful to copy it unless you want weird, unfindable bugs to crop up in your program. I don't buy that. You are right about the dangers - but I fail to see where C++ gives you any protection from these pitfalls. And what disqualifies an array of characters in python that exists and has all the methods I can think of for a mutable string. C++ offers pass by value options. That makes it so you never need to worry about messing up data that doesn't belong to you unless you explicitly pass by reference. Python doesn't do this for you. Thus, a mutable string class in Python requires a great deal more care since you need to make copies of every string in every function in order to prevent changes in one object's string from affecting another. -- http://mail.python.org/mailman/listinfo/python-list
Re: free python hosting!
I provide the link below with the conditions that you don't put spaces between your sentences and the periods which terminate them. http://wiki.python.org/moin/PythonHosting -- http://mail.python.org/mailman/listinfo/python-list
Re: array of array of float
Use nested list comprehensions: matrix = [[0.0 for x in xrange(n)] for y in xrange(m)] This is similar to float matrix[m][n] in C. All cells are independent of each other in doing this. -- http://mail.python.org/mailman/listinfo/python-list
Re: first book about python
Philippe Martin wrote: I don't know, if I were the genious that made up Python I would not believe in any bible (small b) Take it to alt.religion please. I want to learn python. I plan to buy a book. I always find printed material more convenient than reading on-line tutorials. I had the same problem as you. I heard lots of good things about Python, but was unable to sit myself down in front of my computer long enough to learn it. So I picked up a copy of Learning Python and read the entire thing in a night. http://www.amazon.com/gp/product/0596002815/ref=pd_bxgy_img_b/002-4705377-6120028?ie=UTF8 I'm sorry I can't really do a comparison between different books, this being the only one I bought, but it got me to the point where I could start playing with code and reading the online documentation (which is superb). Coming from a relatively strong background in Java and C++, this book was very easy to digest. The book is not a teaching programming book, so unless you have experience in at least one real language programming language, it might not be worth your time. My only complaint about this book is the confusing way it presenting Python's OOP model and the way they present for loops (they make it sound like for loops are 100 times slower than in Java or C++... They don't get the actual point across effectively, that they are just different.) -- http://mail.python.org/mailman/listinfo/python-list
Attaching functions to objects as methods
Python is a crazy language when it comes to object versatility. I know I can do: class test: ...def __init__(self): ... pass x = test() def fun(): ... print fun x.fun = fun x.fun() fun However, experimenting shows that these attached functions are not bound to the object. They do not accept the 'self' parameter. I want to know how one goes about doing that. How do I bind a function to an object to act as if it were a method? It looks like the classmethod() built-in looks *similar* to what I want to do, but not quite. Any help would be awesome =-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Attaching functions to objects as methods
Functions are descriptors[1], and their __get__ method is used to bind them to a particular instance:: Thank you muchly. -- http://mail.python.org/mailman/listinfo/python-list
Re: Attaching functions to objects as methods
Experimenting, I found that x.fun = lambda: fun(x) works as well. Any comments on this way? -- http://mail.python.org/mailman/listinfo/python-list
Re: defining multi dimensional array
bruce wrote: hi... basic question.. how do i define a multi dimensional array a[10][10] I find that list comprehensions are useful for this. [ [None for x in xrange(10)] for y in xrange(10)] You could easily write a wrapper for it to clean the syntax a bit. -- http://mail.python.org/mailman/listinfo/python-list
Re: print shell output in a file
It sounds like you want to use print If you have an open object with a write property, you can do print thefile, mystring and Python will simply redirect the output to thefile instead of sys.stdout. -- http://mail.python.org/mailman/listinfo/python-list
Re: Chapter 9 Tutorial for Classes Not Working
x = MyClass xf = x.f while True: print xf() Python has some VERY nasty gotchas concerning parenthesis (or lack there of). In the first line here, you assign x = MyClass. That means x becomes an alias for the class MyClass. not an object like you intended. Look back at the tutorial. You simply left of the parenthesis. Another time this may cause you headaches is with functions: #!/usr/bin/python def fun(): print Hello world! if __name__ == __main__: fun Run this script, and you will get no output at all. Forgetting the () on the end of fun on the last line makes the difference between executing the function and returning a reference to it. -- http://mail.python.org/mailman/listinfo/python-list
Re: list comprehension
a wrote: can someone tell me how to use them thanks sigh... You do a google on them: http://docs.python.org/tut/node7.html#SECTION00714 They are the program equivalent of set builder notation in math: {x | x in S} would be written [x for x in S] in python. -- http://mail.python.org/mailman/listinfo/python-list
Freezing Python with jythonc
I've got a nice jython application that I wish to freeze. After playing around with flag settinsg on jythonc, I managed to get it to compile without warnings or errors, but when I try to run my main class file, I keep getting the error: Exception in main thread, NoClassDefFoundError. When I just use java gui (gui.class is the bytecode file), it flags an error on org.python.core.PyObject. If add jython.jar to the classpath, it gives me the same error on my gui instead of PyObject. I figured that testing out jythonc on such a large project, I should have expected it to fail. So I wrote a one-liner hello world print Hello world saved it to test.py in a different directory, and tried again to jythonc it. However, I keep getting the same errors. What am I doing wrong? -- http://mail.python.org/mailman/listinfo/python-list
Re: Freezing Python with jythonc
What am I doing wrong? Nevermind, I figured it out. -classpath overwrites the classpath not augments. I needed to use -classpath .;jython.jar and it works fine. -- http://mail.python.org/mailman/listinfo/python-list
Re: Opening a file with system default application
BartlebyScrivener wrote: don't know Jython, but in Python, I think you want: import os os.system('mytextfile.txt') Whatever file you reference should open in the application associated with it. At least that's the way it works on Win XP rd I didn't think about that. It would probably break like mad under *nix that fine. This will solve my issue. Thanks =-) Even still, does anyone know if there is a more platform indepedent way to do this? -- http://mail.python.org/mailman/listinfo/python-list