Python + Motion detection = Fweemote
jedie writes "After reading about different Wiimote hacks on Slashdot I decided to make a video with some demos of my motion-detection library. You can watch the video here. There's a link to the sourcecode (GPL) as well, but the demo is win32 only. It's basically a webcam and some software in python to track LEDs (preferrably IRs). In the demo video, you see the software (albeit badly because of the webcam's IR filter being removed) tracking two differently colored LEDs, so multiplayer is possible. The software can track multiple points easily, and when combined with IR-LEDs, it's easy to simulate one Wiimote (i.e. calculating the distance and angle between two IR-LEDs to determine where the remote is relative to the webcam). I want the code to get some publicity, because I don't have time to work on it (dissertation, blabla) but I don't want the code (however messy it is) to go to waste."
This is not surprising, since I was unable to find any really good Linux python webcam libraries (and by really good, I mean, any that I could get to work).
sigfault. core dumped.
What difference does the language make, you dumb kid? Gah, Slashdot sucks these days, with all these people who think they understand programming.
Your ad here.
So what exactly does that code do? Read an entire directory contents and store the results into an array? The code might look beautiful, but it's no wonder now why python's a memory hog if thats how people use it.
I Browse at +4 Flamebait
Open Source Sysadmin
I don't program in any version of C cuz I can never type those damn square brackets [] correctly the first time lol. I use VB cuz I love the dots! Dot madness!! Just kidding, I use it cuz I like subtracting two date and time values with one command in one line which is why I was gonna say you're partially wrong. It's personal preference but it's not like you can just pick any language and it'll be basically the same. If you choose VB instead of C-anything, you're gonna spend way less time writing the app and it's gonna be a pretty bloated, inefficient app. It's waaay more than preference, it's what the program is gonne be used for. Don't write your backbone apps in VB and don't write a one week little utility project in a C language no matter what language you prefer.
And I don't think your code sample looks pretty lol
Google's Super Secret Search Algorithm: SELECT @search_results FROM internet WHERE @search_results = 'good'
Well, in all fairness, maybe he simply wanted to have the contents of the directory in an array, regardless of the language used? After all, all languages give you the ability to do things in a silly or inefficient manner. Some just look worse than others while doing it ;)
Have you tried this:
import dircache
dircache.listdir('.')
> I don't program in any version of C cuz I can never type those damn square brackets [] correctly
You can't write 'because' either.
It depends on what you're comfortable with. I know a more C than VB, more Perl than C, more Python than Perl. Certain languages may be easier (from whatever point of view) but that doesn't mean they're easier for everyone. Some people do write backbone apps in VB, and some write simple little squirts of software in C. I'm not saying it's a good idea (because I do agree with you) but for some it's just easier to stick with what you know.
Your ad here.
Well yeah, I picked that little snippet because it's a bunch of functions strung together. I can understand some people finding it a bit confusing, but any Python programming with real experience can look at the line I posted and know exactly what it does within a couple seconds. Well, unless they don't know what "dir" does. Even the popen code can be figured out in context.
Your ad here.
Besides, chains like that work in most OO languages.
GLaDOS for President 2016! "Well here we are again. It's always such a pleasure." -- GLaDOS, 2011
I'm sick of people talking about how slow and memory-abusive Python can be. It has changed quite a bit since those negative reviews came out 8 years ago.
Compare it to PHP on the infamous Language Shootout site and you'll see Python is better in every way:
http://shootout.alioth.debian.org/debian/benchmark.php?test=all&lang=python&lang2=php
The same site shows that for both speed and memory use, Python is really better than most other languages. It even beats plain C++/gcc and C# on string manipulations/regex thanks to the optimized standard libraries that it ships with. Best of all, compare the code for these benchmarks and tell me which you would rather maintain. The DNA-regex test is >1500 bytes of gzipped C# and about 300 bytes of python (and yes, the python uses less memory).
In short: write less code with duck typing and intuitive OO & syntax and still run quickly and don't use much memory. Python wins for quickly writing general apps and tools (the "glue" in larger suites).
It seems everytime I log on here there's another article on wiimotes. It's probably time for a Wiimote section, sitting in between Games and Hardware. While you're at it, add one for all these future magic energy storage contraptions that pop up quite a bit.
You can do the same thing in Java and C# if you would like. Seriously. I wonder if you have any proof that Python is a memory hog.
"Thanks for all the money you paid to us. We've used it to buy off ISO among other things" -Microsoft
Python seems to be popular for plugins to some graphics programs. Maybe it could be used to animate virtual puppets in something such as Blender? (Would be cool for recording and choreographing movements if it can actually be worked out.)
Comparing to PHP is like shooting fish in a barrel.
Try this one on for size.
All the crap Pythonites love to boast about and almost universally faster. I'd be careful using the Shootout as a reference though, as not every language gets the love it needs to get a fair shake in such comparisons. In the Python case, Regex DNA has seen some serious love that picked the best concepts from the other implementations in the pursuit of speed. Its place in the ranking is likely not a matter of libraries, as it uses the same libs as the other one.
Note that duck typing restricts the compiler from assuming a function can only take a specific type of object, requiring access to all members and methods of all objects to do a type check first. I like OCaml's typing system for being quite specific, and concise. A tree can be defined thusly in Ocaml:
type tree = Leaf | Node of tree * tree;
Of course, you're missing operations on it, and Objective Caml naturally provides OO ways of doing things. But I've never heavily researched the subject. As I once read and believe, most every pattern in the GoF is trivially obvious in a functional language. I'm also fairly sure they're much simpler to read and write in a functional language.
I Browse at +4 Flamebait
Open Source Sysadmin
"I do love how beautiful the code looks no matter how convoluted you try and write it."
if code aesthetics are really important to you, they you really must go with basic.
10 CLS
20 PRINT "Hello world"
30 END
Look at the beautiful symmetry!
Look at the even row of numbers in one column, and how they prop up the commands sitting beside them.
I must say, BASIC code is truly an example of sublime beauty.
I pity the fool who codes in Python.
-I only code in BASIC.-
However, the C# version was already done by Johnny Chung Lee
"Betta step up yo game"
----- You know you have ego issues when you register a domain in your name.
Convoluted is exactly how I'd describe that horrible piece of buggy, platform-specific code that should be replaced by:
raw = os.listdir(".")http://outcampaign.org/