proposal: Ellipsis in argument list
Dear All, I have an idea that the Ellipsis object could be used in function calls. The "..." syntax should automagically turn into an Ellipsis positional argument. def f(*args): ext_args = [] for i, a in enumerate(args): if a is Ellipsis: ext_args.extend([x for x in range(args[i-1]-1, args[i+1])]) else: ext_args.append(a) return ext_args Calling it for the above example specifically: >>>f(34, ..., 43) [34, 35, 36, 37, 38, 39, 40, 41, 42, 43] That might be useless or someone might say it is confusing, but I think it would be relatively easy to implement and a nice little syntactic "sugar". Best regards, Szabolcs Blaga -- http://mail.python.org/mailman/listinfo/python-list
Re: destructor not called
On Sep 28, 6:00 pm, Marcin201 <[EMAIL PROTECTED]> wrote: > I have a class which uses a temporary directory for storing data. I > would like that directory to be removed when the class is no longer > used. I have tried removing the temporary directory from the class > destructor, however, it was never called. The RAII (Resource Acquisition Is Initialization) pattern is not applicable to Python since the language concept is not suitable for it. The __del__ is not a genuine destructor. In your case it might not be performed when you expected it because there were still references left around to the object. You must take care to break those references. However, you can apply the EAM (Execute Around Method) pattern in Python to achieve the same effect. You can apply the EAM pattern with help of the `with' statement: with Foo() as a: # work with `a' In this case you must implement methods __enter__ and __exit__ instead of __init__ and __del__. The method __enter__ must return an instance of Foo. You can achieve the same effect with try-finally block as well: a = Foo() try: # work with `a' finally: # make `a' remove directories Best Regards, Szabolcs -- http://mail.python.org/mailman/listinfo/python-list
Re: Feature suggestion: sum() ought to use a compensated summation algorithm
On May 5, 12:24 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: > Szabolcs <[EMAIL PROTECTED]> wrote: > > On May 5, 9:37 am, Szabolcs Horvát <[EMAIL PROTECTED]> wrote: > >> Gabriel Genellina wrote: > > >> > Python doesn't require __add__ to be associative, so this should > >> > not be > > used as a general sum replacement. > > >> It does not _require_ this, but using an __add__ that is not > >> commutative and associative, or has side effects, would qualify as a > >> serious misuse, anyway. > > > Sorry, I meant associative only, not commutative. > > Unfortunately an __add__ which is not associative is actually perfectly > reasonable. Well, 'reasonable' is a subjective notion in this case :-) I have never seen a non-associative use of the plus sign in maths, so I would tend to take associativity for granted when seeing a + b + c in code, therefore I would avoid such uses. (Multiplication signs are a different story.) Of course others may feel differently about this, and technically there's nothing in the way of using a non-associative __add__! :) > For example you could have a Tree class where adding two trees > returns a new tree so (a+b)+c gives you: > > . > / \ > . c > / \ > a b > > but a+(b+c) gives: > > . > / \ > a . > / \ > b c -- http://mail.python.org/mailman/listinfo/python-list
Re: Feature suggestion: sum() ought to use a compensated summation algorithm
On May 5, 9:37 am, Szabolcs Horvát <[EMAIL PROTECTED]> wrote: > Gabriel Genellina wrote: > > > Python doesn't require __add__ to be associative, so this should not be > > used as a general sum replacement. > > It does not _require_ this, but using an __add__ that is not commutative > and associative, or has side effects, would qualify as a serious misuse, > anyway. Sorry, I meant associative only, not commutative. -- http://mail.python.org/mailman/listinfo/python-list
Re: Feature suggestion: sum() ought to use a compensated summation algorithm
Gabriel Genellina wrote: Python doesn't require __add__ to be associative, so this should not be used as a general sum replacement. It does not _require_ this, but using an __add__ that is not commutative and associative, or has side effects, would qualify as a serious misuse, anyway. So I think that this isn't a real disadvantage (it can always be documented that sum() expects __add__ to have these properties). But you are right that summing floats with a requirement of high precision is a quite specific use case, so there are no serious arguments to do this, either. -- http://mail.python.org/mailman/listinfo/python-list
Re: Feature suggestion: sum() ought to use a compensated summation algorithm
Duncan Booth wrote: Szabolcs Horvát <[EMAIL PROTECTED]> wrote: I thought that it would be very nice if the built-in sum() function used this algorithm by default. Has this been brought up before? Would this have any disadvantages (apart from a slight performance impact, but Python is a high-level language anyway ...)? There's a thread you might find interesting: http://groups.google.com/group/comp.lang.python/browse_thread/thread/9eda29faf92f532e/027cef7d4429aa3a In that thread I suggested that Python ought to implement sum by adding together each pair of values, then each pair of results and so on. This means that for input values of a similar magnitude the intermediate results stay balanced. The implementation doesn't actually do all the first level sums first, it builds up a stack containing the sum of 2^k, 2^(k-1)...2 values. Also it works for other types as well, and for strings or lists has the advantage of minimising the number of large string or list concatenations. If you follow that thread far enough you'll find a post by Jussi Salmela which shows that summing adjacent pairs performs as well as Kahan summation (he says 'almost as good' but in fact the only time they get different results the 'correct' answer is 50.05 and Kahan and sumpairs get the two nearest representable results either side: 50.048 and 50.054 respectively). I never did get round to re-coding my sumpairs() function in C, I would be interested to see just how much overhead it introduces (and I suspect it would be faster than the existing sum in some cases such as for lists). Thanks for this link! Though some of the thread is missing, it was an interesting read. This sounds like a very good idea: it is more generally applicable than the Kahan summation because it does not require subtraction/negation, so it would work with user-defined types, too. While now I am convinced that using Kahan summation by default is not such a good idea, I cannot see any serious disadvantages/problems with pairwise summation! -- http://mail.python.org/mailman/listinfo/python-list
Re: Feature suggestion: sum() ought to use a compensated summation algorithm
Arnaud Delobelle wrote: sum() works for any sequence of objects with an __add__ method, not just floats! Your algorithm is specific to floats. This occurred to me also, but then I tried sum(['abc', 'efg'], '') and it did not work. Or is this just a special exception to prevent the misuse of sum to join strings? (As I said, I'm only an occasional user.) Generally, sum() seems to be most useful for numeric types (i.e. those that form a group with respect to __add__ and __neg__/__sub__), which may be either exact (e.g. integers) or inexact (e.g. floating point types). For exact types it does not make sense to use compensated summation (though it wouldn't give an incorrect answer, either), and sum() cannot decide whether a user-defined type is exact or inexact. But I guess that it would still be possible to make sum() use compensated summation for built-in floating point types (float/complex). Or, to go further, provide a switch to choose between the two methods, and make use compensated summation for float/complex by default. (But perhaps people would consider this last alternative a bit too messy.) (Just some thoughts ...) -- http://mail.python.org/mailman/listinfo/python-list
Feature suggestion: sum() ought to use a compensated summation algorithm
I did the following calculation: Generated a list of a million random numbers between 0 and 1, constructed a new list by subtracting the mean value from each number, and then calculated the mean again. The result should be 0, but of course it will differ from 0 slightly because of rounding errors. However, I noticed that the simple Python program below gives a result of ~ 10^-14, while an equivalent Mathematica program (also using double precision) gives a result of ~ 10^-17, i.e. three orders of magnitude more precise. Here's the program (pardon my style, I'm a newbie/occasional user): from random import random data = [random() for x in xrange(100)] mean = sum(data)/len(data) print sum(x - mean for x in data)/len(data) A little research shows that Mathematica uses a "compensated summation" algorithm. Indeed, using the algorithm described at http://en.wikipedia.org/wiki/Kahan_summation_algorithm gives us a result around ~ 10^-17: def compSum(arr): s = 0.0 c = 0.0 for x in arr: y = x-c t = s+y c = (t-s) - y s = t return s mean = compSum(data)/len(data) print compSum(x - mean for x in data)/len(data) I thought that it would be very nice if the built-in sum() function used this algorithm by default. Has this been brought up before? Would this have any disadvantages (apart from a slight performance impact, but Python is a high-level language anyway ...)? Szabolcs Horvát -- http://mail.python.org/mailman/listinfo/python-list
Re: c interfacing in 2.5
Diez B. Roggisch wrote: > ctypes is for C. Where it is great to use. if you need simple wrappers then swig and ctypes are both good since they can generate it for you pyrex is also good for wrapping and for writing c extension code > If you need C++-wrapping, I recommend SIP. i recommend py++ for wrapping c++ -- http://mail.python.org/mailman/listinfo/python-list
Re: pythonesque constructs for c++
Josh wrote: > One of the best features of python is its ease of use, and the ease of use > of its modules. Modules like os, os.path, and datetime are invaluable! > > Does anyone know of analagous c++ libraries? It seems to me that most of the > functionality of these modules could easily be replicated in c++. Before I > go about doing that, I was just wondering if anyone knows if they already > exist? Check out Boost. http://www.boost.org/ http://www.boost.org/libs/filesystem/doc/index.htm http://www.boost.org/doc/html/date_time.html -- Szabolcs -- http://mail.python.org/mailman/listinfo/python-list
Re: compiling python and calling it from C/C++
Russ wrote: > Is it possible to compile python code into a library (on unix), then > link to it and call it from C/C++? If so, where can I learn how. > Thanks. not really but you may want to look into these: http://codespeak.net/pypy http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/ http://sourceforge.net/projects/shedskin/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Bragging about Python
Steve Howell wrote: > --- Georg Brandl <[EMAIL PROTECTED]> wrote: > > >> > > >> 15 small programs here: > > >> > > >> http://wiki.python.org/moin/SimplePrograms > > >> > > > > > > IMHO a few python goodies are missing there. > > > > "It's a Wiki." ;) > > > > Yes indeed. Please feel free to add to the page, or > make your own fork. See link above. the title of a program shouldn't be part of the code (or it should at least start with #) sorry i'm too lazy now to fix it, but imho it needs nicer layout to be used as 'bragging about python' site btw nice idea a good example worth a 100 pages of documentation -- http://mail.python.org/mailman/listinfo/python-list
Re: Bragging about Python
Cameron Laird wrote: > In article <[EMAIL PROTECTED]>, > Mathias Panzenboeck <[EMAIL PROTECTED]> wrote: >def fib(): >generation, parent_rabbits, baby_rabbits = 1, 1, 1 >while True: >yield generation, baby_rabbits >generation += 1 >parent_rabbits, baby_rabbits = \ > baby_rabbits, parent_rabbits + baby_rabbits > > for pair in fib(): > if pair[0] > 100: > break > print "Generation %d has %d (baby) rabbits." % pair > > as more appealing to non-Pythoneers. I'm still suspicious about > how they're going to react to itertools.islice(). Now, though, > I've begun to question my own sense of style ... actually i don't like when a tutorial uses over complicated cute names if the context is obvious (fibonacci) then we don't need to add 'parent_rabbits' and such identifiers eg i find more readable and clear the following: def fib(): a, b = 0, 1 while True: yield a a, b = b, a + b for (n, fn) in enumerate(fib()): if n > 100: break print "F[%d] = %d" % (n, fn) ymmv -- http://mail.python.org/mailman/listinfo/python-list
Re: url to image
[EMAIL PROTECTED] wrote: > just wondering are there any snippets out there where you can convert > a url to an image using python you mean render a webpage as an image? does not sound a simple task maybe you can use oss web rendering engines like gecco, khtml or webcore -- http://mail.python.org/mailman/listinfo/python-list
Re: Graph plotting module
Viewer T. wrote: > Is there a python module anywhere out there that can plot straight > line graphs, curves (quadratic, etc). If anyone knows where I can > download one, please let me know. http://matplotlib.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Is PEP-8 a Code or More of a Guideline?
Joe Riopel wrote: > Using camel case instead of the under_score means less typing. I am lazy. > > fooBar > foo_bar camel case makes source code extremely ugly in weird disturbing way YMMV -- http://mail.python.org/mailman/listinfo/python-list
Re: Is PEP-8 a Code or More of a Guideline?
John DeRosa wrote: > +1 QOTW > > >Hey, did you hear about the object-oriented version of COBOL? They call it > >"ADD ONE TO COBOL". actually it is "ADD 1 TO COBOL GIVING COBOL" http://en.wikipedia.org/wiki/COBOL#Aphorisms_and_humor_about_COBOL -- http://mail.python.org/mailman/listinfo/python-list
Re: writing to a file
[EMAIL PROTECTED] wrote: > as i understand there are two ways to write data to a file: using > f.write("foo") and print >>f, "foo". well print will add a '\n' or ' ' if you use ',' after it > what i want to know is which one is faster (if there is any difference there shouldn't be any noticable difference > in speed) since i'm working with very large files. of course, if there > is any other way to write data to a file, i'd love to hear about it other ways: os.system('cat file1 >> file2') or subprocess.Popen or print but sys.stdout = f or ctypes + printf/fputs/.. and probably there are other obscure ways, but the intended way is obviously f.write nsz -- http://mail.python.org/mailman/listinfo/python-list
Re: need advice on building core code for python and PHP
> Is there a way I could code the base (core) code in Python and have > PHP call it? I've really liked using SQLAlchemy and there are other * quick and dirty solution: in a shell: $ python yourscript.py pipe_out in the php script: fwrite(pipe_in, input_data); results = fread(pipe_out, sizeof_results); * simple and nice solution: do not ever use php -- http://mail.python.org/mailman/listinfo/python-list
Re: Lists vs tuples (newbie)
Thanks for all the replies! Phoe6 wrote: > 1) Return values from a function. When you return multiple values > from a function. You store them as a tuple and access them > individually rather then in the list, which bear the danger of being > modified. > Look up the standard library itself and you will find many instances. > > (cin, cout, cerr) = os.popen3('man man') > > If you had the above as list, then you might end up spoiling things > knowingly/unknowingly. Could you please elaborate on this (or give an explicit example how might one do something bad unknowingly when returning multiple values in a list)? Should I think of tuples simply as a safeguard and reminder (because I consciously use them for different thing than lists, as the faq suggests)? Something similar to C++'s "const" (i.e. not strictly necessary but useful for avoiding bugs)? Szabolcs -- http://mail.python.org/mailman/listinfo/python-list
Lists vs tuples (newbie)
I was wondering about why are there both tuples and lists? Is there anything I can do with a tuple that I cannot do with a list? In what circumstances is it advantageous to use tuples instead of lists? Is there a difference in performance? I am still learning Python, so please be gentle ... Szabolcs -- http://mail.python.org/mailman/listinfo/python-list
Re: Numbers and truth values
Alex Martelli wrote: > Maybe somebody assigning a value to True or False is a > common error, but much of my livelihood over the last 10 years has been > about mentoring/coaching programmers in Python, and that's one error I > have *NEVER* observed, so I'd need a lot of empirical evidence to > convince me it's worth adding two more reserved words to Python's > reasonably short list (I feel much the same way about None, by the way). > pychecker, pylint, and friends, are a much better way to detect and warn > about all sort of anomalies of this kind. Yes, I admit that it was a very stupid mistake. (Though I'm not even sure that this is what happened. Next time I should probably sleep on it, and try it again the next day, to avoid posting such a stupid question again.) But note that I was using Python interactively (just experimenting with it). It is very unlikely that someone would write things like True == 2 without any additional context in a real program. (Actually it is unlikely that someone would write this in any circumstance in a real program.) But I still think that it is an inconsistency to allow to redefine a _value_ like True or False (not a built-in function that may have been missing in earlier versions). Saying True = 2 is just like saying 3 = 2. Learning about pylint was very useful (thanks for the advice!) -- it helps in catching those kinds of errors that surface only at runtime in Python programs, but are easily caught at compile time in compiled languages. -- http://mail.python.org/mailman/listinfo/python-list
Re: Numbers and truth values
Steven D'Aprano wrote: > 1 == True > True 0 == False > True 2 == True > False Oh my goodness! Now I also get 2 != True. I really don't know what happened. Most probably this (as a result of mistyping): > True = 2 # DON'T DO THIS!!! 2 == True > True > But shouldn't Python forbid this? Is it possible to get a warning when unintentionally redefining built-in thing? -- http://mail.python.org/mailman/listinfo/python-list
Numbers and truth values
Newbie question: Why is 1 == True and 2 == True (even though 1 != 2), but 'x' != True (even though if 'x': works)? -- http://mail.python.org/mailman/listinfo/python-list
Re: Two syntax questions (newbie)
Thanks for the reply! On Apr 23, 10:55 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > > or define a > > function composition operator for functions that take a single > > argument? > > You could use this: > > def chain(*args): >"""Compose functions (assoc right). >last argument (args[-1]): argument to last function >args[0] .. args[-2]: functions taking a single argument >Returns args[0](args[1](...(args[-2]))(args[-1]) >""" >args = list(args) >data = args.pop(-1) >while args: > fn = args.pop(-1) > data = fn(data) >return data > > import random > items = [random.randrange(100) for _ in range(20)] > print chain(list, reversed, sorted, items) This is already better. Is it possible to define function composition as an operator and have something like ([EMAIL PROTECTED]@sorted)(items) or (list*reversed*sorted)(items) ? > I almost never use backslashes for line continuation. If you have an open > (,[,{ continuation is implicit. If not, usually adding a heading ( is > enough. > That is, instead of > > x = a + b + \ > c - d > > I'd use: > > x = (a + b + > c - d) Thanks! This is very useful. Szabolcs -- http://mail.python.org/mailman/listinfo/python-list
Two syntax questions (newbie)
I used Mathematica for data processing a lot and I got spoiled by its functional programming possibilities. I was drawn to Python because it also allows for a similar programming style (and, more importantly, it has an interactive shell, ipython, and a lot of libraries that are useful to me, like scipy). I am still learning the language, so please be gentle :-) And here comes the first question: Mathematica allows writing result = [EMAIL PROTECTED]@[EMAIL PROTECTED] or even result = data//Sort//Reverse//processData instead of result = processData[Reverse[Sort[data]]] In Python this would be something like result = processData(list(reversed(sorted(data The first two Mma alternatives are both easier to read (especially when part of a bigger expression) and easier to type (an re-type, if working interactively) because I don't have to jump with the cursor to the beginning and end of the expression to insert the brackets when adding another function call. Is there a way to avoid typing all the parentheses in Python? Is it possible to define a different syntax for function calls or define a function composition operator for functions that take a single argument? The second question: Of course Python is not Mathematica and not as friendly with this style as Mma is. Sometimes it forces me to use some temporary variables (e.g. because lines get too long and breaking lines with a backslash is ugly). I like to get rid of these variables as soon as they aren't needed, e.g.: temp = data[:] temp.sort() temp.reverse() result = processData(temp) del temp Is it possible to avoid the explicit del temp? In C/C++ I would simply enclose the piece of code in curly brackets. Is it possible to somehow separate a block of code from the rest of the program and make variables local to it? Of course none of these two things would allow me do to something that I can not already do, but they would make work easier. And I am curious if they are possible. Thanks for your replies in advance, Szabolcs -- http://mail.python.org/mailman/listinfo/python-list
Re: python/C++ wrapper
> Well, pyogre has few problems with maintenance, and new bindings to > Ogre engine was > created using Boost.Python( http://www.ogre3d.org/wiki/index.php/PyOgre ) oh last time i played with pyogre they made a transition from boost to swig :) so they are back again at boost (the problem with boost was the slow recompilation time with all the gccxml parsing and a few other problems which maybe got resolved) > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ thanks for the info this py++ looks promising -- http://mail.python.org/mailman/listinfo/python-list
Re: python/C++ wrapper
> - A c++ program receives a 2D-matrix from python as input and gives a > 2D-matrix as output back to python. pyogre uses swig ogre is a 3d realtime rendering engine written in c++ so there are many matrix manipulation there and also pyogre does not modify the original code cgkit is a computer graphics toolkit written in c++ for python and it uses boost-python and it uses matrices as well if you want matrix manipulations in python then you may want to look into numpy c api -- http://mail.python.org/mailman/listinfo/python-list
Re: Request for a change in the csv module.
> It would be much better to be able to specify an additional > variabel to the Dialect class and change csv. no it wouldn't this is a locale specific problem so it should be handled there -- http://mail.python.org/mailman/listinfo/python-list
Re: What is the best queue implemetation in Python?
> For that purpose I have used the good deque that you can find in > collections in the standard library. It's very good for queues, and > it's a bit faster than regular lists for stacks too. you mean *much* faster (since a list is a reference array so pop(0) is O(n) operation) never use a list as queue if len(queue) > 1 === benchmark $ time ./deque_queue.py 34359607296 real0m0.286s user0m0.264s sys 0m0.016s $ time ./list_queue.py 34359607296 real1m20.915s user1m18.649s sys 0m0.396s === the sources --- deque_queue.py: #!/usr/bin/python2.5 from collections import deque def f(n): sum = 0 queue = deque() for i in range(n): queue.append(i) while queue: sum += queue.popleft() print sum if __name__=='__main__': f(1<<18) --- list_queue.py: #!/usr/bin/python2.5 def f(n): sum = 0 queue = list() for i in range(n): queue.append(i) while queue: sum += queue.pop(0) print sum if __name__=='__main__': f(1<<18) -- http://mail.python.org/mailman/listinfo/python-list
Re: Regex Speed
> Well, just as an idea, there is a portable C library for this at > http://laurikari.net/tre/ released under LGPL. If one is willing to > give up PCRE extensions for speed, it might be worth the work to > wrap this library using SWIG. actually there is a python binding in the tre source with an example python script so it is already done. -- http://mail.python.org/mailman/listinfo/python-list
Re: Recursive calls and stack
[EMAIL PROTECTED] wrote: > Hi, > I have a program which literately finds the object that overlapping a > point. The horizontal and vertical search are called recursively from > inside each other. > ... in case you ever need deeply nested recursion: one solution is to use the already mentioned sys.setrecursionlimit(n) another is to use your own stack dummy example: def fact_recursive(n): if n>0: return fact_recursive(n-1)*n else: return 1 def fact_iterative(n): stack = [] while n > 0: stack.append(n) n -= 1 ret = 1 while stack: ret *= stack.pop() return ret actually you can always rewrite recursion with a stack and iterations note that if you use version >= 2.4, then collections.deque is faster for stack (and especially for queue) data structure than list. -- http://mail.python.org/mailman/listinfo/python-list
Re: f---ing typechecking
Sergey Dorofeev wrote: > Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> (1,)+[1] > Traceback (most recent call last): > File "", line 1, in > TypeError: can only concatenate tuple (not "list") to tuple > >>> [1]+(1,) > Traceback (most recent call last): > File "", line 1, in > TypeError: can only concatenate list (not "tuple") to list > >>> > > Its ugly and boring. what? for me it works fine: >>> (1,)+tuple([1]) (1, 1) >>> [1]+list((1,)) [1, 1] also >>> L=[1] >>> L.extend((1,)) >>> L [1, 1] -- http://mail.python.org/mailman/listinfo/python-list
Re: favourite editor
azrael wrote: > Since i'm new on this forum, and first time meeting a python comunity, > i wanted to ask you for your python editors. > > Im looking for some good python editor, with integrated run function, > without having to set it up manualy like komodo. > I found the pyscripter, and it has all i need, but it's unsatble. > bloated. it crashes when i close an yplication window run by python > from pyscripter. please. tell me a good one with buil in run (<-very > important) and nice gui. if possible to suport projects, code > highlighting, code completition, class browser, python comand line > (>>>), traceback. > > I didn't take a look on vista (and i dont want to), but i hope they > improved the notepad. *sigh* this question arises at least three times a week on this group you can use the googlegroups search function: http://groups.google.com/group/comp.lang.python/search?group=comp.lang.python&q=python+editor+ide&qt_g=Search+this+group also use the python wiki: http://wiki.python.org/moin/IntegratedDevelopmentEnvironments http://wiki.python.org/moin/PythonEditors -- http://mail.python.org/mailman/listinfo/python-list
Re: python linux distro
> ^was(is)^may one day be, but probably not,^ > > From the quoted page: > > """The project is in an early development phase and as of January 2007, > no significant progress was being made due to lack of developer time.[5]""" well actually i managed to boot unununium in qemu so it _is_ an os but obviously there isn't much code and the devs gave up so that's why it _was_ an os project anyway it was not an os about python, but a desktop os with a highly different approach from current os-es they just happen to use a lot of python there were a lot of interesting ideas so the mail archives might be useful for anyone who is interested in os development http://unununium.org/pipermail/uuu-devel/ -- http://mail.python.org/mailman/listinfo/python-list
Re: python linux distro
> Now what would be interesting (and *really* crazy) would be Linux (or > BSD or whatever) distro written almost entirely *in* Python, with the > goal of eliminating as much bash/sh as possible. > > That would be fun. actually there was(is) an os whitch is written "almost entirely *in* Python": http://en.wikipedia.org/wiki/Unununium_(operating_system) (their main site http://unununium.org seems to be down) -- http://mail.python.org/mailman/listinfo/python-list
Re: Best Free and Open Source Python IDE
Srikanth wrote: > Yes, > > All I need is a good IDE, I can't find something like Eclipse (JDT). > Eclipse has a Python IDE plug-in but it's not that great. Please > recommend. > > Thanks, > Srikanth try pida http://pida.co.uk/index.php/Main_Page -- http://mail.python.org/mailman/listinfo/python-list
Re: mplayer bug or python bug?
Marco wrote: > The following code is my test program for control mplayer. > in movies/ there are about 20 movies, the code plays them in circle, > but mplayer will crash silently after a circle, the "sliently" means I > can handle popen2 without except, but no movie. i had some problem with mplayer slave mode too. everything worked ok, but after some movies i got "broken pipe" "caught signal xy" error message on stderr and mplayer quit. mplayer always crashed on the same files and always at the very end (which you normally don't notice since you only want to view 1 file so probably it has nothing to do with slave mode, but buggy mplayer + buggy files) my solution was: check for error and restart mplayer if it crashed (i parsed every output so i knew where are we in the playlist) btw if you just want to use the script to play files in loop, then mplayer has a -loop option as well. -- http://mail.python.org/mailman/listinfo/python-list
Re: C parsing fun
> based on concepts my boss had. To do this I needed to represent C++ > code structure in Python somehow. I read the docs for Yapps, pyparsing > and other stuff like those, then I came up with a very simple idea. I > realized that bracketed code is almost like a Python list, except I > have to replace curly brackets with squared ones and surround the > remaining stuff with quotes. This process invokes no recursion or node yes that's a nice solution sometimes it's not enough though (won't work on code obfuscated with macros) anyway if you need something more sophisticated then i'd recommend gccxml or it's python binding: http://www.language-binding.net/pygccxml/pygccxml.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Python does not play well with others
Paul Rubin wrote: > "George Sakkis" <[EMAIL PROTECTED]> writes: > > > What does "batteries included" mean to you? To me, it means you don't > > > have to install add-ons. > > > > So let's make a 500MB executable and add Numpy, Zope, Django, PIL, > > pretty much everything actually. Even better, make CheeseShop just a > > frontend to a build system that adds and updates automatically > > submitted packages to the core. Problem solved ! . > > Numpy should certainly be included and I think there are efforts in > that direction. There is also a movement to choose a web framework to > include and Django might be a good choice. I think the Zope > maintainers want to keep Zope separate and I think PIL has an > incompatible license... do not do that (1) i love when i can create a minimalistic system think about it this way: what if you want to run python on an embeded/ low resource system? if you want python to do webhosting the solution is _not_ to include every related package look at eg. debian: you can use it for lowresource system, desktop, scientific computation and for webserver as well because of it's package management system --> you can build a min. system and a huge system as well. (2) seriously, python is a programming language and not a flee market (so don't compare it to java or php) unfortunately lots of ppl working on web related stuff think web is the only reason a programming language should exist, which is pretty stupid i don't want a "webmodule" in a stdlib at all. implementing the standards and recommendations should be enough. web in general is a huge and ugly bloat, keep it away from a language core. (3) having a maintained set of modules for every possible problem is nice, but shouldn't be a part of the core lib. eg. numpy, mysql, ssl, pil, ... are not needed in the stdlib since most of the programming tasks don't need those they should be maintained separately, with an easy way to find and install them. that's what cheese shop and distutils are for. for me batteries included means i get a clean and consistent stdlib and if i need special functionality i can add modules and extensions easily nsz -- http://mail.python.org/mailman/listinfo/python-list
Re: Python **kwargs ?
johnny wrote: > What is **kwargs mean in python? When you put double **, does it mean > passing by reference? here's a little example: >>> def f(a, *args, **kw): ... print 'a:',a ... print 'args:',args ... print 'kw:',kw ... >>> f(1,2,3,x=4) a: 1 args: (2, 3) kw: {'x': 4} >>> f(a=1,b=2,c=3) a: 1 args: () kw: {'c': 3, 'b': 2} -- http://mail.python.org/mailman/listinfo/python-list
Re: data design
> Hurray for yaml! A perfect fit for my need! And a swell tool! > Thanks a lot! i warn you against yaml it looks nice, but the underlying format is imho too complex (just look at their spec.) you said you don't want python source because that's too complex for the users. i must say that yaml is not easier to use than python data structures. if you want userfriedly config files then ConfigParser is the way to go. if you want somthing really simple and fast then i'd recommend s- expressions of lisp also here is an identation based xml-like tree/hierarchical data structure syntax: http://www.scottsweeney.com/projects/slip/ -- http://mail.python.org/mailman/listinfo/python-list
Re: data design
> The lazy way to do this: have modules that initialize bunches of > objects, attributes holding the data: the object is somehow the row of > the "table", attribute names being the column. This is the way I > proceeded up to now. > Data input this way are almost "configuration data", with 2 big > drawbacks: > - Only a python programmer can fix the file: this cant be called a > configuration file. > - Even for the author, these data aint easy to maintain. > > I feel pretty much ready to change this: > - make these data true text data, easier to read and fix. > - write the module that will make python objects out of these data: > the extra cost should yield ease of use. > > 2 questions arise: > - which kind of text data? > - csv: ok for simple attributes, not easy for lists or complex > data. > - xml: the form wont be easier to read than python code, >but an xml editor could be used, and a formal description >of what is expected can be used. > - how can I make the data-to-object transformation both easy, and able >to spot errors in text data? > > Last, but not least: is there a python lib implementing at least part > of this dream? there is a csv parser and multiple xml parsers in python (eg xml.etree) also there is a ConfigParser module (able to parse .ini like config files) i personally like the python module as config file the most eg if you need a bunch of key-value pairs or lists of data: * python's syntax is pretty nice (dict, tuples and lists or just key=value) * xml is absolutely out of question * csv is very limited * .ini like config file for more complex stuff is not bad but then you can use .py as well. -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I know both the Key c and Ctrl on the keyboard are pressed?
[EMAIL PROTECTED] wrote: > Hi; > How can I know the Key c and Ctrl on the keyboard are pressed? Or how > to let the program press the > > key Ctrl+c automatically? I just want to use python to develop a > script program. > gear depends on where you got your input from and what do you exactly want eg: in a gui app you get input events from the gui toolkit (wx, gtk, sdl/ pygame...) in a console app if you use curses lib then you can use getch() oslt if you want a general solution to get input key events in a simple script then you cannot do that. however Ctrl+C is a special key combination: running python in a unix terminal it raises KeyboardInterrupt exception, imho in a windows cmd promt it raises SystemExit so you can emulate those by using: raise KeyboardInterrupt or raise SystemExit hope this helps -- http://mail.python.org/mailman/listinfo/python-list
Re: Is any python like linux shell?
Brian Visel wrote: > ipython is probably what you're looking for. or http://sourceforge.net/projects/pyshell -- http://mail.python.org/mailman/listinfo/python-list
Re: deepcopy alternative?
> I believe the only thing stopping me from doing a deepcopy is the > function references, but I'm not sure. If so is there any way to > transform a string into a function reference(w/o eval or exec)? what's your python version? for me deepcopy(lambda:1) does not work in py2.4 but it works in py2.5 (in py2.4 i tried to override __deepcopy__ but it had no effect) -- http://mail.python.org/mailman/listinfo/python-list
Re: python 2.3 module ref
> any pointers to a 2.3 module ref? also look at: http://rgruet.free.fr/PQR2.3.html#OtherModules when coding for different python versions i can reccommend this quick ref: http://rgruet.free.fr/ (every language feature is colorcoded according to the version when it was included) -- http://mail.python.org/mailman/listinfo/python-list
Re: [Boost.Graph] graph.vertices property creates new objects
> It seems that the vertices iterator creates new vertex objects every > time instead of iterating over the existing ones. This essentially i don't know much about bgl, but this is possible since vertices are most likely not stored as python objects inside boost > prevents, among other things, storing vertices as keys in a dictionary > since the hashes of the stored and the new vertex differ although they > compare equal. Is this really what's happening, and if so, why ? that sounds bad, fortunately __hash__ can be overriden so even if id() differs hash() can be the same for the same vertex. if __hash__ is not handled then it's a bug in bgl imho. -- http://mail.python.org/mailman/listinfo/python-list
Re: Random passwords generation (Python vs Perl) =)
> while > 1:i=__import__;print''.join(i('random').choice(i('string').letters > +'1234567890')for x in range(8)),;raw_input() > while 1:i=__import__;r='random';print''.join(i(r).choice(i('string').letters +'1234567890')for x in`r`),;raw_input() even shorter: range -> `'random'` :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Random passwords generation (Python vs Perl) =)
> If you really want a hack, here it is: > > while 1:print > ''.join(__import__('random').choice(__import__('string').letters+'1234567890') > for x in xrange(8)),;n=raw_input() > > This is a one-liner (though mail transmission may split it up), no > import statements. If someone can come up with an even smaller version, > feel free to post. :) while 1:i=__import__;print''.join(i('random').choice(i('string').letters +'1234567890')for x in range(8)),;raw_input() same but shorter: i = __import__; xrange -> range (why use xrange? range is faster and simpler for small ranges) n =(not needed) -- http://mail.python.org/mailman/listinfo/python-list
Re: Random passwords generation (Python vs Perl) =)
> Is os.urandom cryptographically strong on all platforms? http://docs.python.org/lib/os-miscfunc.html "The returned data should be unpredictable enough for cryptographic applications, though its exact quality depends on the OS implementation." -- http://mail.python.org/mailman/listinfo/python-list
Re: Random passwords generation (Python vs Perl) =)
> If you don't mind possibly getting a few nonalphanumeric characters: > > import os,binascii > print binascii.b2a_base64(os.urandom(6)) what about file('/dev/urandom').read(6).encode('base64') (oneliner and without import as op requested) -- http://mail.python.org/mailman/listinfo/python-list
Re: Random passwords generation (Python vs Perl) =)
> If you don't mind possibly getting a few nonalphanumeric characters: > > import os,binascii > print binascii.b2a_base64(os.urandom(6)) what about file('/dev/urandom').read(6).encode('base64') (oneliner and without import sa op requested) -- http://mail.python.org/mailman/listinfo/python-list
Re: Graph Data Structures
i haven't read your code, but there are many graph implementations in python. in case you haven't found these yet: http://wiki.python.org/moin/PythonGraphApi if you only want to do some analysis i think you need this one (as it's pretty complete and simple): https://networkx.lanl.gov/ i also recommend Guido's essay to read: http://www.python.org/doc/essays/graphs.html -- http://mail.python.org/mailman/listinfo/python-list
gopherlib deprecated in 2.5
I've just seen that gopherlib is deprecated in python 2.5 http://docs.python.org/lib/module-gopherlib.html we still use this protocol (though there are only few working gopher servers are left on the net) My friend just wrote a standard compliant gopher server (pygopherd had some problems oslt) and it's much better for hierarchycal content sharing than the http (which is overrated and misused in this respect). So i don't really understand why would one remove it from python. It's a friendly, tiny, simple, standard protocol. what is the opinion of the comp.lang.python crowd? -- http://mail.python.org/mailman/listinfo/python-list
Re: Guide to using python for bash-style scripting
python subprocess module docs: http://docs.python.org/dev/lib/node517.html -- http://mail.python.org/mailman/listinfo/python-list
Re: nested functions
On 14 Apr 2006 04:37:54 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > def a(): > def b(): > print "b" > def c(): > print "c" > > how can i call c() ?? Function c() is not meant to be called from outside function a(). That's what a nested function is for: localizing it's usage and prevent cluttering the global namespace Szabi -- http://mail.python.org/mailman/listinfo/python-list
Re: Python2CPP ?
On 4/12/06, Michael Yanowitz <[EMAIL PROTECTED]> wrote: > 2) Efficiency. It is alot quicker to code something in Python. If I can >write it in Python and auto-convert it to C++. I would save time coding. I don't think you will get a more efficient code. The reason is the extremely dynamic nature of python. Almost everything is done at runtime. I think one goal of PyPy is to automatically infer the types of variable, but I don't think they have reached that point, yet. One project you can consider is the psycho python package which generates specialized native code at the price of high memory consumption. > 3) Education. I would learn more about Python, C++, their similarities and > differences. I don't think so. Higher level languages translated to C are not very readable (or at least that's what I have seen) > 4) Other. Just want to know how well Language translators work these days. I > have seen >Fortran2C and Pascal2C translators in the past. Would like to see how > well these >work with Python. Than I think PyPy is the way to go. I have heard about another project with the goal of translating python to high efficiency C++ code but forgot the url. Anybody? Szabi -- http://mail.python.org/mailman/listinfo/python-list
Re: Python2CPP ?
First of all: why do you want to translate pythont to C++? Anyway, this has a C back-end: http://www.pypy.org Szabi On 4/12/06, Michael Yanowitz <[EMAIL PROTECTED]> wrote: > Hello: > >One topic that has always interested me are the Language translators. > Are there any that convert between Python and C++ or Python and Java? > I remember seeing one that converts from Python to or from Perl but couldn't > find it on a quick google search. I did find a Python2C > http://sourceforge.net/projects/p2c/ and I found: > http://www.strout.net/python/ai/python2c.py which are obviously incomplete. >I know there have been many discussions recently regarding C and C++. > I am (or is it - was?) a C/C++ programmer for over 15 years. Just started > with Python as we need to write come quick code in script form which can > be generated and run through an interpreter. >If not could there be a converter from Python to/from Language X and > from Language X to/from C or C++? >In another thread mentioning a decompiler. Perhaps Python to Assembly > and Assembly 2 C? > > Thanks in advance: > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Best IDE for Python?
ide unification effort: http://pyxides.stani.be/ (there are some useful links and it's more recent than the python.org wiki) -- http://mail.python.org/mailman/listinfo/python-list
Re: editor for Python on Linux
pida is a great ide as well: http://pida.vm.bytemark.co.uk/projects/pida -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: FreeImagePy 1.2.2
eg.: .dds (compressed texture file format) widely used in 3d games but not accessible in pil -- http://mail.python.org/mailman/listinfo/python-list
Re: How to run shell commands within python
use subprocess module from subprocess import call call(['cmd', 'arg1', 'arg2'], stdin='...', stdout='...') eg: call(['ls', '-l']) -- http://mail.python.org/mailman/listinfo/python-list
Re: Location of Python modules
LOL a .py program is a module, you can import it: if it is in the sys.path (import modulename). if it sits in a directory that is in the sys.path and the directory also has a __init__.py file (import dirname.modulename / from dirname import modulname). if there is a modulename.pth file in the sys.path containing the path to your .py file. (the current dir is always in the sys.path). if you want to install your module (copy it under the site-packages dir), then you should use distutils module and create a setup.py script the compiled bytecode (.pyc file) is always automatically generated -- http://mail.python.org/mailman/listinfo/python-list
Re: Location of Python modules
/usr/lib/python2.4/site-packages ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Encoding
what about params='some data'.decode('utf8').encode('1250') ? -- http://mail.python.org/mailman/listinfo/python-list
Re: unicodedata.name
thank you (it's so obvious i don't know how i could misunderstand) -- http://mail.python.org/mailman/listinfo/python-list
unicodedata.name
the unicodedata manual sais: " name( unichr[, default]) Returns the name assigned to the Unicode character unichr as a string. If no name is defined, default is returned, or, if not given, ValueError is raised. " what is the difference between "no name defined" and "not given"? eg. '\n' why gives a ValueError? >>> unicodedata.name(u'\n') Traceback (most recent call last): File "", line 1, in ? ValueError: no such name -- http://mail.python.org/mailman/listinfo/python-list
Re: Numarray, numeric, NumPy, scpy_core ??!!
> Basically all I need is vectors and 3x3 matrices. hmm is numpy really efficient for 3x3 (or 4x4) matrices and vectors? IMHO an optimized matrix4x4 class can be much faster (i'm just guessing here) eg cgtypes is a simple c++ implementation with boost-python wrapper: http://cgkit.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for standalone Python
> Is this possible? yes: movable python http://www.voidspace.org.uk/python/movpy/introduction.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Arithmetic sequences in Python
i would love to see a nice, clear syntax instead of for i in xrange(start, stop, step): ... because xrange is ugly and iteration over int sequences are important. we don't need a range() alternative ( [0:10] or [0..10] ) (because no one would ever use range() if there were a nice integer-for-loop) there was a proposal (http://www.python.org/peps/pep-0284.html): for start <= i < stop: ... but in this way you cannot specify the step parameter and it has some problems when used in list comprehension. pep 204 like syntax would be: for i in (start:stop:step): ... it is much nicer than xrange, but probably it has some inconsistency with slicing (eg (:3)=xrange(3), (-3:)=itertools.count(-3), (:-3)=?, (3::-1)=? ) your .. approach: for i in (start, start+step .. stop): ... here start written down twice if it's referred by a name (and if start is a function call it's evaluated twice) imho without a step it looks nice: for i in (start .. stop): ... but a new syntax would be good only if it can entirely replace the old one (which then can be made deprecated). -- http://mail.python.org/mailman/listinfo/python-list
Re: A bug for unicode strings in Python 2.4?
> Thanks. I'll write my own split(). do you want to split character by character? then use list(u'\u9019\u662f\u4e2d\u6587\u5b57\u4e32') -- http://mail.python.org/mailman/listinfo/python-list
Re: Do you have real-world use cases for map's None fill-in feature?
> There are so many varieties of iterator that it's probably not workable > to alter the iterator API for all of the them. i always wondered if it can be implemented: there are iterators which has length: >>> i = iter([1,2,3]) >>> len(i) 3 now isn't there a way to make this length inheritible? eg. generators could have length in this case: >>> g = (x for x in [1,2,3]) >>> # len(g) == len([1,2,3]) == 3 of course in special cases length would remain undefined: >>> f = (x for x in [1,2,3] if x>2) >>> # len(f) == ? IMHO there are special cases when this is useful: L=list(it) here if it has length, then list creation can be more effective (required memory is known in advance) nsz -- http://mail.python.org/mailman/listinfo/python-list
Re: Do you have real-world use cases for map's None fill-in feature?
> There are so many varieties of iterator that it's probably not workable > to alter the iterator API for all of the them. i always wondered if it can be implemented: there are iterators which has length: >>> i = iter([1,2,3]) >>> len(i) 3 now isn't there a way to make this length inheritible? eg. generators could have length in this case: >>> g = (x for x in [1,2,3]) >>> # len(g) == len([1,2,3]) == 3 of course in special cases length would remain undefined: >>> f = (x for x in [1,2,3] if x>2) >>> # len(f) == ? IMHO there are special cases when this is useful: L=list(it) here if it has length, then list creation can be more effective (required memory is known in advance) nsz -- http://mail.python.org/mailman/listinfo/python-list
Re: How to create a script that list itself ?
> But is there a way / a variable that contains the current file in > memory ? yes: import __main__ you can do: import inspect import __main__ print inspect.getsource(__main__) or simply: print open(__file__).read() nsz -- http://mail.python.org/mailman/listinfo/python-list
Re: Try Python update
Hello Thanks for trypython, it's a cool idea I got TryPythonError after an IdentationError and i could not get rid of it (other than refreshing the page): Python 2.4.2 (#3, Dec 16 2005, 23:54:20) [GCC 2.95.4 20020320 [FreeBSD]] on freebsd4 Type "help", "copyright", "credits", or "license" for more information. >>> if 1: ... qwerty IndentationError: expected an indented block (, line 2) >>> a=2 TryPythonError: I couldn't find the prompt, so did nothing >>> 1 TryPythonError: I couldn't find the prompt, so did nothing >>> TryPythonError: I couldn't find the prompt, so did nothing >>> -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
my two solutions (well I wasn't so clever to encode everything in strings instead of numbers, but at least it won't give warnings about non ascii characters): 128: j,seven_seg=''.join,lambda s:j(j(' |_ |'[i>>3*int(c)&b]for c in s for b in(4,2,1))+'\n'for i in(306775170,1060861645,524130191)) 122: seven_seg=lambda s,j=''.join:j(j(' _ _|_| |_ |'[i>>3*int(c)&14:][:3]for c in s)+'\n'for i in(8208,934111592,664455910)) -- http://mail.python.org/mailman/listinfo/python-list
Re: python for with double test
for i in range(0,10): if f!=1: break ... i=0 while i<10 and f==1: ... i+=1 -- http://mail.python.org/mailman/listinfo/python-list
Re: What is unique about Python?
>> identation > >Feh. A red herring. At best, syntactic sugar. At worst, something for >potential adopters to get hung up about. i always ident my code, but in python i don't need to bother with the {} and the ; (which is redundant if i ident anyway) so i like it because i need to type less, and i can read other's code (because of the same layout). >> lightweight oo (no public/protected/private) > >This one is debatable. This is value in private data (and methods). >Fortunately, Python does let you make things private with the >double-underscore syntax. i like it because i need to type (and think) less. When i need to make it clear, which method is private/protected, i can always add a '_' or '__' prefix by convention. >> built-in types (list, dict, str have useful methods) > >Python does come with a good assortment of built-in types and containers, >but most languages these days come with pretty much the same assortment. python has very few built-in types and these are powerful. C++ stl or java.util has more data structures but those are somewhat less usable. Other languages with the same bult-in data types (thinking about perl, php, ruby) always have a little bit differrent behaviour and i always happen to prefer the python way. (nothing can beat python's list + slicing or the ease of creating a dict). -- http://mail.python.org/mailman/listinfo/python-list
Re: Python IDE's
it's a very common question here. try to search for an answer http://groups.google.com/group/comp.lang.python/search?q=python+ide&start=0&scoring=d&; also see http://wiki.python.org/moin/PythonEditors and http://wiki.python.org/moin/IntegratedDevelopmentEnvironments -- http://mail.python.org/mailman/listinfo/python-list
Re: What is unique about Python?
i don't know if they are unique, but my favourite features are: readable and short code (consistent syntax, few keywords) iterpreter (very useful for learning) dir(obj) / vars(obj) (very useful for learning) identation dynamic typing lightweight oo (no public/protected/private) built-in types (list, dict, str have useful methods) iterator protocol generators (yield syntax) list comprehension / generator expression keyword args slicing tuple assignment (unpacking tuple: a,b =1,2) return with multiple values (tuple makes it easy) widespread (it's easy to find a python module for any kind of task) extendible with low-level languages (pyrex/swig/boostpython) crossplatform free nszabolcs -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get started in GUI Programming?
have you tried gtk.MessageDialog ? http://www.pygtk.org/pygtk2reference/class-gtkmessagedialog.html -- http://mail.python.org/mailman/listinfo/python-list
Re: JAPH
charset, modulo, japh = " .JPacehknorstuy", 17, "" s = 69859911049503515105680510599913390885187193231927247909305172858127641629 for n in xrange(2,): if s%n==0: japh += charset[(n - 1) % modulo] s /= n if s==1: break print japh -- http://mail.python.org/mailman/listinfo/python-list
Re: which feature of python do you like most?
> which feature of python do you like most? i cannot chose one but here is my list: iterpreter (i can try out things at once) dir(obj) (using dir() i can learn a new library quickly) identation (code is readable, no need for {} and ;) dynamictyping (no type declaration -> less code to write) lightweight oo (no public/protected/private -> less code to write) widespread (it's easy to find a python module for any kind of task) built-in types (creating list, dict is easy, iterator protocol wins) generators (creating an iterator is easy: replace return with yield) listcomprehension (intuitive and clear way of creating lists) pyrex/swig/boostpython (easily extendible with c/c++) crossplatform (i can write code for my win/linux os) free (yes it's free and it has a reasonable license) comp.lang.python (good questions and even better answers, friendly folks:) -- http://mail.python.org/mailman/listinfo/python-list
Re: PNG processing with only base python install
use pil for image processing in python (http://www.pythonware.com/products/pil/) if pil is not installed then i don't think you can process png files (well at least there is a pure python jpeg decoder: http://davidf.sjsoft.com/files/pyjpeg/) -- http://mail.python.org/mailman/listinfo/python-list
Re: How to translate python into C
python script crashed and you want to debug it? if no trace back provided with the line number where the exception raised, then the crash caused by an extension module (most likely written in C), i don't know howto debug it, but at least you can find the place where the crash occures by adding lots of print statements with debug information. i don't think compiling to c would make it easier. there are python debuggers but i've never used one (these can only debug python scripts not the binary extension modules). pdb builtin module: http://docs.python.org/lib/module-pdb.html nice debugger with gui: http://www.digitalpeers.com/pythondebugger/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to translate python into C
python creates bytecode (like java classes) you cannot translate python directly to c or machine code, but there are some projects you probably want to look into Pypy is a python implemetation in python and it can be used to translate a python scrip to c or llvm code. (large project, work in progress) http://codespeak.net/pypy/dist/pypy/doc/news.html Shedskin translates python code to c++ (not all language features supported) http://shed-skin.blogspot.com/ Pyrex is a nice language where you can use python and c like code and it translates into c code. (it is useful for creating fast python extension modules or a python wrapper around an existing c library) http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Where to find python c-sources
if u just want to browse the code online then use this: http://fisheye.cenqua.com/viewrep/python/python/dist/src *much* nicer than sourceforge cvs viewer nsz -- http://mail.python.org/mailman/listinfo/python-list
Re: Builtin classes list, set, dict reimplemented via B-trees
IMO sorted dict implementation can be useful, eg. one can get an interval: L = D['A' : 'K'] other useful data types: linkedlist queue, stack (well deque can do it efficiently in py 2.4) prioritydict (for graph algorithms) multimap, multiset (i've never used it but it's in the c++ stl) mutable string (kind of list/array of chars, but with string functions) nsz -- http://mail.python.org/mailman/listinfo/python-list
Re: Python linear algebra module -- requesting comments on interface
nice interface, but with 3d apps i prefer cgkit's approach, which has vec3, vec4, mat3, mat4 and quat types with lots of useful functions for 3d graphics (like mat4.looakAt(pos, target, up) or mat3.toEulerXYZ()) there are other libs with similar types and functions: cgkit (http://cgkit.sourceforge.net/) pyogre (http://www.ogre3d.org/wiki/index.php/PyOgre) panda3d (http://panda3d.org/) -- http://mail.python.org/mailman/listinfo/python-list
Re: Possible improvement to slice opperations.
with the current syntax L[i:i+1] returns [L[i]], with nxlist it returns L[i+1] if i<0. L=range(10) L[1:2]==[L[1]]==[1] L[-2:-1]==[L[-2]]==[8] L=nxlist(range(10)) L[1:2]==[L[1]]==[1] L[-2:-1]==[L[-1]]==[9] # not [L[-2]] IMHO in this case current list slicing is more consistent. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for Webscripting (like PHP)
I don't think stdlib offers anything like that The problem with python is it's white space sensible and html is not. However there are some nice solutions: http://www.webwareforpython.org/Papers/Templates/ my favourite is not listed here: http://karrigell.sourceforge.net/ For web development with python i'd rather recommend a complete webframework: http://www.djangoproject.com/ http://subway.python-hosting.com/ http://www.zope.org/ nszabolcs -- http://mail.python.org/mailman/listinfo/python-list
time.clock() problem under linux (precision=0.01s)
I have to measure the time of a while loop, but with time.clock i always get 0.0s, although python manual sais: "this is the function to use for benchmarking Python or timing algorithms" So i tested timer functions capabilities with a short script: import time import os def test_timer_func(func): print 'min time-time: %.10f'%min(abs(func()-func()) for i in xrange(10**5)) print 'max time-time: %.10f'%max(abs(func()-func()) for i in xrange(10**5)) dt = 0.0 loopcount = 0 t = func() while dt==0.0: dt = func() - t loopcount += 1 print "min measurable loop time : %.10f"%dt print 'loopcount while dt==0 :',loopcount print '\n time.clock()' test_timer_func(time.clock) print '\n time.time()' test_timer_func(time.time) print '\n os.times()' ot = os.times test_timer_func(lambda:ot()[4]) My output is: time.clock() min time-time: 0.00 max time-time: 0.01 min measurable loop time : 0.01 loopcount while dt==0 : 2703 time.time() min time-time: 0.019073 max time-time: 0.460148 min measurable loop time : 0.050068 loopcount while dt==0 : 1 os.times() min time-time: 0.00 max time-time: 0.010007 min measurable loop time : 0.009998 loopcount while dt==0 : 2515 So the precision of time.clock is 0.01s under my ubuntu linux system, which means it's not suitable for benchmarking. (i want to benchmark the fps in my pygame+pyode program and it needs at least 0.001s precision) time.time seems much better solution, but python manual sais: "not all systems provide time with a better precision than 1 second" Should i use time.clock or time.time to be more crossplatform? Is time.time ok for windows? (time()-time() != 0.0) nszabolcs -- http://mail.python.org/mailman/listinfo/python-list
Re: Python interpreter error: unsupported operand type(s) for |:
you cannot use | with two dict (dict has no .__or__ method) what are you trying to do? -- http://mail.python.org/mailman/listinfo/python-list
Re: Case Sensitive, Multiline Comments
i found case sensitivity very useful 1. variables can be stored in a dict (think about __dict__, globals()) and dict type should be case sensitive 2. It's necessary when i write short scripts and i use one letter names. (eg. when i playing with linear algebra i always use a,b,c for vectors and A,B,C for matrices). I dont want to think about "more than one letter" names when i run that script only once. And usually this is the case with python (at least when i use it in interpreted mode). 3. i write sometimes: class Foo: ... foo = Foo() and i think it's readable and makes sense. 4. actually i never wanted to use 'foo', 'Foo' and 'FOO' for the same variable and i can't imagine a situation when it's useful. it makes the code less readable so i think the language should force the programmer not to use different names for the same variable. nsz -- http://mail.python.org/mailman/listinfo/python-list
Re: PyGTK vs. wxPython
I forgot to mention in my previous post that the best thing in wxPython is the wxPython demo. It helped me a lot. Browsing through the examples usually faster than browsing through the api doc. About XRCed: I put every static components of the window layout in an xml file with XRCed (not static components: buttons moving around, changing labels ...) Generally my code looks like: import wx import wx.xrc class Frame(wx.Frame): def __init__(self, parent, resource): w = resource.LoadFrame(parent, 'FrameName') self.PostCreate(w) self.SetIcon(wx.Icon('myapp.ico', wx.BITMAP_TYPE_ICO)) ... #lots of init code here ... #event handlers here class App(wx.App): def OnInit(self): resource = wx.xrc.XmlResource('myapp.xrc') self.f = Frame(None, resource) self.f.Show() return True if __name__ == '__main__': app = App() app.MainLoop() -- http://mail.python.org/mailman/listinfo/python-list
Re: PyGTK vs. wxPython
it's not quite true since the latest stable release (2.6.0.0) see the new wx doc (it's generated with epydoc so it's not for C++): http://www.wxpython.org/docs/api/ i used wxPython with XRCed a few times and i liked the way it works (worked under linux and win as well for me) nsz -- http://mail.python.org/mailman/listinfo/python-list
Re: Modifying Call Tips and Intellisense Behavior
have a look at eclipse + pyDev http://pydev.sourceforge.net/ probably it works as you wish -- http://mail.python.org/mailman/listinfo/python-list
Re: On benchmarks, heaps, priority queues
hello nice benchmarks some time ago i've also done some benchmarking i sorted 10 random int with differrent heap implementations, bisect module and with list.sort() I know that heaps are not for sorting, but i tested their performance with sorting back then. my results (sorting algo / time): myheap: (my dummy heap implementation with non-standard comparison) 4.08311503909 heapdict: (my heapdict able to update/delete arbitrary items: heap[key]=value) 5.11007613686 priodict: (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/117228) 4.96804296435 pyheapq: (heapq from py 2.3) 2.37830548956 cheapq: (heapq from py 2.4) 0.375011378197 sort: (list.sort) 0.118014529543 bisect: (bisect module) 3.88104577077 i didn't made many benchmarks but bisect is not so fast with larger amount of data (if i saw well your PQ0 implementation used bisect) it's not scaleable (not even O(nlog(n)) because inserting in a python list is not O(1)) however for small amount of data bisect is the fastest if i used 10 times more data every algorithm scaled well except for bisect: myheap: 50.6242882263 heapdict: 67.465409454 priodict: 71.5018580555 pyheapq: 30.9821771082 cheapq: 6.41072844834 sort: 1.58179548464 bisect: 785.215063469 nsz -- http://mail.python.org/mailman/listinfo/python-list