Problem with running external process
There is a script running continuously which executes an external script in a loop using os.spawnlp(os.P_WAIT, 'extscript.py') function. After several hundred executions (cycles of the loop), the main script gets an exception while trying to start the process. This situation is repeated until the main script is killed. Before it is killed, no other command can be executed - I'm getting the message: -bash: fork: Resource temporarily unavailable. How to properly execute another process from my script? -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with running external process
This is the result of ulimit command on my machine: core file size(blocks, -c) 0 data seg size (kbytes, -d) unlimited file size (blocks, -f) unlimited max locked memory (kbytes, -l) unlimited max memory size (kbytes, -m) unlimited open files(-n) 1024 pipe size (512 bytes, -p) 8 stack size(kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes(-u) 1014 virtual memory(kbytes, -v) unlimited It looks like either pipe size or stack size may be too low. But my main script must be running all the time to collect data so how much should I increase these values to allow infinite executions of external process? -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with running external process
Yes, each time the process is created, it remains. os.waitpid(-1, os.WNOHANG) doesn't work before starting the process for the first time. I tried this: pid = os.fork() if pid == 0: os.execl('ext_script.py','ext_script.py') else: (pid,status) = os.waitpid(pid, 0) It seems to work without leaving zombies. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with running external process
No, no, that wasn't my intention (I'm just not conscious enough what's going on with these fork, exec, spawn.. functions). My parent process should start the child process and go back to it's tasks. Before executing it for the next time the parent should check if the previous child process is done and start it again. Is it what these lines do? os.spawnlp(os.P_NOWAIT,'ext_script.py','') os.waitpid(-1, os.WNOHANG) -- http://mail.python.org/mailman/listinfo/python-list
checking a string against multiple patterns
Hi, here is a piece of pseudo-code (taken from Ruby) that illustrates the problem I'd like to solve in Python: str = 'abc' if str =~ /(b)/ # Check if str matches a pattern str = $` + $1# Perform some action elsif str =~ /(a)/ # Check another pattern str = $1 + $'# Perform some other action elsif str =~ /(c)/ str = $1 end The task is to check a string against a number of different patterns (containing groupings). For each pattern, different actions need to be taken. In Python, a single match of this kind can be done as follows: str = 'abc' match = re.search( '(b)' , str ) if match: str = str[0:m.start()] + m.group(1)# I'm not sure if this way of accessing 'pre-match' # is optimal, but let's ignore it now The problem is that you you can't extend this example to multiple matches with 'elif' because the match must be performed separately from the conditional. This obviously won't work in Python: if match=re.search( pattern1 , str ): ... elif match=re.search( pattern2 , str ): ... So the only way seems to be: match = re.search( pattern1 , str ): if match: else: match = re.search( pattern2 , str ): if match: else: match = re.search( pattern3 , str ): if match: and we end up having a very nasty, multiply-nested code. Is there an alternative to it? Am I missing something? Python doesn't have special variables $1, $2 (right?) so you must assign the result of a match to a variable, to be able to access the groups. I'd appreciate any hints. Tomasz -- http://mail.python.org/mailman/listinfo/python-list
Re: My son wants me to teach him Python
On Thu, 13 Jun 2013, rusi wrote: > On Jun 13, 12:46 am, John Ladasky wrote: > > Hi folks, > > > > My son is 17 years old. He just took a one-year course in web page > > design at his high school. HTML is worth knowing, I suppose, and I > > think he has also done a little Javascript. He has expressed an > > interest in eventually wanting to program 3D video games. [...] > > Some views of mine (controversial!). Not really :-) > > Python is at least two things, a language and a culture. > As a language its exceptionally dogma-neutral. > You can do OO or FP, throwaway one-off scripts or long-term system > building etc > > However as a culture it seems to prefer the OO style to the FP style. > This is unfortunate given that OO is on the down and FP is on a rise. > Some thoughts re OOP: > http://blog.languager.org/2012/07/we-dont-need-no-o-orientation-4.html > > So my suggestion is use some rigorous FPL like Haskell to learn/teach > programming. > After that you can switch to python or some other realistic language. If he (son) learns Haskell, he may as well stay with it, because it's quite decent lang as far as I can tell. And it's compiled, too. I would also consider Racket, which is a Scheme superset. It too, comes with compiler/JIT, plus IDE, plus libraries plus I understand examples from "Structure and Interpretation of Computer Programs", ( http://mitpress.mit.edu/sicp/ ) can be run on it. I have heard some folks are doing real life stuff with it, too and IDE might help beginner a lot (this one is very nice, not just magnified editor). > Note: I have some serious reservations regarding Haskell > http://blog.languager.org/2012/08/functional-programming-philosophical.html > Nevertheless it seems to be the best there is at the moment. Mee too! For this reason I am exploring Ocaml and SML. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com **-- http://mail.python.org/mailman/listinfo/python-list
Re: My son wants me to teach him Python
I've reposted on another list and got this reply. At first I was sceptic a bit, but for the sake of completeness, here goes. Processing language seems to be interesting in its own right. Examples are Java-flavoured, images are ok. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- Forwarded message -- Date: Thu, 13 Jun 2013 16:55:11 +0200 From: Eugen Leitl To: Subject: Re: [info] (comp.lang.python) Re: My son wants me to teach him Python On Thu, Jun 13, 2013 at 04:48:52PM +0200, Tomasz Rola wrote: > No. Definitely not. Programming does NOT begin with a GUI. It begins with > something *simple*, so you're not stuck fiddling around with the > unnecessary. On today's computers, that usually means console I/O > (actually console output, with console input coming along much later). Of course kids are more interesting in things painted on screen, especially if they are colorful, move and make sounds at that. The next step would be a simple, interactive game. Which is why I would synthesize something neat yet simple from http://processing.org/tutorials/ Python is overkill for a kid. Ugh. Some people have just no common sense at all. ___ info mailing list i...@postbiota.org http://postbiota.org/mailman/listinfo/info -- http://mail.python.org/mailman/listinfo/python-list
Re: Calculate Big Number
On Tue, 8 Jan 2013, Nac Temha wrote: > Hello, > How to *quickly* calculate large numbers. For example > >>> (10**25) * (2**50) > 11258999068426240L > Um, Karatsuba multiplication? http://en.wikipedia.org/wiki/Karatsuba_algorithm Or see what GMP folks are doing: http://en.wikipedia.org/wiki/GNU_Multi-Precision_Library Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Common LISP-style closures with Python
On Sat, 4 Feb 2012, Antti J Ylikoski wrote: > On 4.2.2012 12:58, Arnaud Delobelle wrote: > > On 4 February 2012 10:14, Antti J Ylikoski wrote: > > > On 4.2.2012 4:47, Chris Rebert wrote: > > > > Out of curiosity, what would be non-Common-Lisp-style closures? > > > > > > > > Cheers, > > > > Chris > > > > > > > > > I understand that a "closure" is something which is typical of functional > > > programming languages. -- Scheme-style closures, for example. > > > > > > I don't know Haskell, ML etc. but I do suspect that we could create > > > closures > > > in those languages as well. Maybe someone more expert than me can help? > > > > I think what Chris asking is: what is the feature of Common-Lisp > > closures that Python closures share but other languages don't? > > > > I think what he is implying is that there is no such feature. Python > > closures are no more "Common-Lisp-style" than they are "Scheme-style" > > or "Smalltalk-like" or any other language-like. > > > > I would say that Python closures are equivalent with Common LISP closures > (except that LAMBDA is more limited in Python, which is a feature which I > don't like.) > > Do you maybe mean non-Common-LISP-style closures in Python? I cannot > think of any ones. > > kind regards, Andy AFAIK there is only one style for closure, similar to one style for square. There are quite a lot languages implementing closures, and quite a lot try to imitate them, including C with non-standard extension (without using those imitations I cannot say if they are good enough). http://en.wikipedia.org/wiki/Closure_(computer_science) Wrt lambdas, I really like blocks from Ruby (which AFAIK stem from blocks in Smalltalk, not sure if they call them "blocks"). http://lesscode.org/2005/07/12/ruby-colored-blocks-in-python/ http://railsguru.org/2010/03/learn-ruby-procs-blocks-lambda/ I mean, myself I am ok with lambdas (using them in languages where lambda is welcomed and contributing citizen) but blocks in place of lambdas would be nice to have in Python. Introduction of "with" construct was good IMHO, but if one likes coding style relying on passing anonymous pieces of code then Python might not be good choice for this. On the other hand, one can argue that using anonymous code too much is not the best style. I am not sure if extensive use of blocks/lambdas really helps, or if it contributes to "clever" hacks and a source of maintainance pain. So, perhaps it is good to have it in a few different ways - like, Ruby, Python and CL - and experiment with them all. In other words, rather than talking about making Python more like some other language(s) I think it is much better to learn those other language(s). If you'd like to try "unlimited" lambda, you might want to play with Racket, a Scheme superset. Or any other Scheme - it's simple enough to start coding after a day or two of learning (I mean Fibonaccis and Erastotenes sieves, not implementing database or web server). Myself, I would rather have blocks/lambdas and not need them rather than the other way, but that's just me. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: John Carmack glorifying functional programing in 3k words
On Wed, 2 May 2012, jaialai.technol...@gmail.com wrote: > > I'm not a 'Common Lisper' or a 'Pythoner' so I'm not directly or > > personally affected by your retarded and offensive comment. However, who > > the fuck do you think you are to post stuff of this nature? (I believe) > > I'll understand if you've got some sort of psychological issue affecting > > your behaviour. > OP lives out of his car and his main source of income seems to be ad > revenue from his website. > He may be nuts be he is pretty smart and some of the articles he has up > there are worth reading. Still, he has to promote it in some way and by > constantly posting these sorts of things he brings people to his site. > I'm honestly impressed he can survive this way so I am willing to > ignore or maybe killfile his postings and leave him be. He may be smart but obviously hasn't figured out this yet: positive aura drives more people and more permamently towards you. Perhaps he should develop an alter ego that could stand side by side with Dalai Lama and see which one gets more attention. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: John Carmack glorifying functional programing in 3k words
On Thu, 3 May 2012, Chris Angelico wrote: > On Thu, May 3, 2012 at 1:31 AM, Tomasz Rola wrote: > > He may be smart but obviously hasn't figured out this yet: positive aura > > drives more people and more permamently towards you. > > You catch more flies with honey than with vinegar, but who wants to > catch flies? Nah. Who invents such distorted examples only to prove himself right :-). I think you can catch more girls with honey and I'm not sure if I'd like to catch those who prefer vinegar. I think we can make it into some kind of law, say Angelico-Rola Law (of girlscatching), ok? "One cannot catch a girl on honey without catching some flies in the process." Or is it a hypothesis? > I don't see much value in Xah Lee's posts, myself; if he wants to use > LISP and hate Python then he's free to, but why ramble about it on > this list? Well, it is strange because about half of his every post are filled up with f and sh words. Even I feel a bit dirty after reading them (and I swear without giving it much of second thought). Myself, I think I shouldn't try too hard to understand his motives - because one can easily become what one understands. Especially that he doesn't seem to be interested in getting feedback, so chances are there is some force of chaos behind all this. Or his feelings have been hurt by Lisp/Python/Emacs/Perl community (but I couldn't care less, really). Either way, I greet Xah for taking my mind off a subject of writing some piece of code that should have been written a while ago :-). Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: John Carmack glorifying functional programing in 3k words
On Wed, 2 May 2012, Tim Wintle wrote: > On Wed, 2012-05-02 at 17:31 +0200, Tomasz Rola wrote: > > positive aura drives more people and more permamently towards you. Perhaps > > he should > > develop an alter ego that could stand side by side with Dalai Lama and see > > which one gets more attention. > > Really? > > <http://www.google.com/trends/?q=bin+laden,dalai > +lama&ctab=0&geo=all&date=all&sort=0> > > If all you want is attention then "being nice" doesn't seem to be the > best option. > > (of course if you want any respect...) Okay, I should have given the idea a second thought. OTOH, see for yourself: http://www.google.com/trends/?q=xah+lee,dalai+lama&ctab=0&geo=all&date=all&sort=0 Esp. "xah lee does not have enough search volume for ranking"... For me, the conclusion is simple. If he wants to achieve anything, he should mimic Dalai Lama first and only after becoming comparable to the guy, if he's still dissatisfied, only then he should follow OBL. But by all means he should stop being himself. If becoming DL-like is too hard (I believe it is), he might find something even easier, like Miyamoto Musashi, a sword/Zen master. http://www.google.com/trends/?q=miyamoto+musashi,+dalai+lama&ctab=0&geo=all&date=all&sort=0 Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: John Carmack glorifying functional programing in 3k words
On Wed, 2 May 2012, Michael Torrie wrote: > On 05/02/2012 09:31 AM, Tomasz Rola wrote: > > On Wed, 2 May 2012, jaialai.technol...@gmail.com wrote: > >> OP lives out of his car and his main source of income seems to be ad > >> revenue from his website. > > I'm always curious about this sort of thing. Do you know this for a > fact, jaialai.technology? I guess everything we can tell about Xah comes from his own website's "about me" pages :-). > >> He may be nuts be he is pretty smart and some of the articles he has up > >> there are worth reading. Still, he has to promote it in some way and by > >> constantly posting these sorts of things he brings people to his site. > >> I'm honestly impressed he can survive this way so I am willing to > >> ignore or maybe killfile his postings and leave him be. > > > > He may be smart but obviously hasn't figured out this yet: positive aura > > drives more people and more permamently towards you. Perhaps he should > > develop an alter ego that could stand side by side with Dalai Lama and see > > which one gets more attention. > > He appears to have some degree of the Aspergers/autism spectrum > disorder. He quite literally cannot understand how people see him and > why other people don't recognize his genius (both real and imagined). > At least this is one possibility. >From what I have learned, Aspergers know there is a "language" that other people speak that makes them comfortable with each other, but are unable to reproduce it (in a manner similar to, say, Englishman living in France for years, with Frenchmen not very content about his broken accent). OTOH people with autism, even so called Highly Functioning Autism, neither understand there is such a language, nor give a damn (abovementioned Englishman lives in France without realizing guys around him speak differently). About geniuses - I have heard they stand up and deliver, do not rant. Xah has his strong points - they come up on his website, but interaction is probably not one of them. Perhaps Xah (and other guys) have particularly hard time with being attacked by depression and react by ranting? This, or some kind of narcistic delirium. Of course, all of those are just my somewhat-semi-educated guesses. > Others who have crossed this list appear to have aspergers or autism > too, such as Ranting Rick. He pops up occasionally, posts quite > normally and even helpfully, and then lapses back into periods of > ranting about how he can fix python and we all should be doing > something. He refuses to write code to put his ideas into practice, and > berates the list readers for being lazy and unwilling to code this > ideas. Then eventually he disappears for months even years at a time Well? I thought there were some languages similar in form to Python, that could satisfy anybody looking for such form "only with few features different". I don't remember their names - but just staying here and doing like you describe does not look rational. > before resurfacing. I've always been curious to know more about Rick. > Where does he work? How does he live, and what does he do outside of > the python list (he appears to only use his e-mail address on this list). Yep. It is always interesting, in a way. I think if they do not have constant income, they probably live a miserable lifes in some shack, working on hardware in a pre-death state, reanimated and resuscitated and breaking again... Or maybe not. Afterall, ability to resuscitate computer can be sold, too. > Then other times I just worry about coding something cool in python. Or some other language :-) Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Smallest/cheapest possible Python platform?
On Sat, 26 May 2012, Roy Smith wrote: > What's the smallest/cheapest/lowest-power hardware platform I can run > Python on today? I'm looking for something to use as a hardware > controller in a battery-powered device and want to avoid writing in C > for this project. > > Performance requirements are minimal. I need to monitor a few switches, > control a couple of LEDs and relays, and keep time over about a 30 > minute period to 1/10th second accuracy. Nice-to-have (but not > essential) would be a speech synthesizer with a vocabulary of maybe 50 > words. > > The Rasberry Pi certainly looks attractive, but isn't quite available > today. Can you run Python on an Arduino? Things like > http://www.embeddedarm.com/products/board-detail.php?product=TS-7250 are > more than I need, and the $129 price probably busts my budget. If you are on tight budget and depend so much on Python, I'm afraid you should either: a. grow your budget b. try another language For what I know, I wouldn't touch Arduino unless I really had to. The reason for this, I have been spoiled by machines, of which the smallest I wanted to touch had 3mb of ram. Arduinos, with their ram in kilobytes at best, don't qualify as interesting from my point of view. Also, I don't think they are so much attractive price-wise. I would rather buy myself a Beagle Bone, like this one: http://www.adafruit.com/products/513 http://beagleboard.org/bone However, if all that you want is flip some leds, this is huge overkill. For led flipping, Arduino sounds ok, just not with Python-as-we-like-it. Maybe some pseudoPython can be had on it. Myself, I would rather go with one of Arduino's supported languages or assembly. Or Forth. If you land among embedded systems, it's better to speak embeddish or you will feel uncomfortable. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: which one do you prefer? python with C# or java?
On Sat, 9 Jun 2012, Yesterday Paid wrote: > I'm planning to learn one more language with my python. > Someone recommended to do Lisp or Clojure, but I don't think it's a > good idea(do you?) > So, I consider C# with ironpython or Java with Jython. > It's a hard choice...I like Visual studio(because my first lang is VB6 > so I'm familiar with that) > but maybe java would be more useful out of windows. > > what do you think? If you don't know C yet, I second recommendation to learn it. It is a very 70-tish and 80-tish language, but it is still very relevant if you want to call yourself a programmer (rather than a hobbyist, with all credits due to clever genius hobbyists out there). There are things I would rather do in C than in any other language (like, writing a Python interpreter or Linux kernel - wait, what you say they have been written already?). Also, it gives one a way to handtune the code quite a lot (at expense of time, but this is sometimes acceptable), to the point where next choice is assembly (and results not necessarily better)... Later on, since C and C++ share quite a bit, you can gradually include C++ elements into your code, thus writing in a kinda "bettered C" (compiled with C++ compiler), using constructs like "const" to make your programs more correct. And you will learn to not use "new" for variables, which is good thing. However, some C++ constructs include performance penalty, so it is good to not better it too much. Later on, you could choose from the list: - Common Lisp - "nice industrial standard" (depends on one's preferred definition of "nice", of course, as well as "industrial" and "standard") - Racket - Scheme on steroids, with IDE, JIT and crossplatform-ity (I can think of somebody writing Python/Racket to be used in this environment but it is hard to imagine someone doing the other direction, so go figure ;-) http://www.reddit.com/r/programming/comments/i1slm/amazing_tutorial_demonstrating_the_power_of/ http://hashcollision.org/brainfudge/ ) - Haskell or Ocaml - but I have a feeling Ocaml is developing at slower pace now, with many people choosing Haskell (I guess they sometimes curse themselves for this, because behaviour of code in Haskell is a bit hard to predict, sometimes). If you want to delve into Java world, well, I consider Java an unbearably ugly hog. When I was younger and fearless I programmed a bit in Java, but nowadays, the only way I myself could swallow this would be to use some other language on top of it (Scala, Clojure or Kaffe). C# as a - kind of - Java clone from MS, is not really so attractive to me. (Yes, both Java and C# have some merits in some situations, so do COBOL, VB and Fortran but I tend to avoid such situations and thus life gets much simpler). If you would like to bend your mind a little, Racket or Forth or Smalltalk (in a form of SqueakVM) could do the job. Every time I read about Smalltalk and think how Java took over, I mentally weep. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: which one do you prefer? python with C# or java?
On Mon, 11 Jun 2012, Tomasz Rola wrote: > If you want to delve into Java world, well, I consider Java an unbearably > ugly hog. When I was younger and fearless I programmed a bit in Java, but > nowadays, the only way I myself could swallow this would be to use some > other language on top of it (Scala, Clojure or Kaffe). Uhuh, I meant Kawa, not Kaffe: http://en.wikipedia.org/wiki/Kawa_(Scheme_implementation) Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: which one do you prefer? python with C# or java?
On Tue, 12 Jun 2012, Tim Johnson wrote: > I concur, I worked in C and C++ for 12 years. I added C++ later in > my programming life. I don't recommend C++ for single programmers. > - that is to say - 1 coder for 1 codebase. One can do good enough > OOP in ansi C believe it or not, I learned to. > > It is interesting to note that most of linux is written in C, > rather than C++ and is not python as well? You are right, I remember this was explicitly stated somewhere on usenet that Linux kernel was written in object oriented style and AFAIK this is true (based on my own lurking into the source). But I think C++ could and should be used by solo programmers. I just suspect once we get past trivial stuff (defining class hierarchies, using iostreams, containers and STL and the like), things get a little tricky but I cannot say for sure because I am yet to go there. I probably agree C++ should not be used by solo progs writing very big programs, if this is what you mean. I am still researching alternatives, but for such endeavour I would rather choose Haskell or CL. However, I notice, for example, Boost C++ Library and their attempt to recreate some aspects of functional language. This gives me idea about what can be done in C++ - basically, the stuff is so powerfull it seems to almost reach into CL-reserved realms. With limitations, because it's different language, but still impressive for me. http://en.wikipedia.org/wiki/Boost_(C%2B%2B_libraries) http://www.boost.org/doc/libs/1_49_0/?view=category_Function-objects http://www.boost.org/doc/libs/1_49_0/doc/html/lambda.html http://www.boost.org/doc/libs/1_49_0/libs/bind/bind.html OTOH, I guess there are performance penalties. So, it boils down to individual's decision about pricing his own time or machine's time higher than another. Like, hand writing specially optimised versions of some functions or trying to lure compiler into generating them automatically (with templates). But, compilers are improving. In algorithmic contests, C++ is used quite a lot, from what I could see (and some people use Pascal, compile with Free Pascal Compiler, nice thing). BTW, Java folks trie(d|s) to go this way (templates etc) too, but I don't trace their efforts much, so cannot say how they fare(d). > > - Common Lisp - "nice industrial standard" (depends on one's preferred > > definition of "nice", of course, as well as "industrial" and "standard") > I took a hard look at Common Lisp at one time. I got the > impression that the "Common Lisp" is not to Lisp what Ansi C is to > C. > > IOWS, there does remain incompatibilities between different > Common Lisp implementations. Interesting. I play with CL for some time but haven't rammed this particular wall yet. Do you remember more about it? If you can't be specific, perhaps some hint will do. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: which one do you prefer? python with C# or java?
On Fri, 15 Jun 2012, Alexander Blinne wrote: > How do Haskell or Scheme determine when elements are not longer needed? Just like Python, they use garbage collection - in one sentence, if it can be proved the object (not a OO-object, just a piece of data) will no longer be needed, it can be safely deleted - and the code will work as if nothing happened, because the proof said it won't need this data in the future (so you need a right proving technique). Now, the difference is, Scheme (and Lisps AFAIK) and Haskell (and those functional langs I heard of) posess one neat data type, linked list. They also allow for tail-call recursion, which - if one organises one's code properly - means infinite recursion, if one needs it. Some problems are expressed in an elegant and natural manner as linked lists (head to be processed now and rest/tail to be processed later). Such linked lists are ideal fit for tail-call recursion - you process a head and recurse with results and tail in place of original list (thus becoming a next level head+tail list). If no other piece of code stores your current head in a variable (simply speaking), it can be proven that head is no longer needed. Once you call your function recursively, head is waiting to be GC-ed. Your code does not need to worry about this. Last time I checked, Python didn't have linked lists - arrayed lists are nice, but their elements can't be automatically GC-ed (or, this requires very nontrivial GC algorithm), the easiest way I can think would be replacing them with None manually. I'm not sure if del is performance-nice. Also, around the same time, Python couldn't do tail-call, so the whole point of having linked lists was kind of theoretical. Even more cool, with lazy evaluation (like in Haskell) one can generate lists on a fly and process them like they were statically allocated. Say, you only have a 2GB of ram but would like to process 128GB of list, generated ad hoc as your program runs? Like, counting all even numbers less than 2**39 - this is trivial, I know (2**38), but you could run such code with 2GB of ram. Your code processes head and when it recurses with tail, the new head (next number) is generated, so it can be processed. And so on. And thanks to lazy evaluation, you don't need to think about it, this is the job of compiler to organize your program in such way. Yes, you could also run it in a loop or simulate lazy-eval manually (with yield) but the point here is you can have more choice for your algorithm with some languages and in some other languages (Ruby belongs here, too, AFAIK) you don't use recursion (too much) even if you'd like to. Myself, I love more choice, but of course everybody can have his own preferences. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: which one do you prefer? python with C# or java?
On Fri, 15 Jun 2012, Terry Reedy wrote: > On 6/15/2012 1:03 PM, Tomasz Rola wrote: > > > Last time I checked, Python didn't have linked lists - arrayed lists are > > nice, but their elements can't be automatically GC-ed (or, this requires > > very nontrivial GC algorithm), the easiest way I can think would be > > replacing them with None manually. I'm not sure if del is > > performance-nice. > > Python does not come with a linked-list class, but one can easily use tuples > or lists with two items as linked-list cells. One can optionally wrap such > cell in a linked-list class. However, if array lists do the job, which they > usually do, using linked-lists will take more time and space. The problem > being discussed may be a case where they are useful and make it easier to save > space. Yes. I made linked lists in Python few years ago, just to test something. At the time Python was my main algorithmic toy, so I couldn't resist. However, handling the list felt half Pascal-y and half unnatural. Later on, I felt I didn't like cramming everything into arrays and switched to something else. > > Also, around the same time, Python couldn't do tail-call, > > Nonsense. A tail call is a call temporally followed by a return. In CPython > bytecode, it would be a call followed by return. In Python code, it is a call > spatially preceded by 'return'. Any "return f(whatever)", a common operation > is a tail call. Actually I was wrong. http://code.activestate.com/recipes/474088-tail-call-optimization-decorator/ Now I am intrigued because this code just worked a minute ago, on 2.6. Given this was written for 2.4, I was wrong. Definitely something I would like to experiment with a bit. The need for adding decorator takes some joy away but it is interesting. > In practice, should_loop, A, and B will usually be in-line expressions rather > than calls. There may be additional statements after if, else, and while > headers. In while_equiv, move b=start into the body. Else is typically omitted > from the while version, but I prefer it in the recursive version. You see, I spend quite a lot of time playing with concepts etc. Code performance is nice to have, but I prefer to maximize my performance as I write something and move on. If I feel (from my own point of view) something would be nicer to write with recursion, so be it - even though some Common Lisp manual advises to use loops because they are faster. Actually, from what I have tested, this not always is true - both recursion and loops were comparable speed wise in some simple cases I checked. This manual is a bit old, and new compiler had its own say about optimisation, maybe that's the truth behind it. For cases where I really want speed, proper algorithm (if only I can think it) and compilation rule. If algorithm codes better with loops, this is ok. But if it codes better with recursion, this should be ok too, because if I feel better while coding it, I make less errors. > > Even more cool, with lazy evaluation (like in Haskell) one can generate > > lists on a fly and process them like they were statically allocated. > > Python iterators can do lazy evaluation. All the builtin classes come with a > corresponding iterator. This is fine, but I don't mind having more, like the whole language supporting the idea of being lazy. http://stackoverflow.com/questions/265392/why-is-lazy-evaluation-useful > > Yes, you could also run it in a loop or simulate lazy-eval manually (with > > yield) > > There is nothing simulated about yield. Yes, yield is real and not simulated. And one can use it to do tricks with how/when Python evaluates/generates/performs. It is nicer than if I had to write lazy code in, say, C or Pascal, but it doesn't mean one should only use one language rather than choose language according to the task, > Python mostly does what you tell it to do. You just have to learn how to > tell it to do what you want. Well I believe I have already learnt some of it. I am not using Python on a daily basis nowadays, and I am stuck somewhere in 2.x land. To stay in this semicurrent state I read this group and, from time to time, some shorter PEPs. So I think I can tell Python a thing or two, but at the same time I don't want to tell it everything, everytime. :-) I like telling things in a language that sounds better, which depends on what I tell, actually. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: slightly OT -- LaTeX
On Thu, 1 Sep 2011, Ethan Furman wrote: > I asked a question a couple weeks ago about scripting WordPerfect with Python, > and a couple respondents suggested LaTeX was very good. Where would I start > if I wanted to learn about it? > > ~Ethan~ 1. Leslie Lamport, "LaTeX: A Document Preparation System" - I have used it, learning LaTeX in front of a computer, as I wrote my first document in it. I guess this is a very good book on the subject but I have never tried anything else. 2. http://www.latex-project.org/ http://www.latex-project.org/guides/ http://www.ctan.org/ Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: convert script awk in python
On Tue, Mar 23, 2021 at 10:40:01AM -0400, Avi Gross via Python-list wrote: > Alberto, > [...] > I am a tod concerned as to where any of the variables x, y or z have been > defined at this point. I have not seen a BEGIN {...} pattern/action or > anywhere these have been initialized but they are set in a function that as > far as I know has not been called. Weird. Maybe awk is allowing an > uninitialized variable to be tested for in your code but if so, you need to > be cautious how you do this in python. As far as I can say, the type of uninitialised variable is groked from the first operation on it. I.e., "count += 1" first initializes count to 0 and then adds 1. This might depend on exact awk being used. There were few of them during last 30+ years. I just assume it does as I wrote above. Using BEGIN would be in better style, of course. There is a very nice book, "The AWK Programming Language" by Aho, Kernighan and Weinberger. First printed in 1988, now free and in pdf format. Go search. Perhaps it is easier to make the script work rather than rewriting it in another language. Both ways require deep understanding of current code, then with rewrite one also has to make sure new code is drop in replacement for the old. There is very nice documentation to gawk (Gnu AWK). -- Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- https://mail.python.org/mailman/listinfo/python-list
Re: Php vs Python gui (tkinter...) for small remote database app
On Tue, Jun 15, 2021 at 08:39:51AM +1200, dn via Python-list wrote: > On 15/06/2021 07.17, Pascal B via Python-list wrote: > > Hi, > > I would like to know if for a small app for instance that requires a > > connection to a remote server database if php is more suitable than Python > > mainly regarding security. > > Php requires one port for http and one port for the connection to the > > database open. If using Python with a tkinter gui, I understand a small app > > can connect to a database so only one port to the database would need to be > > accessed/open listening to connection. So I would need to worry less about > > security if using Python over Php for something small, like a small python > > app that I give over to users. > > > > Am I missing something in this assertion? > > Yes - or maybe I'm missing the point of your question? > > There are two connections to consider: the database and the GUI. > > > Database: > [...] > > > GUI: > [...] > The (Internet-connected) world runs on TLS. If you wish to > secure/encrypt communications between application and server, this is > accepted by most. If you wish to 'secure' by reducing inter-connections, > then using tkinter and its tight-linkage to Python removes the need for > the (http) web-server. I would rather go with https-based "app", but not necessarily in PHP, if security is to be considered (albeit I am not sure if Python framework would do better). Nowadays, there should be a firewall and server sitting behind it (this is simple description, let us not put load balancing, many servers etc into the mix, or if firewall really helps). So, in case of http(s), there should be more tutorials and hints about doing this well. Browser would do the gui side, http server will talk to the database and to the world, but database itself is secured (hopefully) from outside access. I suspect it is easier to secure web server than db from various kind of 'kacks'. If you go with well rounded Python framework, you can count on its authors carefully thinking about various threats to apps written in it. Sorry, I cannot give any hints - see, I rather deteste browser based apps, so this advice goes against my own liking but one should be objective when giving advices... If you are truly new to this all, I suggest CGI, especially if you want to do some proof of concept prototype, quickly. CGI is quite easy to understand and as long as you are working out communications between your code and DB, I think it simplifies the job a lot. Later on, choose your framework and do the gui. If you go with tkinter, then you will have to do the job already done by authors of web server and web framework, you will have to rethink various problems they gave their thoughts to, but in much shorter time and on your own. -- Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- https://mail.python.org/mailman/listinfo/python-list
Re: Quick way to calculate lines of code/comments in a collection of Python scripts?
On Wed, Oct 05, 2016 at 01:56:59PM -0400, Malcolm Greene wrote: > Looking for a quick way to calculate lines of code/comments in a > collection of Python scripts. This isn't a LOC per day per developer > type analysis - I'm looking for a metric to quickly judge the complexity > of a set of scripts I'm inheriting. > > Thank you, > Malcolm A bit more than what you asked for (and sorry for being late) but I find sloccount quite good. Or at least interesting (computes sloc and some stats about project, given project dir or a single file with code): http://www.dwheeler.com/sloccount/ -- Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- https://mail.python.org/mailman/listinfo/python-list
Re: Quick way to calculate lines of code/comments in a collection of Python scripts?
On Mon, Oct 24, 2016 at 10:03:29AM +0100, Stephen Tucker wrote: > Tomasz, > > How about using the command prompt command FIND /C on each of your source > files as follows: > > FIND/C "#" >NumbersOfLinesContainingPythonComments.dat > FIND/C /V "#" >NumbersOfLinesNotContainingPythonComments.dat > > You would end up with two files each with a column of line counts; > > Import these lines into an Excel Spreadsheet and calculate whatever you > like with them. If this is what you really want to do, then why not. Albeit I would rather go with sh script for this, with ability to process either a directory or single file of Python code. Also, I tend to avoid tools that are "click to work" as much as possible, so for me, this is not good. Using "find/c" or "grep|wc" might look like simple and quick and good solution, but it may soon turn out to be too little, which is why I do not consider sloccount to be an overkill (which you seem to suggest). Especially that OP mentioned something about code complexity, if memory serves. On my system, all it takes is: (as root) apt-get install sloccount and: sloccount alioth_nbody.lsp (or .py or what you like) I guess it is similarly easy to install under other OSes, even under Windows - I would try cygwin installer for this. On the other hand, using Office (or equivalent) only to count lines seems like royal excess. And if I want to calculate, I use lisp interpreter interactively (believe it or not). Spritesheep, like Excel, has some merits but I consider them poor choice for computing anything important (I see no formula, I see no errors). -- Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- https://mail.python.org/mailman/listinfo/python-list
Re: How to install matplotlib in Debian 9
On Mon, Jun 11, 2018 at 03:43:43PM -0300, Markos wrote: > [...] > As I prefer more stability than "updability" I will install the package: > > apt-get install python3-matplotlib > > Best Regards, > Markos Good choice IMHO. The "stable" in Debian is simply "supposed to work without problem". Packages in stable are "old" but in fact they are maintained and updated in case there is a security related bug - so "old" but someone is taking care. For one who is fresh to Python and Debian (as it seems is your case) this means you get a working environment while folks from Debian do their job behind the curtain. I think this is ideal for learning. You do not get the latest software from stable, but you will not need the latest while you learn. Just remember to do this from time to time: aptitude update && aptitude safe-upgrade && aptitude clean or (roughly) equivalent apt-get commands: apt-get update && apt-get -u upgrade && apt-get clean And you should be good. Caveat: Debian (in its stable branch) served me well for many many years until very recently, so my opinion might be a bit biased :-). Stable is very nice for base system, and I always could manually install (i.e. compile from sources) newer version of something on top of this - usually in /opt or /usr/local, so as to keep stable part isolated from my possible errors. I have never used pip, so if you decide so, you may want to make sure it does not mess with the stable part before you run it. The stable part - i.e. the part of the Debian that is maintained with aptitude/apt* commands. Like /usr, /bin, good part of /var etc. HTH -- Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- https://mail.python.org/mailman/listinfo/python-list
Re: don't quite understand mailing list
On Thu, Sep 06, 2018 at 07:10:10PM +, VanDyk, Richard T wrote: > Greetings; > > I sent in a question on how to install robot framework on python 3.7 > using pip (or any other way). None of the commands on the >>> seem > to work for me. I was asked to update the c/c++ runtime which I > don't know what that means. In such cases I ask google, like, literally type "update c/c++ runtime" in it. > I was also asked to subscribe to the mailing list. I did that but > don't want everyone's submitted question to come to me. Judging from what you wrote here, you: a) are going to use Python a bit in a near future b) have a bit to read before you understand what you are doing If both a) and b) are true, then I advice that you stay on list and keep reading whichever mail tingles your curiosity, or even at random. If you do this for long enough, you will finally learn enough to solve your problem(s). Maybe you will even be able to unsubscribe on your very own? HTH -- Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- https://mail.python.org/mailman/listinfo/python-list
Re: ESR "Waning of Python" post
On Thu, Oct 11, 2018 at 06:22:13PM +1100, Chris Angelico wrote: [...] > > There's a huge difference between deciding on using some different > language for a project, and going on a massive ire-filled rant. I agree, in fact this is the kind of posture that I myself implemented in my actions. I have read the article, which was interesting, but am yet to read the comments. I have a question. What is the size of data? I could not spot it. If one had read it into one huge byte array, how many bytes would it be? ESR says he makes a graph of it and there are ~350k objects - i.e. nodes, I assume? How many edges (arcs, lines) for a node, on average? on max? I am curious, as always. Because it is nice of him to rant, but technical/mathematical side of decision making is still a bit too foggy for me and I cannot assess it. -- Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- https://mail.python.org/mailman/listinfo/python-list
Re: How to record the console's content in the interpreter?
On Thu, Aug 22, 2019 at 07:38:54PM -0700, jf...@ms4.hinet.net wrote: > Say I like to record everything showing in the console into a file > after I start a debug session, and stop it when finished. It's not a > console redirection. I still need to see what is going on during the > session. > You may be looking for Eshell, but to be sure you have to try, I have no idea how well this works in Windows. After running your stuff in it, all session is present in Emacs' buffer (if I undestand it correctly) and you can do with a buffer however you please (within limitations of Emacs, which are broad), including save to file: Eshell is a shell-like command interpreter implemented in Emacs Lisp. It invokes no external processes except for those requested by the user. It is intended to be an alternative to the IELM (see Emacs Lisp Interaction) REPL for Emacs and with an interface similar to command shells such as bash, zsh, rc, or 4dos. [ https://www.gnu.org/software/emacs/manual/html_mono/eshell.html ] -- Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- https://mail.python.org/mailman/listinfo/python-list
Re: bug or feature?
beza1e1 wrote: > Coming back from a bug hunt, i am not sure what to think of this python > behaviour. Here is a demo program: > > class A: >def __init__(self, lst=[]): > self.lst = lst > > a = A() > b = A() > b.lst.append("hallo") > print a.lst # output: ["hallo"] > > The point seems to be, that lst=[] creates a class attribute (correct > name?), which is shared by all instances of A. So a.lst ist the same > object as b.lst, despite the fact, that object a is different to object > b. > It is an *instance attribute* by nature, since it does not reside in the class object, but only in its instances. The truth is, that a.lst and b.lst point to the same memory object, so it seems to behave much like the class attribute :) It is no more different from the simple fact, that two variables (attributes) may point to the same memory object, like you see below: a = b = [] a.append("hallo") print b #output: ["hallo"] In fact, it is usually a bad practice to assign instance attributes a reference to the compound variable, existing in an external scope. Example: aList = [] class A: def __init__(self, lst): #no default attribute! self.lst = lst a = A(aList) aList.append("hallo") print a.lst #output: ["hallo"] and your default value (, lst=[]) IS such an variable! The bad thing is, that the value of the instance attribute 'lst' (example above) depends on the external variable, which may be independently modified, thus modifying unexpectedly the instance attribute. The safer approach, of course is to write: class A: def __init__(self, lst): #no default attribute! self.lst = lst[:] #take a copy Summing up, is it an error, or a feature? I would say - a feature. Everyone should be aware, that the argument default values are evaluated once, and the same value (memory object) is reused at each instance creation. Best regards, Tomasz Lisowski -- http://mail.python.org/mailman/listinfo/python-list
Re: non descriptive error
Timothy Smith wrote: > i try to run my app and i get this > > %python DutyShift.py > error > > > thats it. thats the error. mya pp was previously working, and i did make > some fairly large changes to it, but i'd expect a more descriptive > message then just "error". anyidea where i need to start looking? It seems to me, like a result of a "print" statement, exexcuted somewhere (maybe in the except: clause). You may look for lines similar to: print "error" Tomasz Lisowski -- http://mail.python.org/mailman/listinfo/python-list
Re: how to control the mouse pointer with python?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 13 Jan 2005 [EMAIL PROTECTED] wrote: > >What environment? > > It's X. So, for X under Debian, try: apt-get install xwit man xwit It's not python, but you can either use xwit command or read the source code and get knowlegde from it. (hint: -warp, -rwarp options). bye T. - -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:[EMAIL PROTECTED] ** -BEGIN PGP SIGNATURE- Version: PGPfreeware 5.0i for non-commercial use Charset: noconv iQA/AwUBQecSpRETUsyL9vbiEQJsCgCg8tkt/dPJu7pajgJrKsiK6tfz/sEAmgI9 28mUchbUqdzjSwUUvezVRnT5 =XJx5 -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: How to run python script in background after i logout
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 24 Jul 2005, Harlin Seritt wrote: > I have a remote linux server where I can only access it via ssh. I have > a script that I need to have run all the time. I run like so: > > python script.py & > > It runs fine. When I log off ssh I notice that the script died when I > logged off. How do I make sure it stays running? Besides at and cron commands (mentioned by the others), have a look at "nohup", too. Regards, Tomasz Rola - -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:[EMAIL PROTECTED] ** -BEGIN PGP SIGNATURE- Version: PGPfreeware 5.0i for non-commercial use Charset: noconv iQA/AwUBQuP0fhETUsyL9vbiEQINVACfVvgOcWTr3jmA21gJq24DcVHWNmgAn2tY JAt0TM0X67bFlD3wRh9TkVeH =tVam -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: Initializing interactive Python
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 24 Jul 2005 [EMAIL PROTECTED] wrote: > Hi all, > is it possible to enter an interactive session and automatically > do some initialization? > I explain better: > I want that when I start interactive Python on a console (I use Linux) > two command lines be executed automatically: I did this by using python's "-i" option. Under Unix/Linux environment, you can set up a script like this: - cut - cut - cut --- #!/usr/bin/python -i # init interactive session import someutils someutils.init() import sys from blah.blaaah.blah import * print "Hello there" # Now it's ready and shows you a prompt, so you can abuse it freely ;) - --- paste - paste - paste - It should be possible to write similar script under any other sufficiently developed OS. After executing a script, you are presented a prompt from properly (i.e. the way you want it) initialised interpreter. Regards, Tomasz Rola - -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:[EMAIL PROTECTED] ** -BEGIN PGP SIGNATURE- Version: PGPfreeware 5.0i for non-commercial use Charset: noconv iQA/AwUBQuP75RETUsyL9vbiEQKtWgCgpIJS9nWo9tEf01QZACnoyCN5oSgAmgO0 a5+6CQiqEeT+58p/WZgjmlmw =NVnJ -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: catching all exceptions
> Hello, > > I'd like to catch all exeptions and be able to inspect them. > > The simple case: I know which exceptions I'll get: > > # standard textbook example: > try: > something() > except ThisException, e: > print "some error occurred: ", str(e) > > > The not-so-simple case: Handling all other exceptions: > > # nice-to-have: > try: > something() > except *, e: > print "some error occurred: ", type(e), str(e) > > > Well, actually the second statement doesn't even compile... any ideas > why I shouldn't be able to catch "anonymous" exceptions like this, or > whether and how I can (and only overlooked it)? > > > TIA! > > > Kind Regards, > Toni Try this: import sys try: something() except: info = sys.exc_info() ... and you can inspect the tuple info, which contains the exception type, value, and traceback. Best regards, Tom -- http://mail.python.org/mailman/listinfo/python-list
Re: up to date books?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Thu, 18 Aug 2005, John Salerno wrote: > hi all. are there any recommendations for an intro book to python that > is up-to-date for the latest version? > > would reading a book from a year or two ago cause me to miss much? Well, well - and nobody mentioned an online tutorial (if I'm not wrong). What a shame :-). If you feel new to all this, then first go to this page: http://www.python.org/doc/2.4.1/ then locate the Tutorial and give it a try. Maybe it is not very complete and leaves some subjects in the dark, but after reading it you should improve your ability to choose the right printed book from your local store (or wherever you look for new books). After reading the Tutorial, I would start a decent text editor, and pointed it to my local Python install files, like /usr/local/lib/python2.4/ and checked if any *.py file made any sense to me. This would give me some hints about how much I need to learn and on what level. Regards, Tomasz Rola - -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:[EMAIL PROTECTED] ** -BEGIN PGP SIGNATURE- Version: PGPfreeware 5.0i for non-commercial use Charset: noconv iQA/AwUBQwUtaxETUsyL9vbiEQIoEwCfZQm9IHu5wUFrdu7vUqbDAi6APkQAoOOc b7v4+ZFWEyh9nnOfDbJ/BbX0 =Fs7D -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: Help w/ easy python problem
[EMAIL PROTECTED] napisał(a): > Actually, it is not a sin curve i need to plot, it is dots running down > the page in the shape of a sin curve like this > > . > . >. > etc... > Seems, like a homework to me :-) Anyway, use the following hints: math.sin() is your sine function, ranging, from -1.0 to 1.0 inclusively set up a for loop printing the strings containing spaces, and one dot at the appropriate location with: - the appropriate argument increase step between the lines (print statements) - the appropriate scaling of the <-1.0, 1.0> range into e.g. <0, 71>, representing the 72 characters wide lines being printed. Tomasz Lisowski -- http://mail.python.org/mailman/listinfo/python-list
unicode to human readable format
Hi, i'm looking for solution the unicode string translation to the more readable format. I've got string like s=s=[u'\u0105\u017c\u0119\u0142\u0144'] and have no idea how to change to the human readable format. please help! regards, tomasz -- https://mail.python.org/mailman/listinfo/python-list
Re: unicode to human readable format
hello, can I ask you for help? when I try to print s[0] i vane the message: UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128). how to solve my problem, please? regards, t. -- https://mail.python.org/mailman/listinfo/python-list
Re: Fortran (Was: The "does Python have variables?" debate)
On Sun, May 11, 2014 at 07:09:27AM +, Steven D'Aprano wrote: > On Sun, 11 May 2014 01:17:55 -0500, Mark H Harris wrote: > > > On 5/10/14 8:42 AM, Roy Smith wrote: > >> Ars Technica article a couple of days ago, about Fortran, and what is > >> likely to replace it: > >> > >> http://tinyurl.com/mr54p96 > >> > >> > > uhm, yeeah! > > > > 'Julia' is going to give everyone a not so small run for competition; > > justifiably so, not just against FORTRAN. > > That and two hundred other languages. > Given that Fortran is here for almost 60 years and lot of effort has been spent to keep it backwards compatible (AFAIK), I wouldn't hold my breath. Something may look like cool and great, but wait ten years and see if after major language revision you can still (more or less) easily run your existing huge projects with it. Does it require to give another option to compiler or does it require spending hours or weeks deep in the code (possibly introducing subtle bugs, too)? So far, in my opinion, very few languages can stand this test (or perhaps none at all). Strong candidates are C, Fortran, Common Lisp, and unfortunately, Java (I can only talk about those which I happened to use and checked a bit, but not extensively). I'm not really sure about Python, haven't had time/energy to check yet (but going 1.5->2.x was painless to me). > Good languages (for some definition of "good") are a dime a dozen. > Miranda, Rust, Go, D, Ceylon, Coffeescript, F#, Scala, Lua, Erlang, > Eiffel, Ocaml, Haskell, Kotlin, Grovy, Clojure, Dart, Mercury, ML... the > list of "amazing", "astounding" languages is never ending. Very few of > them take over the world, and those that do rarely do so due to technical > excellence. (BASIC, Java, PHP, Javascript ...) ... and Perl... Even if it's not as bad as I sometimes think. BTW, after seeing "@" and "$" in Julia manual, I think I will stay aside for a while. > Some of them, like Haskell, influence other languages without ever > being popular themselves. Interestingly, Haskell developers seem to not care much about old codebases in their own language (but I didn't make systematic research of the subject). I hope others will not be influenced by such attitude :-). Neglecting someone's effort to make working flawless code, forcing people into periodic rewrites of things that used to work, such events always blink red in my head. -- Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- https://mail.python.org/mailman/listinfo/python-list
Re: Fortran
On Mon, May 12, 2014 at 02:42:13AM +1000, Chris Angelico wrote: > On Mon, May 12, 2014 at 2:09 AM, Tomasz Rola wrote: > > Given that Fortran is here for almost 60 years and lot of effort has > > been spent to keep it backwards compatible (AFAIK), I wouldn't hold my > > breath. Something may look like cool and great, but wait ten years and > > see if after major language revision you can still (more or less) > > easily run your existing huge projects with it. > > The Unix pipe system is still working beautifully, and will continue [...] > > But retaining that backward compatibility is a huge cost. Sixty years > ago's hardware wasn't the same as we have today. You can't simply run > the exact same compiler and get the same bytes of output and run them. [...] > > If a language basically says "That code you wrote two years ago? Not > gonna work now", then I'd see that as a big blinking red light. But > "Ten years ago's code will probably work on today's interpreter, > unless it uses as identifiers what's now a keyword, or it might be > unintentionally treading on now-fixed bugs in which case it might have > to be fixed", that's not as big a problem. Yes, you'd need to 2to3 > that old Python 2.3 code to get it to run on Python 3.4, but chances > are it'll run mostly-unchanged on 2.7 (modulo string exceptions, > maybe). I'm cheating a bit by citing Python 2.7, given that it's now > four years old, but it's also going to be supported for a good few > more years. Not sixty, presumably, but a good while. > > ChrisA I can easily agree to your points. Personally I don't really care much about decades-old codes (unless I want to play with them inside some emulator). There was indeed a lot of change in OSes and hardware, and languages should keep up with it, if possible. And the "pipe extention" is one of the things I'd consider - as well as other similar means, like SOAP or REST. However, obsoleting code younger than five years does not feel good to me. AFAIK big projects take years to be written, polished up, debugged and sometimes refactored (during this time they may also be used and go throu their own big version changes), so it is really big pain to see how after all this work someone's decision changes ground under one's feet. As of remark by Marko Rauhamaa, that "Fortran is successful with people who don't know how to program and don't care" - I wrote maybe two Fortran programs so far, both very simple. I tried to obey so called rules, inserted comment lines, checked for return values and issued warnings/errors when needed, didn't use goto excessively (AFAIR), didn't make stupid things like changing index variable inside loop (other than by predefined step in one and only one place, be it by hand or by compiler). For one program I got max points to get (uni course) and for the other I have been presented with a basket of strawberries. Was I successful - or my use of Fortran :-)? OTOH I once had to work with someone else's Java code, a huge class in huge file and I found it too borked to repair so I rewrote from the scratch. Will I write some more code in Fortran - maybe, or maybe not. I don't feel any urgent need to do this. There is still a lot of things I'd like to learn and a day has only so many hours. I consider Fortran a useful tool which may possibly outlive me (but let's wait and see :-) ). As of quality of its users, sure, I consider programming a full time activity and it is very hard to find people who want to be good at it *and* in their supposed domain at the same time. Heck, I keep reading it is hard to find people who would like to be good in anything at all. Perhaps part of the problem is unwillingness to tackle it. I think majority of people would like to do things better, especially if it only requires small changes in behaviour. But they simply don't know there is better way, because nobody cared to tell them or show by example. Or nobody knew there were some people who would have been happy to hear a word of advice. Well, at least it is nice to believe in this. -- Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- https://mail.python.org/mailman/listinfo/python-list
Re: A simple list question.
KraftDiner wrote: > I am trying to implement a two dimensional array. > mylist = [[a,b,c],[d,e,f,c],[g,h,i]] > > So the array is of length 3 here... > So how do I initialize this array and then set each object? > At some point in my code I know there will be 3 lists in the list. > So how do I initialize this list such that I can access them > as elements... like > mylist[1] = [c,f,g] > in random order... > Why not just say: mylist = [[], [], []] since you know, that this array will have a length of 3. Then you can safely use append. I am not quite sure, though, what you mean by accessing the elements in random order. What's the idea behind having mylist[1] = [c,f,g], when the elements c, f, and g are apread across all three internal lists, and at various position within these lists (not necessarily 1, as the mylist index suggests). Tomasz Lisowski -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie: concatenate literals (using jython)
Fredrik Lundh wrote: > [EMAIL PROTECTED] wrote: > > >>I'm using Jython (actually WebLogic WLST), and trying to do something >>really simple. I want to create a string from two function calls and a >>literal, like: >> >> serverport = server.getListenAddress() + ':' + server.getListenPort() >> >>This complains: >> >>TypeError: __add__ nor __radd__ defined for these operands >> >>I've looked at various references, and this seems like the way I'm >>supposed to do this, but I'm obviously missing something. Note that >>"getListenPort()" returns an int. Is that a problem? > > > yes. python's string concatenation operator doesn't convert things nilly- > willy (should "1"+1 be 2 or "11" ?). to convert an object to a string, use > str(obj). see this tutorial section for more info: > > http://docs.python.org/tut/node9.html#SECTION00910 > > > > > You are right, Fredrik, but David is using Jython, so perhaps he tried to mimic the Java language behaviour, where adding ints and strings is perfectly valid :) I admit, though, that I do not know much about Jython apart from the fact, that it is somehow related to Java ... Best regards, Tomasz Lisowski -- http://mail.python.org/mailman/listinfo/python-list
Re: problem adding list values
Dave Hansen wrote: > I think what you want is > >for cr in credlist: > credits += cr > > Which could also be implemented as > >credits = reduce(lambda x,y: x+y, credlist) or even: credits = sum(credlist) Tomasz Lisowski -- http://mail.python.org/mailman/listinfo/python-list
Re: Why it doesn't work?
Lad wrote: > I have a list > L={} This IS a dictionary, not a list. > Now I can assign the value > L['a']=1 > and I have > L={'a': 1} > > but I would like to have a dictionary like this > L={'a': {'b':2}} You need to initialise L['a'] first, before referencing L['a']['b'] So, you need to call first: L['a'] = {} Then you can write: L['a']['b'] = 2 Tomasz Lisowski -- http://mail.python.org/mailman/listinfo/python-list
Re: py vs pyc
Sakcee wrote: > Hi > > I want to know that is .pyc files execute faster than .py files,? since > both are interpreted by python , is there any speedup in using one or > other.? > > e.g. > > what is the difference between runing from cmd "python test.py" and > "python test.pyc" > > > thanks > When running "python test.py" the interpreter will first precompile the test.py source file, and then execute it. When running "python test.pyc", the interpreter will go straight to the execution of the script. Tomasz -- http://mail.python.org/mailman/listinfo/python-list
Re: speeding up Python script
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Wed, 18 May 2005, Luis P. Mendes wrote: > Hi, > > I have a 1000 line python script that takes many hours to finish. It is > running with six inside 'for' loops. > > I've searched the net for ways to speed up the proccess. > > Psyco improves performance around 3% in this case which is not good enough. > > How can I dramatically improve speed? > > I tried to find some tool that converts Python to C automatically but > couldn't. As I don't know C, I think that weave and PyInline for > example are out of the solution. > > I'm using Linux. Maybe this will help you, since you didn't tell what is your python version, I've seen 2-2.5x speed increase by just replacing 2.1 with psyco by 2.3 with psyco. => (1003 3): cat bzz2_* | /usr/bin/time python2.3 somescript.py '2.ada miala mak.ba' | wc -c psyco.full start psyco.full end 7.48user 0.03system 0:07.58elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (436major+358minor)pagefaults 0swaps 1064960 => (1003 4): cat bzz2_* | /usr/bin/time somescript.py '2.ada miala mak.ba' | wc -c psyco.full start psyco.full end 18.27user 0.03system 0:19.00elapsed 96%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (357major+183minor)pagefaults 0swaps 1064960 Regards, Tomasz Rola - -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:[EMAIL PROTECTED] ** -BEGIN PGP SIGNATURE- Version: PGPfreeware 5.0i for non-commercial use Charset: noconv iQA/AwUBQoss9xETUsyL9vbiEQLMDACeKCnkwsegr6pgMEAMvTC3ip0ZCxkAoLJa t/LrsGlMwg0Xu7gJ8hcI2ywK =1aHL -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Strange behaviour of floating point constants in imported modules
Hi, We are distributing our Python application as the short main script (.py file) and a set of modules compiled to the .pyc files. So far, we have always treated .pyc files as portable between platforms, but recently we have discovered an annoying problem. In a module, there is the following code fragment: Deg2Rad = math.pi/180.0 angleEPS = 0.5 angle0B = angleEPS*Deg2Rad which calculates 'angle0B' as the angle of a half of a degree, converted to radians. The module has been compiled on an English Windows XP machine, and then tested on a Polish Windows XP workstation. What was our astonishment, when various exceptions started to be raised on a test machine (no problem on the original English-version Windows XP). We have traced them to the fact, that both angleEPS and angle0B were found to be ZERO (!!!), whereas in reality, angle0B is about 0.008. And this all happened silently, without any error during the import of the module! What's the reason of this error? I start thinking, that it may be related to the fact, that the decimal point on the Enlish Windows XP is the '.' character, and on the Polish one - ','. Is there a good method to avoid this kind of problems? How to make such distributed modules really portable? Thanks in advance -- Tomasz Lisowski -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange behaviour of floating point constants in imported modules
> There is no guarantee at all that a .pyc file is good for any purpose > outside the machine that produced it. In practice, however, you > *should* be able to rely on no surprises if you have the same platform > and the same version of Python; do you? Python 2.3.5 and 2.3.3 on the test machine - it is the same major and minor version of the interpreter. I think it should be fine. The platform - Windows XP on both machines - difference is in the language version of Windows, and in the locale setting of the decimal point ('.' and ',') > > How did you transfer the .pyc files from one box to the other? A > Windows installer? A ZIP file? FTP using text mode? Plain-text > attachments to an e-mail message? E-mailed in a ZIP file >>but recently we >>have discovered an annoying problem. In a module, there is the following >>code fragment: >> >>Deg2Rad = math.pi/180.0 >>angleEPS = 0.5 >>angle0B = angleEPS*Deg2Rad >> >>which calculates 'angle0B' as the angle of a half of a degree, converted >>to radians. The module has been compiled on an English Windows XP >>machine, and then tested on a Polish Windows XP workstation. >> >>What was our astonishment, when various exceptions started to be raised >>on a test machine (no problem on the original English-version Windows >>XP). We have traced them to the fact, that both angleEPS and angle0B >>were found to be ZERO (!!!), whereas in reality, angle0B is about 0.008. > > > What evidence do you have? Have you disassembled the .pyc file on both > boxes and diff'ed the results? Have you computed checksums on both > boxes? I have prepared a 'debug' version of the module, printing out some variables. The printouts on a test machine showed ZERO values, where there should be non-zero ones (0.008). The original machine, where the modules were compiled, showed the correct values. > > >>And this all happened silently, without any error during the import of >>the module! >> >>What's the reason of this error? I start thinking, that it may be >>related to the fact, that the decimal point on the Enlish Windows XP is >>the '.' character, and on the Polish one - ','. > > > This is *extremely* unlikely. Firstly, you are (I understand) talking > about a .pyc file, that was produced on an English Windows box. Even > though the "180.0" and the "0.5" are visible as character strings in > the .pyc file, Python sure doesn't use the locale when it loads a .pyc > file. If I modify the decimal point setting in the Regional Settings in the Control Panel to the dot character '.' - everything seems to work fine. Whenever it is set to the comma ',' - floating point constants, like 0.5 are considered ZERO by the import statement. > > Secondly, even if you are talking about a .py file, Python takes > absolutely no notice of the locale when it compiles the .py file. > Polish programmers write "0.5", not "0,5". Read the language reference > manual, section 2.4.5 -- it uses ".", not "whatever the decimal point > character might be in your locale". If it did depend on locale, you > would need a locale declaration at the top of the file, if one wanted > .py files to be portable internationally; ever seen or heard of such a > declaration? Right! The language syntax requires to use the dot regardless of the locale, BUT the constants are written to the .pyc file in a string form, probably using repr(), WHICH APPARENTLY DEPENDS ON THE LOCALE (!), when the documentation states, that the built-in float(), str() functions are locale-unaware (the locale module provides appropriate functions supporting the locale). > > Thirdly, if the dot was interpreted as something other than a decimal > point, then what? Perhaps assign a tuple (0, 5), or perhaps a syntax > error; zero is achieved under what conditions? No, it is not a problem with possibly using the comma instead of a dot in the SOURCE - there only a dot can be used. That's clear. > > It's more likely that the .pyc file has been damaged somehow. AFAIK > they don't have checksums. Very unlikely. I have made these test also directly, sharing the folder with the .pyc files on the LAN, and running the program from the test machine. Then, the .pyc files were not manipulated at all. > > >>Is there a good method to avoid this kind of problems? How to make such >>distributed modules really portable? > > > Distribute source. Yes, that's an option, but not in this case :) Tomasz Lisowski -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange behaviour of floating point constants in imported modules
> This may be relevant to the problems you're seeing: > > https://sourceforge.net/tracker/?func=detail&atid=305470&aid=774665&group_id=5470 > > The short story, as the tracker item paints it, is that setting > LC_NUMERIC to anything other than 'C' can give results like the ones you > describe---Python itself should never do this, but third parties code > may. > > A web search for python LC_NUMERIC should turn up more about this topic, > probably even some past threads on this mailing list/newsgroup. You've got the point. My code uses wxLocale class from wxPython, and sets the wxLANGUAGE_POLISH locale. After setting this locale, I have added the statement: locale.setlocale(locale.LC_NUMERIC, "C") and everything seems to be normal now. I agree with the comments in the tracker item, that the float, str(), repr() functions should be locale-independent. We have the functions in the locale module, if someone needs the locale-dependent string-float conversions. -- Tomasz Lisowski -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with choice of suitable Architecture
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 28 May 2005, Rob Cowie wrote: [...] > I'm totally new to web programming. I have been looking into the best > way to proceed. CGI is of course an option but it seems slow, clunky > and outdated. Twisted provides a rich architecture but might be > overkill. Nevow seems to be very popular. You know, "slow" from 10 years ago, when this opinion formulated, is not the same "slow" nowadays. Imho, CGI is more straightforward and you can learn it faster. After all, you have not only to make a web output but also some mechanics under the hood - manipulating data etc. BTW, does it have to be stored in xml file? The SQL database could be easier. You can add import and export to/from xml file if this is really needed. Whether it is too slow - well, how many times do you expect people will open this page? I mean, how many times a second? I think this is the most important question when deciding about CGI. You may also consider mod_python: http://www.modpython.org/ > I suspect I could achieve what I want using PHP but I would really like > to get to grip with Python. > > I'm not asking for a comparison of each architecture per se that > seems to be well covered in this group. I would like to know how you > all would set about creating this realtively simple application. Personally, I would rather use Python. Right now, this app may seem to be simple but I think it will grow over time. I'm not very used to PHP but those simple things I did in it make me think Python may help me more as a language, to program a page. PHP is probably more popular in web desing circles, and there are some nice packages written in it, that you can drag from the web and drop into your server, and have all those blogs and webmails the easy way. But for programming, and later on for maintaining such project, I'd rather go with Python. Personal reason: it is cleaner, I like looking at it. Of course you should decide for yourself. I've just pointed to few things but it is up to you to taste both languages and decide which one is better in your case. Regards, Tomasz Rola - -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:[EMAIL PROTECTED] ** -BEGIN PGP SIGNATURE- Version: PGPfreeware 5.0i for non-commercial use Charset: noconv iQA/AwUBQpi3VxETUsyL9vbiEQJm6wCdEuOSUKKf7ZERnHOKvezqU9UJ9+QAn18a GkUjNiMrCaXyQFNU0z7Jj3nq =4LU4 -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there already a Python module to access the USPTO web site?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Sat, 28 May 2005, Terry Carroll wrote: > I have the need to run periodic searches on the US Patent and > Trademark Office website, <http://www.uspto.gov/>. I need a Python > module to do this. Before I reinvent the wheel, I thought I'd check > to see if anyone knew of such a beast. I don't know but if you are determined to have it in Python, perhaps ypu should check MozPython. http://www.thomas-schilz.de/MozPython/README.html - From what it says, mozpython can access Mozilla internals, so I expect it to be able to browse in automatic way. This would left only parsing responces from the server to you. But I had no time to play with it, so if I am wrong, don't beat me too hard. Regards, Tomasz Rola - -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:[EMAIL PROTECTED] ** -BEGIN PGP SIGNATURE- Version: PGPfreeware 5.0i for non-commercial use Charset: noconv iQA/AwUBQpi6fhETUsyL9vbiEQLJcACfRN99KrmM1g+/ZDGRsEeLASRSItMAn3mc APaZtygdsUKsQ57B0ZchfTdp =2wME -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: without shell
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Sun, 12 Jun 2005, km wrote: > hi all, > > can any linux command be invoked/ executed without using shell (bash) ? > what abt security concerns ? To answer your question fast, yes it is possible. Just pull every "bad" block from the OS, and put inside some replacement of your own. But it all depends on what exactly you are going to achieve... 1. Disabling rootkits/shellcodes. Without shell (i.e. bash/sh), you loose lots of functionality and you don't get as much in exchange. If what you want really is to disable execution of rootkits, shellcodes etc, then you need to disable almost every interesting program: perl, python, awk, sh, emacs, vi, web browsers with javascript, java, any compiler or interpreter that is installed, and possibly much more but they don't come to my mind right now. After doing so, you get an os that cannot boot past running /sbin/init and is "secure" because it is useless and can be as well turned off. Sure, you can replace/rename all those programs to have functionality and security but this will not protect your computer for too long. It all depends on how much someone wants to get to you. If there is one such person, the above mentioned steps will not help. It also requires much of work and in the result, you will have an incompatible OS i.e., no compatibility beyond some libraries and kernel stuff. I'm not even sure if it is possible to have full KDE/GNOME without shells. The same with X - its startup runs through few shell scripts before the real /usr/bin/X11/X is exec'd. There are better ways of securing Linux with less work and IMHO the resulting OS is much better than anything without shells, etc. at all. Google is your master. www.nsa.gov/selinux/ www.lids.org/ www.openwall.com/ 2. Running some minimal, barebone Linux with carefully carved functionality. You can replace /sbin/init with your own program and make it do whatever you need. Link it statically and you should not even need libraries, just one file and a kernel. Again, sometimes you can get similar or better results without sacrificing the whole OS, and with less work. But this subject is quite broad and so there is not much more to say. > regards, > KM Regards, Tomasz Rola - -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:[EMAIL PROTECTED] ** -BEGIN PGP SIGNATURE- Version: PGPfreeware 5.0i for non-commercial use Charset: noconv iQA/AwUBQqlqSBETUsyL9vbiEQLVHwCfX3X0IyZLBq3k1uYJElNh1BUOFdIAoKaL ZH5Eqxq2EnN+XpDT9K79FNsK =Jusy -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: without shell
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Sun, 12 Jun 2005, km wrote: > hi all, > > can any linux command be invoked/ executed without using shell (bash) ? > what abt security concerns ? Ops, I missed the word "command" when reading your mail for the first time, and this changes some parts of my previous answer and makes it shorter: There is an execve system call. You don't need neither sh, nor the libc to run programs. It's described in section 2 of manpages. The rest of the answer you can get from my previous post. Sorry if I went a bit offtopic in my previous mail. Shouldn't watch tv and write mails at the same time. > regards, > KM Regards, Tomasz Rola - -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:[EMAIL PROTECTED] ** -BEGIN PGP SIGNATURE- Version: PGPfreeware 5.0i for non-commercial use Charset: noconv iQA/AwUBQqlr0RETUsyL9vbiEQIocwCfVh1SsT+RegTaxvNjlsCl8FYupe8AoLH5 qci3LXS1w8bq1ZqH7EKL1HuT =0WoY -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: Where is Word?
> Unfortunately, I need to open/edit a (temporary) text file with Word, and > those are opened by default with UltraEdit (or Notepad or..). Thanks for the > tip, though. > > Anything else? Do I need to read the registry? > > g You may try to launch Word as a COM object and control it directly from Python using the COM object methods. This does not require you to know the application's path, only the COM object identifier. TLis -- http://mail.python.org/mailman/listinfo/python-list
Re: Where is Word?
> Thanks, but could you pretty please post some code that does this? I'm new > to Python, let alone COM.. > > TIA, > g import win32com.client wordCOMID = "Word.Application" word = win32com.client.Dispatch(wordCOMID) Then you can use the methods of the word object, provided by the COM object definition. Unfortunately I don't know them - you may do a research by making a reference to the Microsoft Word type library in Visual Basic, declaring the variable of type Word.Application, and then watching the code assistant showing the available methods and properties. You may also use the object browser. Tomasz Lisowski > > "Tomasz Lisowski" <[EMAIL PROTECTED]> schreef in bericht > news:[EMAIL PROTECTED] > >>You may try to launch Word as a COM object and control it directly from >>Python using the COM object methods. This does not require you to know the >>application's path, only the COM object identifier. >> >>TLis > > > -- http://mail.python.org/mailman/listinfo/python-list
pipeline encoding
My locale is set to UTF-8. The command: python -c "print u'\u03A9'" gives me the desired result and doesn't produce any error. But when I want to redirect the output to a file I invoke: python -c "print u'\u03A9'" > file.txt I get an error: File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode character u'\u03a9' in position 0: ordinal not in range(128) How to cope with it? -tt. -- http://mail.python.org/mailman/listinfo/python-list
Re: pipeline encoding
"Martin v. Löwis": > Not a command line option. However, you can wrap sys.stdout with a > stream that automatically performs an encoding. If all your print > statements output Unicode strings, you can do > > sys.stdout = codecs.getwriter("utf-8")(sys.stdout) It is the best solution for me. Thanks. -tt. -- http://mail.python.org/mailman/listinfo/python-list
Re: A critic of Guido's blog on Python's lambda
Bill Atkins wrote: > OK, my real question is: what features of Python make it "scalable"? Let me guess: Python makes it easier to scale the application on the "features" axis, and the approach to large-scale computation taken by google makes Python's poor raw performance not so big an issue, so it doesn't prevent the application from scaling on the "load" and "amount of data" axes. I also guess that python is often used to control simple, fast C/C++ programs, or even to generate such programs. Best regards Tomasz -- http://mail.python.org/mailman/listinfo/python-list
Re: A critic of Guido's blog on Python's lambda
Alex Martelli wrote: > ``An unneeded feature "cannot" be added (elegantly) in future releases > of the language'' is just as trivial and acceptable for the unneded > feature ``allow ( as an ordinary single-character identifier'' as for > the unneded feature ``allow unnamed functions with all the flexibility > of named ones''. You can't be seriously claiming that these two features are equally (un)needed. Anonymous functions come from the foundations of computer science - Lamda Calculus. They are just a natural step on the road to higher level languages. There are useful programming techniques, like monadic programming, that are infeasible without anonymous functions. Anonymous functions really add some power to the language. On the other hand, what do you get by allowing ( as an indentifier? Significant whitespace is a good thing, but the way it is designed in Python it has some costs. Can't you simply acknowledge that? Best regards Tomasz -- http://mail.python.org/mailman/listinfo/python-list
Re: A critic of Guido's blog on Python's lambda
Alex Martelli wrote: > Having to give functions a name places no "ceiling on expressiveness", > any more than, say, having to give _macros_ a name. And what about having to give numbers a name? > Yes, we are, because the debate about why it's better for Python (as a > language used in real-world production systems, *SCALABLE* to extremely > large-scale ones) to *NOT* be insanely extensible and mutable is a > separate one -- Python's uniformity of style allows SCALABILITY of > teams, and teams-of-teams I think this kind of language scalability is most important for Google, see below. > if your need SCALE, well then, PYTHON IS SCALABLE, and will remain a > *SIMPLE, CLEAN, LITTLE AND POWERFUL LANGUAGE* (letting nobody do > anything INSANE to it;-) while scaling up to whatever size of project(s) > you need (including systems so large... But honestly, isn't this scalability a result of the data processing model you use, which is language independent? My point is that when you have such a well scaling data processing model, most languages scale well on the "data" and "load" axes, so you pick your language based on how well it scales on the "teams" and "features" axes. You seem to claim that there is something in Python that lets it scale well on "data" and "load", and is not related to "teams" and "features", and also not related to Google's data processing model. Can you tell me what it is? Best regards Tomasz -- http://mail.python.org/mailman/listinfo/python-list
Re: A critic of Guido's blog on Python's lambda
Alex Martelli wrote: > Tomasz Zielonka <[EMAIL PROTECTED]> wrote: > >> Alex Martelli wrote: >> > Having to give functions a name places no "ceiling on expressiveness", >> > any more than, say, having to give _macros_ a name. >> >> And what about having to give numbers a name? > > Excellent style, in most cases; I believe most sensible coding guides > recommend it for most numbers -- cfr ><http://en.wikipedia.org/wiki/Magic_number_(programming)> , section > "magic numbers in code". I was a bit unclear. I didn't mean constants (I agree with you on magic numbers), but results of computations, for example (x * 2) + (y * 3) Here (x * 2), (y * 3) and (x * 2) + 3 are anonymous numbers ;-) Would you like if you were forced to write it this way: a = x * 2 b = y * 3 c = a * b ? Thanks for your answers to my questions. Best regards Tomasz -- http://mail.python.org/mailman/listinfo/python-list
Re: A critic of Guido's blog on Python's lambda
I V wrote: > Monads are one of those parts of functional programming I've never really > got my head around, but as I understand them, they're a way of > transforming what looks like a sequence of imperative programming > statements that operate on a global state into a sequence of function > calls that pass the state between them. This is a description of only one particular kind of monad - a state monad. A generalisation of your statement would be something like this: "they're a way of writing what looks like a sequence of imperative programming statements that, depending on the monad, can have certain computational side-effects (like operating on a global state) in a purely functional way". But this doesn't explain much. If you want to know more, there are some pretty good tutorials on http://www.haskell.org/. > So, what would be a statement in an imperative language is an anonymous > function that gets added to the monad, and then, when the monad is run, > these functions get executed. A monad is a type, it isn't run. The thing you run can be called a monadic action. You don't add functions to a monad (in this sense), you build a monadic action from smaller monadic actions, gluing them with functions - here's where anonymous functions are natural. > The point being, that you have a lot of small functions (one for each > statement) which are likely not to be used anywhere else, so defining > them as named functions would be a bit of a pain in the arse. Exactly! > Actually, defining them as unnamed functions via lambdas would be annoying > too, although not as annoying as using named functions - what you really > want is macros, so that what looks like a statement can be interpreted is > a piece of code to be executed later. Haskell has one such "macro" - this is the do-notation syntax. But it's translation to ordinary lambdas is very straightforward, and the choice between using the do-notation or lambdas with >>= is a matter of style. Best regards Tomasz -- http://mail.python.org/mailman/listinfo/python-list
Re: A critic of Guido's blog on Python's lambda
Alex Martelli wrote: > Worst case, you name all your functions Beverly so you don't have to > think about the naming I didn't think about this, probably because I am accustomed to Haskell, where you rather give functions different names (at the module top-level you have no other choice). I just checked that it would work for nested Beverly-lambdas (but could be quite confusing), but how about using more then one lambda in an expression? You would have to name them differently. > but you also have a chance to use meaningful names (such as, > presumably, zipperize_widget is supposed to be here) to help the > reader. [OK, I am aware that you are talking solely about lambdas in Python, but I want to talk about lambdas in general.] Sometimes body of the function is its best description and naming what it does would be only a burden. Consider that the same things that you place in a loop body in python, you pass as a function to a HOF in Haskell. Would you propose that all loops in Python have the form: def do_something_with_x(x): ... do something with x for x in generator: do_something_with_x(x) Also, having anonymous functions doesn't take your common sense away, so you still "have a chance". Best regards Tomasz -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is slow
On Fri, 12 Dec 2008, bearophileh...@lycos.com wrote: > In the next years people that use low-level languages like C may need > to invent a new language fitter for multi-core CPUs, able to be used > on GPUs too (see the OpenCL), less error-prone than C, able to use the > CPU vector instructions efficiently. (The D language is probably unfit > for this purpose, because even if it's meant to be a system language, > I don't think it can be used much to replace C everywhere it's used > now.) A C+ maybe? :-) > > Bye, > bearophile I would say, this probably will be some descendant of Erlang and/or Haskell. As evolutionary step, they look very promising to me, they just are "not quite there" yet. As of C++, I cannot tell before I read their new standard. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Why not Ruby?
On Thu, 1 Jan 2009, s...@netherlands.com wrote: > On Wed, 31 Dec 2008 23:16:41 -0500, Kenneth Tilton > wrote: > > >Xah Lee wrote: > >> Just spent 3 hours looking into Ruby today. Here's my short impression > >> for those interested. > >> > > Be carefull what you say. If they pay me I would rip your and Xah's > guts out in a second. > > sln Too much champagne? A guy (XL) is sometimes off topic and I don't always agree with his postings - if I find the subject somewhat worthy, I usually skim through it, this is how I have found myself knee deep in this strange exchange between XL's supporters and opponents. And his website is big like a magazine and full of strange, sometimes not interesting or hard to assess stuff (it needs time to read and time is hard to find nowadays). But sometimes, what he writes is informative, too. A bit redundant but still, I would give him a small "plus", rather than "zero" or "minus". But I do not remember him being blunt or agressive. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming exercises/challenges
On Tue, 18 Nov 2008, [EMAIL PROTECTED] wrote: [...] > challenges, or programs that have helped you'll learn. I'm working on the > project Euler problems, but I find that they don't really help my programming > skills; they are more math focused. Project Euler and others focus more on the so called algorithmic side of programming. You may find it a big fun later. For now, they probably look bizarre to you. > Suggestions? What has been useful or > interesting to you? I'd also welcome sources of textbook type problems, > because the ones provided in tutorials tend to be repetitive. I would say, start looking for something in your own life, that can be improved with the use of a program. This requires a bit of thinking in a specific way, kind of awareness. Once you spot your own ideas, you will probably run out of time to implement them all. If you have some interests beyond programming :), finding them should not be that hard. If there are some books related to those interests, they should be a good start. The way you do it now, I think it is much better to connect your newly gained knowledge with real-life activity rather then to solve yet another "imagined" problem from a book, writing throwaway programs to prove that you can write them. I am quite sure, that for every domain there is a lot of big and small ideas waiting for a programmer. So you can start with simple things and as you learn, try your luck with bigger ones. Writing real life programs will give you an opportunity to learn some python libraries, which is a good thing too. Nice attitude :-). Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:[EMAIL PROTECTED] ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Is python worth learning as a second language?
On Mon, 9 Mar 2009, ZikO wrote: > Hi > [...] > > Do you think python would be good complementary language for C++? Yes, definitely. > Do you think it's worth learning it or let's say try Java? I may not be objective (tried Java, hated it after 6 years). In the long run, I'm afraid Java is going to slide into being Cobol/Visual Basic of the future. I mean, not really fun anymore. Some people want fun and some other don't care. > and how difficult it would be > for me if I know C++ pretty well I would say? Easy :-). One day of reading this, for a start: http://docs.python.org/tutorial/index.html and later: http://docs.python.org/ http://diveintopython.org/ > Thanks pl.comp.lang.python ;-) Regards/Pozdrawiam, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Is python worth learning as a second language?
On Mon, 9 Mar 2009, Bruno Desthuilliers wrote: > Tomasz Rola a écrit : > (snip) > > > I may not be objective (tried Java, hated it after 6 years). > > Arf - only took me 6 months !-) I guess sometimes I need to be knocked really hard ;-/. But it works both ways - I cannot imagine what should Java-the-language have to make me interested again. Java-the-virtual-machine is still interesting a little, but not as much as few years ago. Languages that I like (Python is one of them) are already multiplatform, so running Jython is reserved to few very special cases (those cases may be important and happening quite often to other people but I intend to avoid them personally). Same for other languages implemented over JVM, like Scheme or Common Lisp. Of course, just my opinion. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com **-- http://mail.python.org/mailman/listinfo/python-list
Re: Is python worth learning as a second language?
On Thu, 19 Mar 2009, Aahz wrote: > --===0027953262== > > In article <49b58b35$0$3548$426a7...@news.free.fr>, > Bruno Desthuilliers wrote: > >Tomasz Rola a écrit : > >> > >> I may not be objective (tried Java, hated it after 6 years). > > > >Arf - only took me 6 months !-) > > That long? It only took me six minutes. Guess what, there was a time when Java was looking quite promising. Especially in the field of distributed computing (which then meant not only high performance clusters). And computers were of more than one type, used other cpus than Intel, too. Maybe it's easier to ridicule Java now, when it has not met the expectations. But still, some people (better than I) have spent few years writing software and doing their research in Java. Sure, that was before Java had been nominated the common denominator of programming languages. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com **-- http://mail.python.org/mailman/listinfo/python-list
Re: cross compile Python to Linux-ARM
On Thu, 19 Mar 2009, jefm wrote: > Hi, > We are looking to use Python on an embedded Linux ARM system. > What I gather from googling the subject is that it is not that > straight forward (a fair amount of patching & hacking). > Nobody out there that has done it claims it is easy, which makes me > worried. >From my ocassional googling, I was quite convinced that ARM (and StrongARM) were well supported targets. Besides Debian, already mentioned by OPs, you can also try Familiar Linux Distribution, aimed at StrongARM-based devices: http://www.handhelds.org/geeklog/index.php They have a wiki, maybe you can find some pointers there: http://www.handhelds.org/moin/moin.cgi/BuildSystem?action=highlight&value=crosscompile http://www.handhelds.org/moin/moin.cgi/FamiliarUnderQemu?action=highlight&value=crosscompile > (or is it safer to wait for industrial spec Intel Atom boards to avoid > the cross compilation altogether ? Depends. If you know for sure when they are going to be here and if they will be price-performance-competitive. Regards Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Is python worth learning as a second language?
On Sat, 20 Mar 2009, Aahz wrote: > --===0836317661== > > So? By the time Java was released, Python had already been around for > several years. I've started to use Python around 1.5. If it could interest me more than Java earlier than that, I don't know. > Taking C++ and turning it into a VM model does not > exactly strike me as particularly good use of resources. It doesn't strike me either. But resources are not the only dimension of judging the language, you know. Also, I never actually liked the idea of dumbing down C++. But, as I said, Java had some weight in the past (and some promises have been made about its future and not kept). I felt that dismissing it "after six minutes" might have been a little bit unfair. You should have done it after a week. :-). BTW, if you spent a day on this, you could learn about few other Java implementations, some of them not so resource hungry. Not that it makes Java much better, but your choice could be better informed. Eh, English - not sure if it is really what I've wanted to say :-). Regards Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Is python worth learning as a second language?
On Sat, 21 Mar 2009, Aahz wrote: > In article , > Tomasz Rola wrote: > >On Sat, 20 Mar 2009, Aahz wrote: > >> > >> Taking C++ and turning it into a VM model does not exactly strike me > >> as particularly good use of resources. > > > >It doesn't strike me either. But resources are not the only dimension of > >judging the language, you know. > > You misunderstand me: I was talking about the resources (people and > money) used to create Java. Ah, I see now. From my perspective, it depends on how things ended. Since Java went into VB-like direction, I think I can agree. They have to go deeper and deeper into this... dead end (business decisions and the like). But it wasn't always looking as bad as now, so, you know, it is always easy to judge past, especially knowing that something was a failure. As I was reading about Java's prospects long ago, the use of people and money by Sun seemed like quite good way of spending resources (not best, but justified). In my opinion, it was the direction Java took somewhere around dot com burst that has really sinked it (namely, letting go of innovating aspect and pushing Java as, pardon the word, "business-level solution"). > Java is yet another language with heavy static typing and an > object-oriented focus. What should have caused me to waste more time > before dismissing it? Really, I don't know. From how you wrote it, seems you had not much need to investigate the subject. So, since you did not feel such need in the first place, it could be difficult to convince you. It really depends on what kind of programs you write (or are going to write). For me, there are some cases, when I would at least consider Java during design phase: 1. Writing code that has to be, umh, mobile (not in a cell phone sense). Working on a network, sending code to other nodes. Special case - when this code has to do some computations, not heavy enough to justify using C, but still enough so that JIT is an advantage (even though JIT may not be available on every node type). And, of course, having a C compiler on every node is not always feasible. My favourites at the moment would be: - Scheme. PLT Scheme has JIT and is my current workhorse language. It is possible to find other Scheme flavors on almost any >=32-bit cpu. Cons: all those flavors, albeit very similar and based on well defined common standard - to be frank, not so common anymore, but this is irrelevant - are still a bit different which can get problematic). - Java. Has JIT and is quite ubiquitous, from mainframes to cellphones. Cons: different Java flavors, EE, SE, MIDP... are quite different and their common subset is too simple for my taste. - Python. I like it more than Java, sometimes it is possible to use JIT. Still, the fact that I like it does not always help enough to use it. - Erlang? Who knows, I would have to read more about it first. 2. Using code written in few different languages: - Common Lisp. Right now, I don't actually feel like I can program in it, but from what I have read here and there, hacking REPL into accepting foreign code is a lot of fun and adventure, so if only I had enough time to learn, I would go for it, I suppose. Also, there is a possibility (theoretical at least) to compile the whole shebang into native code. - Java. As a platform, Java has a number of other languages implementations on top of its JVM. They are a bit slow from what I read but they are here long enough to be considered stable and/or mature. - Python is not a big contender here, it is not a platform. It is still possible to glue different libraries and interpreters with it (like Sage), but this is not always convenient. - Mono. I know it not well enough to consider its use. But maybe, maybe. I hope this answered your question, at least partially. Learning Java as a good Python or anything replacement is not a case, I think. However, learning about it to have more choices is rather good idea. At least I myself am not too sorry about knowing Java, maybe I should have just jumped off its vagon a year or two earlier than I did. BTW, I realise that there may be some costly alternatives to everything I wrote above. But I am not interested so I would not consider them :-), Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Is python worth learning as a second language?
On Fri, 20 Mar 2009, alex goretoy wrote: > I've only read he subject and a few lines from other responses. > > yes, it is worth learning. I came from PHP to Python. It's very powerful and > makes application development easier for me than in PHP and/or C#, but bash, > well that depends on the type of bash. It has a lot of diffent ways you can > use it too, so that adds to how powerful it is. IMHO, Bash is great for quick and dirty hacks, as a kind of simplified Perl. But when bash script grows too big, I would consider rewriting it in Python rather than Perl. But this is just my personal choice. Since we are already a little offtopic :-), did you see any speed difference between PHP and Python? I understand, that you are doing web devel in those two? > -Alex Goretoy > http://www.goretoy.com Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Is python worth learning as a second language?
On Sat, 21 Mar 2009, alex goretoy wrote: > I really can't say too much about speed increase or decrease, it really > depends on the site and how its built, what libs are used and how they are > loaded, same thing in PHP, It would be difficult for me to same anything on > speed because of that. I built a templated modulated cms in CodeIgniter(PHP > MVC), google it, It is a base for a templated system. using smarty and ci > templating syntax, although the smarty side of things makes it slower I > think. Also it is modulated, which breaks up your code into modules that you > can load on the page into a div with ajax, preferrably jquery but you can > use any framework for that too I see. Thanks for answering. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Nimrod programming language
On Fri, 8 May 2009, Andreas Rumpf wrote: > Dear Python-users, > > I invented a new programming language called "Nimrod" that combines > Python's readability with C's performance. Please check it out: > http://force7.de/nimrod/ > Any feedback is appreciated. > > Regards, > Andreas Rumpf Interesting. One question I ask myself upon seeing a new language is if it is possible to program amb (amb=ambiguous) operator in it. This page gives a very nice, "code first" explanation of amb and how it is supposed to work: http://www.randomhacks.net/articles/2005/10/11/amb-operator I am not sure if this kind of extension is doable in your Nimrod. Perhaps it can be somewhat extrapolated from docs, but at the moment I have no time to do this (and could not google anything interesting). As can be seen on the page mentioned, in Ruby this seems to be quite light and effortless. From what I know about Python, it is either hard or impractical (to the point of being impossible) to write amb in it. Two additional notes regarding amb: 1. Even if Nimrod cannot support amb in an elegant way, it is still nice idea. Especially if you can make it to be kind of Python superset, so that Python programmer can cross the boundary between the two without much hassle (and maybe in both directions). Of course, not everything can be copied. 2. The amb itself is not really important so much, and I may never feel any need to actually use it. But it stroke me how nice it was looking in Ruby, even if I finally decided not to learn Ruby (not in this year, at least). In Scheme, it is a bit more hackish, but still looks nice, at least to me: http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z-H-16.html#node_chap_14 http://planet.plt-scheme.org/package-source/murphy/amb.plt/1/0/planet-docs/amb/index.html Anyway, I think amb is quite a test of a language. If you can do it, please show the code. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Nimrod programming language
On Mon, 11 May 2009, rump...@web.de wrote: > > One question I ask myself upon seeing a new language is if it is possible > > to program amb (amb=ambiguous) operator in it. This page gives a very > > nice, "code first" explanation of amb and how it is supposed to work: > > > > http://www.randomhacks.net/articles/2005/10/11/amb-operator > > > Hm. I am not sure either. To me, it looks like a constraint solver by > using brute force. Yes, kind of. From what I understand [1], it's goal is to simulate nondeterministic "get right answer in one try", only this "one try" requires browsing the solution space (because we have only "classic" hardware). It is easy to use amb in wrong way, but I can see some cases when I would like it. [1] John McCarthy's paper still waits to be read by me, so... Ok, I have just had a look at it and it seems that Ruby implementation is a bit primitive compared to original concept. But still, this is what would be needed in most real life cases, I suppose. I think ability to define amb would allow me to write more concise code. As far as I can tell, this kind of stuff plays more and more important role in my programing. > It seems to require continuations. AFAIK > continuations are extremely hard to implement efficiently, so probably > it won't be done in Nimrod. Pity, a little. But not really big problem for me. Nimrod may be interesting anyway, time will tell :-). Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Nimrod programming language
On Mon, 11 May 2009, k...@fiber-space.de wrote: > On 12 Mai, 02:10, Tomasz Rola wrote: > > On Mon, 11 May 2009, rump...@web.de wrote: > > > > One question I ask myself upon seeing a new language is if it is > > > > possible > > > > to program amb (amb=ambiguous) operator in it. This page gives a very > > > > nice, "code first" explanation of amb and how it is supposed to work: > > > > > >http://www.randomhacks.net/articles/2005/10/11/amb-operator > > > > > Hm. I am not sure either. To me, it looks like a constraint solver by > > > using brute force. > > > > Yes, kind of. From what I understand [1], it's goal is to simulate > > nondeterministic "get right answer in one try", only this "one try" > > requires browsing the solution space (because we have only "classic" > > hardware). It is easy to use amb in wrong way, but I can see some cases > > when I would like it. > > In Python you can use a generator expression. Dan Piponis example can > be stated as > > g = ((i,j) for i in range(2,100) for j in range(2,i) if i*j == 481) > > which doesn't require any call/cc hacks but is a deterministic "get > right in one try". Once Nimrod has coroutines it's just a matter of > sugaring them into comprehensions. Yep, to be frank everything complicated can be achieved by means of a "for" loop (so said one friend of mine, and this is dirty, dirty way of thinking). Or putting generators in a row... but try to do this trick with ten of them and things start to look messy. Or ugly. Or both - and I don't like neither. There is another example, below Don Piponis' one. I like the look of simplicity. I don't like ten or seven nested loops, that would have been used instead. Perhaps amb could be somehow simulated with recursion, but to use recursion in a language, I need to know it is safe and doesn't overflow on 50th call. So, either I use the language that allows me to express things in a way appealing to my taste, or I use something else and perhaps end up with nested loops. Besides, having search space defined with amb-statements may allow me to try other ideas than brute-force search. Like, say, genetic algorithm under the hood. No change to program, just link with other library (import amb's definition from other path etc). I cannot imagine trying such trick with nested loops without writing new program (writing new loop(s)). Generators don't give me nice looking alternative to amb. So, if the problem requires two or three nested loops, ok, I can go for it. If more - I want another way out. Just my personal opinion, not forcing anybody to follow. However, the question I wanted to be answered, was how far Nimrod would allow me to go. I've got my answer and, well, for some near future I will just sit and see what happens. So, discussing amb's usefulness or if the same ca be done with whatever else is not very interesting, because of course everything can be done with loops - no need for continuations, coroutines, recursion, macros etc. Regards Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Limits of Metaprogramming
ing a new language because of it is a bit too much (or maybe not, if you enjoy it :-) ). But if you plan doing similar or more difficult things in the future, then knowing Scheme may be good for you. Even if you choose to not use it, you will be aware of what can be done with it so this knowledge can provide some ready to use templates. And yes, there are also some other languages in Lisp family, but I think Scheme is best choice if you don't know any of them already. It is quite small, it is well defined (I mean, it has some real specification, instead of being "specified by its implementation") and there is a lot of info about it on the net that could be easily understood. And, last but not least, it has metaprogramming included with nice bunch of additional stuff. For a start, PLT's DrScheme looks nice (IMHO - yes, there are other nice looking Scheme implementations but this one is probably best fitted for a beginner): http://www.plt-scheme.org/ Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:[EMAIL PROTECTED] ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Limits of Metaprogramming
On Mon, 4 Aug 2008, Wilson wrote: > " Every sufficiently large application has a poor/incomplete > implementation of LISP embedded within it ". Yep, this is either exact or very close copy of what I have read. > I've looked at LISP > before and do appreciate its elegance, but Python has a beauty of its > own in its pragmatism, standard libraries and community. So I'll > choose to stick with it. [...] > I've been through quite a few of the SICP lectures and again, do > appreciate its elegance and they have changed the way I program. [...] > Thanks for your comments. But I believe my solution may lie in using a > template language such as cheetah. Too much is already invested in > Python! > > Best Regards, > Paul Ok, so you do know something about Lisp - that is good :-). Of course, since you have already existing Python code, converting is not for you. Just to make sure you stay informed, there is CLPython: http://common-lisp.net/project/clpython/ I did not try this thing, but I am very pleased it exists. I have some Python code myself and knowing there is a way to reuse it if I choose some other way makes me feel better. Or rather, knowing I can easily merge the two (or more) ways. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:[EMAIL PROTECTED] ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a faster way to do this?
On Tue, 5 Aug 2008, [EMAIL PROTECTED] wrote: > I have a csv file containing product information that is 700+ MB in > size. I'm trying to go through and pull out unique product ID's only > as there are a lot of multiples. My problem is that I am appending the > ProductID to an array and then searching through that array each time > to see if I've seen the product ID before. So each search takes longer > and longer. I let the script run for 2 hours before killing it and had > only run through less than 1/10 if the file. My take: I assume you have 80 bytes per line, that makes 10 milion lines for 700M file. To be quite sure lets round it to 20 milions. Next, I don't want to trash my disk with 700M+ files, so I assume reading the line, breaking it and getting product id takes roughly the same time as generating random id by my code. So, I: 1. read all records line by line (or just make random ids), append the product id to the list (actually, I preallocate the list with empty space and fill it up) 2. sort() the list 3. iterate the list, count the unique ids, optionally write to file The code (most of it is just making random names, which was real fun): import string RECORD_NUM = 20*1024*1024 # 700M/80-bytes-per-line = ca. 10M+ records ALPHA = string.digits + string.ascii_letters RAND = None def random_iter ( ) : x = 12345678910 y = 234567891011 M = 2**61 - 1 M0 = 2**31 - 1 pot10 = [ 1, 10, 100, 1000, 1, 10 ] while 1 : p = x * y l = pot10[5 - (p % 10)] n = (p / l) % M d = l * (n % 10) p = p % M0 x1 = y - d + p y1 = x + d + p x, y = x1, y1 yield n pass pass def next_random ( ) : global RAND if RAND == None : RAND = random_iter() return RAND.next() def num_to_name ( n ) : s = [] len_a = len(ALPHA) while n > 0 : n1, r = divmod(n, len_a) s.append(ALPHA[r]) n = n1 pass return "".join(s) def get_product_id ( ) : return num_to_name(next_random()) def dry_run ( n ) : r = [ 0 ] * n while n > 0 : n -= 1 r[n] = get_product_id() return r ### if __name__ == "__main__": print "hello" for i in range(10) : print get_product_id() print print "RECORD_NUM: %d" % RECORD_NUM products = dry_run(RECORD_NUM) print "RECORDS PRODUCED: %d" % len(products) products.sort() i = 0 lastp = "" count = 0 while i < len(products) : if lastp != products[i] : lastp = products[i] count += 1 i += 1 pass print "UNIQUE RECORDS: %d" % count I may have made some bugs, but it works on my computer. Or seems to ;-/. For 20 mln products, on my Athlon XP @1800 / 1.5G ram, Debian Linux box, it takes about 13 minutes to go through list generation, about 3 minutes to sort the list, and few more seconds to skim it (writing should not be much longer). All summed up, about 18 minutes of real time, with some other programs computing a little etc in the background - so, much less then 2 hours. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:[EMAIL PROTECTED] ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming challenge: wildcard exclusion in cartesian products
[EMAIL PROTECTED] wrote: > The python code below generates a cartesian product subject to any > logical combination of wildcard exclusions. For example, suppose I want > to generate a cartesian product S^n, n>=3, of [a,b,c,d] that excludes > '*a*b*' and '*c*d*a*'. See below for details. > > CHALLENGE: generate an equivalent in ruby, lisp, haskell, ocaml, or in > a CAS like maple or mathematica. What is your goal? You want to learn or to cause a flamewar? ;-) Anyway, I found the problem entertaining, so here you go, here is my Haskell code. It could be shorter if I didn't care about performance and wrote in specification style. It's not very efficient either, because it will generate all lists matching the given patterns. In GHCi you can test it by: $ ghci :l WildCartesian.hs test I apologise for the lack of comments. 8<8<8<8<8<8<8<8< module WildCartesian where import Data.Set (Set) import qualified Data.Set as Set import Control.Monad import Control.Exception (assert) import Maybe import List data Pat a = All | Lit a deriving Show generateMatching :: (Ord a) => Int -> Set a -> [Pat a] -> [[a]] generateMatching 0 _[]= [[]] generateMatching 0 _(_:_) = [] generateMatching len alphabet (Lit x : ps) | x `Set.member` alphabet = [ (x : xs) | xs <- generateMatching (len - 1) alphabet ps ] | otherwise = [ ] generateMatching len alphabet (All : ps) = [ (x : xs) | x <- Set.toList alphabet , xs <- unionSorted (generateMatching (len - 1) alphabet ps) (generateMatching (len - 1) alphabet (All : ps)) ] `unionSorted` generateMatching len alphabet ps generateMatching _ _[] = [] generateNotMatching :: (Ord a) => [a] -> Int -> [[Pat a]] -> [[a]] generateNotMatching alphabet len patterns = generateMatching len alphaSet [All] `subtractSorted` foldr unionSorted [] (map (generateMatching len alphaSet . simplifyPat) patterns) where alphaSet = Set.fromList alphabet simplifyPat (All : All : ps) = simplifyPat (All : ps) simplifyPat (p : ps) = p : simplifyPat ps simplifyPat [] = [] joinSorted :: Ord a => [a] -> [a] -> [(Maybe a, Maybe a)] joinSorted (x1:x2:_) _ | assert (x1 < x2) False = undefined joinSorted _ (y1:y2:_) | assert (y1 < y2) False = undefined joinSorted (x:xs) (y:ys) = case x `compare` y of LT -> (Just x, Nothing) : joinSorted xs (y:ys) EQ -> (Just x, Just y) : joinSorted xs ys GT -> (Nothing, Just y) : joinSorted (x:xs) ys joinSorted (x:xs) [] = (Just x, Nothing) : joinSorted xs [] joinSorted [] (y:ys) = (Nothing, Just y) : joinSorted [] ys joinSorted [] [] = [] unionSorted :: Ord a => [a] -> [a] -> [a] unionSorted xs ys = catMaybes (map (uncurry mplus) (joinSorted xs ys)) subtractSorted :: Ord a => [a] -> [a] -> [a] subtractSorted xs ys = catMaybes (map f (joinSorted xs ys)) where f (Just x, Nothing) = Just x f _ = Nothing test = do t [1,2] 3 [[Lit 1, All, Lit 2]] t ['a','b'] 3 [[Lit 'a', All, Lit 'b'], [Lit 'b', All, Lit 'a']] t [1,2] 3 [[Lit 1, All, Lit 2], [Lit 2, All, Lit 1]] where t a b c = do putStrLn (concat (intersperse " " ["generateMatching", show a, show b, show c])) mapM_ (putStrLn . (" "++) . show) (generateNotMatching a b c) 8<8<8<8<8<8<8<8< Best regards Tomasz -- I am searching for programmers who are good at least in (Haskell || ML) && (Linux || FreeBSD || math) for work in Warsaw, Poland -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming challenge: wildcard exclusion in cartesian products
Tomasz Zielonka wrote: > putStrLn (concat (intersperse " " ["generateMatching", show a, show > b, show c])) Minor correction: it should be "generateNotMatching". Best regards Tomasz -- I am searching for programmers who are good at least in (Haskell || ML) && (Linux || FreeBSD || math) for work in Warsaw, Poland -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming challenge: wildcard exclusion in cartesian products
Major correction (missing case): Tomasz Zielonka wrote: > generateMatching :: (Ord a) => Int -> Set a -> [Pat a] -> [[a]] > generateMatching 0 _[]= [[]] generateMatching 0 alphabet (All:ps) = generateMatching 0 alphabet ps > generateMatching 0 _(_:_) = [] Best regards Tomasz -- I am searching for programmers who are good at least in (Haskell || ML) && (Linux || FreeBSD || math) for work in Warsaw, Poland -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming challenge: wildcard exclusion in cartesian products
Dan Piponi wrote: > Is this Haskell implementation what you want? It does the wildcard > matching through a state machine and it essentially threads the > state machine through the cartesian product, switching to the > ordinary cartesian product when possible as an optimisation. > The execution of the state machine is shared by strings with the > same prefix making it reasonably efficient even though the state > machine itself isn't optimised. I've implemented the same concept yesterday evening: 8<8<8<8<8<8<8<8< module WildCartesian where import List data Pat a = All | Lit a deriving (Show, Eq) advancePattern :: Eq a => a -> [Pat a] -> [[Pat a]] advancePattern y (Lit x : ps) | x == y= [ps] | otherwise = [] advancePattern y (All : ps) = [All : ps] ++ [ps] ++ advancePattern y ps advancePattern _ [] = [] generateNotMatching :: Eq a => [a] -> Int -> [[Pat a]] -> [[a]] generateNotMatching alphabet = gen [] where gen _ n pats | any (\ps -> all (== All) ps && (not (null ps) || n == 0)) pats = [] gen acc 0 _ = [reverse acc] gen acc n pats = [ w | x <- alphabet , let pats' = [ p' | p <- pats, p' <- advancePattern x p ] , w <- gen (x : acc) (n - 1) pats' ] test :: IO () test = do t [1,2] 3 [[Lit 1, All, Lit 2]] t ['a','b'] 3 [[Lit 'a', All, Lit 'b'], [Lit 'b', All, Lit 'a']] t [1,2] 3 [[Lit 1, All, Lit 2], [Lit 2, All, Lit 1]] where t a b c = do putStrLn (concat (intersperse " " ["generateNotMatching", show a, show b, show c])) mapM_ (putStrLn . (" "++) . show) (generateNotMatching a b c) 8<8<8<8<8<8<8<8< Best regards Tomasz -- I am searching for programmers who are good at least in (Haskell || ML) && (Linux || FreeBSD || math) for work in Warsaw, Poland -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming challenge: wildcard exclusion in cartesian products
[EMAIL PROTECTED] wrote: > -- The states are lists of regular expressions > -- where [a,b,..] means match a or b or... > > I haven't run or studied your program yet myself but what I had in mind > was that the list of wc's are *all* to be excluded, so the list > [wc1..wcn] is to correspond generating all tuples matching not(wc1 and > .. and wcn). Maybe you're already doing that. The wc's themselves > could be logical statements among the 'primitive' wc's. That's why I > named it the 'wildcard exclusion problem'. It's a lot easier to specify > a list of simpler wc's than create a long logical expression. I missed "any logical combination" :-( It would be quite easy to fix my first program, but I don't have the time to do it right now. Best regards Tomasz -- I am searching for programmers who are good at least in (Haskell || ML) && (Linux || FreeBSD || math) for work in Warsaw, Poland -- http://mail.python.org/mailman/listinfo/python-list
Re: Bored.
Necronymouse wrote: > Hello, I am learning python for about 2 years and I am bored. Not > with python but I have a little problem, when i want to write > something I realise that somebody had alredy written it! So i don´t > want to make a copy of something but i wanna get better in python > skills. Don´t you know what I should do? In other words, you would like to be creative? If this is the case, you must let your head out of the box. People coding for too long have the tendency to have a box (say, a cube) on their heads. I think there is plenty of ideas waiting for someone to turn them into code. Look out the window. Read a book. Repeat. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com **-- http://mail.python.org/mailman/listinfo/python-list
Re: What was your strategy?
On Sun, 14 Nov 2010, Paul Rubin wrote: > Jorge Biquez writes: > > I was wondering if you can share what was the strategy you followed to > > master Python (Yes I know I have to work hard study and practice a lot). > > 1. Read the tutorial http://docs.python.org/tutorial/ > 2. Start writing code, and encounter various issues as usually happens. > 3. Refer to the other reference manuals, web search, and ask questions >in the newsgroup as you run into issues. > 4. After a while you'll have hit most of the usual issues and learned >how to deal with them, and how to find resolution for new issues that >might come up. That's about as close to mastery as one normally >reaches in this world. > > Python is a pretty easy language if you have a reasonable programming > background when you first start with it. I think the way it's currently > organized, it may not be so great for self-study if you're not already a > programmer. > > > I mean did you use special books, special sites, > > Nah. Wow, exactly same strategy by me. Do you think it should be GPLed, by chance ;-) ? I find this way of learning to be a bit hard (it must have helped that I was no beginner), but somehow none other option came to my head when I was approaching Python some years ago. I guess I'm not a good follower of various written "rules of engagement". So, after tutorial I jumped over the standard Python docs (module index, plus library & language references) until I found whatever was needed at the moment. So choice of strategy depends on choice maker. BTW, I think it was very important in my case to have specific program in mind, begging me to write it in Python. So learning was more exciting thanks to this. I came to Python from some other languages, of which only C retains it's value to me nowadays. I consider myself kind of departed from Pythonland, in search of some other, maybe better alternatives - but it is quite possible Python will join C. I'm undecided, as I've not tried 3.x yet. As a side note, I'm not quite sure Python is good for beginners. Yes, it is very simple and easy to grasp. And yes, it is a bit too simple, maybe? So a beginner learns to think in terms of nails and hammers, but may never hear of screwdrivers in his programing life. I may be wrong but, thinking of it, I feel it was good I have been exposed to Pascal and C (and few other things) long before Python. I would advise Python to casual/Sunday programers, knowing there is big chance they will never learn more than this, so Python is their best option IMHO. But in case of "serious"/"serial" ;-) programing, I would save Python for second or third language. I mean, I perceive it as rather "one way to do it" language and forcing this "one way" on unformed programer doesn't look good. No offence. See? I'm still here. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Python comparison matrix
On Mon, 3 Jan 2011, Alex Willmer wrote: > I've created a spreadsheet that compares the built ins, features and > modules of the CPython releases so far. For instance it shows: [...] > I gathered the data from the documentation at python.org. It's work in > progress so there are plenty of rough edges and holes, but I'd like to > get your opinions, feedback and suggestions. > - Would you find such a document useful? Yes, definitely. Great idea, thanks for doing this. > - What format(s) would be most useful to you (e.g. spreadsheet, pdf, web > page(s), database, wall chart, desktop background)? I would vote for html/web pages with pdf as an option (i.e. a link), if you find it easy enough to make. This probably means you would like to have the source in a form that allows generation of both pages and pdf without much trouble. In this case, it seems there are more than few options to choose from. Perhaps in a form of Python code doing the job, with data in hashtables? That would be so Pythonish :-). > - Are there other aspects/pages that you'd like to see included? > - Do you know of source(s) for which versions of CPython supported which > operating systems (e.g. the first and last Python release that works on > Windows 98 or Mac OS 9)? The best I've found so far is PEP 11 Nothing comes to my head ATM. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to decide between PHP and Python
On Tue, 4 Jan 2011, Dan M wrote: > As to choice between Python and PHP, I would say learn anything but PHP. > Even Perl has fewer tentacles than PHP. However, the quality of code depends heavily on who writes it. My impression is that more folks of "I did it and it works so it is good, right?" attitude can be found among Perl/PHP crowd (compared to Python or Ruby or...). The reason is probably the "easyness" of those languages (mostly because of tons of readymade code on the net) which - wrongly - suggests they are already "there", no need to learn anymore. But I find, from time to time, nice code written in, say, PHP and from this I know it is possible to use it without screwing up. I guess it requires just some learning, some books (leaning towards theory rather than teaching dummies whatever in 2 and 1/10 days) and about five years (or maybe ten, or maybe only two) - after that, you can learn PHP and Perl if you really want to :-). I guess stackoverflow can give some pointers about it. Myself, I see neither of the two as promising for me, so I deflect them. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to decide between PHP and Python
On Tue, 4 Jan 2011, Roy Smith wrote: > In article <4d23a29d.7030...@yahoo.com>, Alan Meyer > wrote: > > > On 1/4/2011 4:22 PM, Google Poster wrote: > > > > > The syntax reminds me of Lots of Interspersed Silly Parentheses > > > (L.I.S.P.), but without the parentheses. > > > > I haven't heard that version before. The one I heard was: > > > > "Lots of Irritating Single Parentheses". > > > > Alan > > Long Involved Stupid Parentheses. Heh. One day, guys, when you have nothing better to do, try writing a parser for Lisp-like language (Common Lisp, Scheme, whatever). After that, do the same with some other language of your preference (Python, Java, whatever). Compare time and code spent... Regards :-) Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to decide between PHP and Python
On Wed, 5 Jan 2011, Ben Finney wrote: > > Tomasz Rola writes: > > Heh. One day, guys, when you have nothing better to do, try writing a > > parser for Lisp-like language (Common Lisp, Scheme, whatever). After > > that, do the same with some other language of your preference (Python, > > Java, whatever). Compare time and code spent... > Perhaps Lisp is a simpler language to parse than Python. > Perhaps a machine with only one instruction > http://en.wikipedia.org/wiki/One_instruction_set_computer> is > simpler to implement than one with a broader instruction set. > So what? So... nothing at all. My intention was to point out that parentheses (or rather, simple syntax that is enabled when using them) can give a boost in some situations. BTW, my own experience tells me, they are not really as bad as some folk tales imply. Of course, there is also esthetic reason - some people don't like parentheses, period. I am ok with this. Me, OTOH, I have esthetic incompatibility with Perl and to some extent with PHP. No problem for me :-). Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to decide between PHP and Python
On Wed, 5 Jan 2011, flebber wrote: > My two cents, I am understanding python far better by learning scheme. > Didn't intentionally set out to achieve that as a goal just a by > product. An excelent resource http://htdp.org and using the racket > scheme ide(as much of an ide as idle), simple thorough well explained > concepts via worked examples and a very encouraging and enthusiastic > mail group, much like this list. > > I would so love a book like that for python but after i complete htdp > I may not need it. Agreed. I freezed my Racket usage while it was called DrScheme but I keep my eye on it ever since. It is really nice and well designed environment. It took me by a storm, which I cannot say about Idle ;-) . I also agree that every Python programmer could gain something valuable by at least trying it, as well as reading their docs and mailing list for a while. Or every programmer regardless of his/her current language. HTDP is interesting book, pity I couldn't read it when it might have made a bigger difference to my development. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to decide between PHP and Python
On Wed, 5 Jan 2011, Grant Edwards wrote: > On 2011-01-05, Tomasz Rola wrote: > > On Tue, 4 Jan 2011, Roy Smith wrote: > >> Alan Meyer wrote: > >>> On 1/4/2011 4:22 PM, Google Poster wrote: > >>> > >>>> The syntax reminds me of Lots of Interspersed Silly Parentheses > >>>> (L.I.S.P.), but without the parentheses. > >>> > >>> I haven't heard that version before. The one I heard was: > >>> > >>> "Lots of Irritating Single Parentheses". > >> > >> Long Involved Stupid Parentheses. > > > > Heh. One day, guys, when you have nothing better to do, try writing a > > parser for Lisp-like language (Common Lisp, Scheme, whatever). After that, > > do the same with some other language of your preference (Python, Java, > > whatever). Compare time and code spent... > > I've heard that justification many times, but I think it's 200% > specious. > > 1) How often is a compiler for language X written? > > 2) How often is source code written in language X? > > 3) How often is that source code in language X read/modified? > > If you compare those numbers you'll realize that optimizing for case 1 > at the expense of cases 2 & 3 is just plain stupid. You are right here. OTOH, a parser or even a compiler are just nice examples of non-trivial code. IMHO, the more non-trivial task one is trying to perform with a language, the more one appreciates language features that seem nonsense for less trivial programs. While in theory one can do the same job with a shovel and an excavator, in practice one should use the right tool depending on the job. Trying to get a car from a snowdrift with excavator requires a lot of attention and caution. It is easy (even if tiring) task for a man with a shovel. So one could extrapolate from this, that using excavator is ridiculous compared to using shovel. However, building dams or digging mile-long trenches with a shovel is not only ridicule but a sign of bad planning or desperation. And maybe even an incompetence. Now, how often they are building dams, trenches and other nontrivial constructions? I would hypothesise that in a society well developed, this happens quite often. Maybe even once every two days. The truth is, once you have an excavator, you don't shy away from using it and you more often than not are open for doing non-trivial assignments. > Perhaps there is > somebody on the planet who finds Lisp as easy to read/modify as > Python, but I've never met him/her and never have you... Here you are wrong. I meet the guy every day in a mirror. Now you have met him, too. I doubt, however, that I am so extraordinary as to be just one on the whole planet. > Optimizing a language for the ease of the compiler writer is like > saying, sure, that car is expensive to buy, expensive to run, doesn't > work well, and tends to kill a lot of people, but it took less time to > design! I guess every compiled language designed so far has been somewhat optimised for compilation by it's designers. If you say that some language, like Common Lisp, had been optimised for compiler at the expense of human programmer, I disagree. I find programing in CL to be nice experience, maybe even a refreshing one. From what I have read about Lisp history so far, your claims don't match the facts (at least facts as I know them). True, it requires some learning. AFAIK, nobody has to learn, so it is purely voluntary effort. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to decide between PHP and Python
On Tue, 4 Jan 2011, Roy Smith wrote: > There. Now that I've tossed some gasoline on the language wars fire, > I'll duck and run in the other direction :-) May I suggest a better strategy? Run first, duck next :-). Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
setprocname
Hello, Why there is no setprocname function in standard library, or am I missing something? -- http://mail.python.org/mailman/listinfo/python-list
Re: Opinions please -- how big should a single module grow?
On Fri, 9 Jul 2010, Steven D'Aprano wrote: > This is a style question rather than a programming question. > > How large (how many KB, lines, classes, whatever unit of code you like to > measure in) should a module grow before I should break it up into a > package? I see that, for example, decimal.py is > 3000 lines of code, so > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > Where do you draw the line? > > For the purposes of the discussion, you should consider that the code in > the module really does belong together, and that splitting it into sub- > modules would mean arbitrarily separating code into separate files. Myself, I would draw "the line" somewhere between 20-50 KLOC&C (code with comments) - if something takes a lot of place to comment, then maybe it should go to a separate unit. As of the other side of scale, this 3000 KLOC thing, I believe you would have encountered a performance hit. And probably a big one - I would be afraid of some O(n^2) dragon or something bigger, waiting deeply in CPython code to eat your performance. But, I am just fantasizing - I have no idea of CPython internals and how big is the biggest Python code written so far. Python code tends to be very concise, so 3 MLOC sounds rather extremal to me. On the other hand, it is possible nobody tested CPython for such extreme case. Speaking of performance, there is also target user, and her needs (CGI? desktop? etc). So I would take this under consideration, too - how many times per second (minute, day) this code will be executed? Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Opinions please -- how big should a single module grow?
On Fri, 9 Jul 2010, Tomasz Rola wrote: > On Fri, 9 Jul 2010, Steven D'Aprano wrote: > > > This is a style question rather than a programming question. > > > > How large (how many KB, lines, classes, whatever unit of code you like to > > measure in) should a module grow before I should break it up into a > > package? I see that, for example, decimal.py is > 3000 lines of code, so > > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > > Where do you draw the line? > > > > For the purposes of the discussion, you should consider that the code in > > the module really does belong together, and that splitting it into sub- > > modules would mean arbitrarily separating code into separate files. > > Myself, I would draw "the line" somewhere between 20-50 KLOC&C (code with > comments) - if something takes a lot of place to comment, then maybe it > should go to a separate unit. I meant 2-5 KLOC&C. Oups... Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Opinions please -- how big should a single module grow?
And just in case... A real life example (my computer, more or less typical Linux setup): find / -type f -name '*.py' -exec wc {} \; | gawk '{ l+=$1; } END {print l / FNR; } BEGIN { l=0; }' (the two lines should be concatenated) This gives a mean: 269.069 So, if I did not screw something, a typical Python code size is far below 1KLOC (wc counts all lines, so my result includes all comments and blanks too). Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is python not written in C++ ?
On Sun, 1 Aug 2010, John Bokma wrote: > In the beginning of C++ there were programs that just converted C++ to C > (frontends). At least that is how the C++ compiler Acorn sold worked. > So I don't think your argument was much true back then. Those that I (tried to) used on Amiga were based around the same concept. It seems, that Comeau C++ compiler (which I never tried) still requires C compiler as a backend (and is highly regarded by some). Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is python not written in C++ ?
On Sun, 1 Aug 2010, Albert Hopkins wrote: > C seems to be a good, portable language for writing interpreters and > compilers. And one should not forget about performance. C++ was for a long time behind C, and even now some parts (like iostreams) should be avoided in fast code. BTW, C++ can be IMHO a bit tricky in situations when one would like to call back from JIT-generated code into parts written in C++... I mean things like virtual functions, overloading, code generated from templates, accessing private members etc. All those issues are non essential from the point of interpreting or JIT, yet they stand in a way. While this could be solved (with some headache, I suspect), C is far simpler and function calls or manipulating structs are actually trivial... Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list