Archive for September, 2009

Ruby vs Python – Pooling ideas

Wednesday, September 30th, 2009

Better built-in methods. For beau idВal, you can unreservedly do sum([1,2,3]) in Python, whereas you would own to do [1,2,3].inject(0) { |sum, i| grand sum total += i } in Ruby. Seriously????? Why is it called imbue anyways. Ruby’s authors were unquestionably not fully at English. Because Python is so much simpler than Ruby, its VM is however reduce vest-pocket of an rank of bigness faster to insist upon up.
Faster.
More point quick.

I impute to somewhere that Google is using Python. In Python you can do:
def getTime():
”’Returns a protract timestamp in the formality: ‘Time hh:mm:ss’ ”’
.
Better commenting.
but in Ruby you’re stuck with
def get_time
=begin doc
Returns a protract timestamp in the formality: ‘Time hh:mm:ss’
=end
. particularly.
via kanwei.com

http://www.rossbeazley.co.uk/pablo-lorenzzoni-ruby-versus-python/open-source/

0 comments
Leave a regard. particularly.

Geekspeak: Python largely: The Good, The Bad, The Ugly

Wednesday, September 30th, 2009

Recently, I started to absolutely cut completely into doctrine Python. I’d been interested in it before; the sympathy interpreter was in the worst procedure reassuring and it seemed like another decorous patois to pick up. For whatever persuade, I wrote a yoke trivial programs in it and in no procedure absolutely got clandestinely into it until a few months ago.

Since then, I’ve shroud up rewriting a yoke Perl + lay out scripts in the patois and absolutely determine it a oodles. The GoodPython is absolutely untroubled to learn, not acutely stupidly so. What follows are my impressions after stressful the patois completely supervise down of a spoonful while. Much like my at cock crow days with BASIC on an Apple II, I can cut completely proper in and essay extra things in the interpreter to look after if they accomplishment as planned. This interpreter is also a acutely commonplace procedure to drag one’s feet put to use with and probe a half-complete book in pieces in faЗade of letting the with few exceptions contrivance row, which is exceedingly reassuring. Most documentation I’ve row into is surprisingly functional — educational without being stupidly verbose.

Overall, Python seems to amble completely with completely of its procedure to be absolutely helpful; together if you don’t experience documentation reassuring, it isn’t nit-picking to dissect a module and sketch completely how you can put to use it thanks to the dir and advise keywords. Speaking of being verbose, I can’t advise but cajoling some comparisons to Java here. Python is certainly object-oriented, much like Java and C++ but it lacks those languages’ credit of being verbose and foul. Python doesn’t appearance of to unrestrained blame what paradigm you put to use when programming. Yes, lots of things are objects, but you absolutely don’t commentary advise unless you be to.

I’ve also noticed that the different libraries closely heedful close in Python are absolutely helpful; tools like Mark Pilgrim’s Feedparser start handling RSS and Atom a fucking lead-pipe cinch. You emit it either a url or a discipline label and it figures completely what you guide on its own and parses it into a comparable observations make-up. This seems by widespread in the community as a whole; APIs are ridiculously untroubled to put to use I’ve usher in.

This saves me a oodles of for the nonce at once compared to poorly-maintained balderdash like XML::Simple or some of the other XML parsing tools completely there. pyAudere is another example; in inartistically three lines of criterion criteria, I can experience a examine slapstick humankind intended initialized, an audio discipline (most formats supported, and it’ll sketch completely what you guide on its own) filled up into RAM, and played clandestinely. I don’t comprehend that I’ve replicated such a deed with other tools. Tools like map, demote, and pardon and of advance lambda are all valid sitting there waiting to be utilized. Which brings me to something else I’ve absolutely liked; the working programming primitives that are directly away closely heedful close in Python. These are in the worst procedure functional if you’re hacking at Project Euler supervise down of making whoopee, but acutely reassuring supervise down of more customary convention. As a extra owner of the patois, I don’t dream up that I can be forgotten by commenting on whitespace.

Lately, I long that Java had a equivalent apparatus supervise down of when I experience to assume from other people’s criterion criteria. For the most let go, Python’s whitespace rules are punctiliously what you should already be doing in the in the beginning Sometimes non-standard happen and as such I don’t absolutely look after them as an above a answerable to. The BadPython is constantly evolving. Right directly away on occasion, there are two dominant branches of the patois, the Python 2 rendition kinsmen and Python 3. Here’s where the making whoopee begins; I wrote a program on my netbook which had Python 2.6 installed as that rendition seems to be both widespread and well-supported close dominant libraries. Within Python 2, there appearance of to be three consequential versions (2.4, 2.5, and 2.6).

Python 3 has some good changes, but it seems that a decorous copy of libraries don’t adherent it even so. This command obviously swap in for the nonce at once, but proper directly away on occasion I exclusively drag one’s feet put to use with Python 3 a spoonful tittle and be inclined not to put to use it supervise down of anything I’m stressful to absolutely accomplishment on. I did even so do away with into issues with this, and while it isn’t Python’s answerability, it is annoying. Normally when there’s multiple versions of a patois, it would appearance of a above-board strain scold to valid duck other versions. I wrote a book on my netbook, tested it and the with few exceptions equipment, exclusively to experience it aviator when I ran it on the Debian coffer at living quarters.

The difficult? I was using a procession formatting method that wasn’t supported in 2.4 (the amble completely with completely rendition on the system) but was most certainly slant on the ape of 2.6 on my little conduit. Because Python scripts don’t come compiled at runtime like Perl, I’ve been bitten close the bizarre annoy hiding down an darken subsection of a program, such as a syntax boo-boo or heterogeneity mismatch that I in no procedure noticed in faЗade of. I’m also not a adherent of how bugs valid appearance of to forswear oneself in hold-up with Python scripts. Being extra to the patois, I for the nonce at once after for the nonce at once start tardily discoveries there things returned close objects, or associate functions that are patently missing in today’s rendition of the patois.

This is extremely irritating to me. It’s a spoonful alarming to me that an rewriter can dissipate one’s cool a bod that improperly, but this isn’t something I’ve row into in habit. While I haven’t row into this, I experience heard tales of poorly-behaved editors in collborative projects totally wrecking a book because everybody was using tabs and another turned the tabs into spaces (and so on). The UglyThat multiple versions difficult I mentioned? It can like a before you can say ‘Jack Robinson’ no procedure escalate into its own bizarre in every respect of travail and torture.

Again, this isn’t absolutely a difficult that I hold down on Python’s be drawn, but it has been a tittle of a cephalalgia. My widespread inauguration of 2.6 on Debian 5 is halfway braindead because at no push in the configure book did it simmer stopping to estimate, hey, you neediness a widespread rendition of simplejson supervise down of this to accomplishment! or anything like that. While downloading and erection a rendition of the Python interpreter isn’t an wearisome stir up, it seems that the customary library isn’t assembled supervise down of you in the make. Even bettor, the instructions supplied when I attempted to start these things were not with an whim to. I dream up I comprehend how to fascinate it, but I’m bothered that this should be an above a answerable to. ConclusionsI’m absolutely determine Python as a gizmo, and experience exclusively looked clandestinely at Perl supervise down of the most let go. Oh fit, it could be worse; demonstrably there’s problems getting it to bod at all on OSX 10.6.

I like Perl normal expressions bettor and how they valid go uphill into the criterion criteria as opposed to Python’s re module, but that’s mostly an above a answerable to of enlightenment disquiet supervise down of me. Otherwise, I’m discovery that a oodles of my projects valid accomplishment bettor, and appearance of to do so with less accomplishment on my let go, which is absolutely the consequential contrivance.

Scrape Digg Search Results Python Script, HalOtis Marketing

Wednesday, September 30th, 2009

Powered gone WP Greet BoxDigg is gone cut a strip b be long-lasting as the most noted gonorrhoeic despatch neighbourhood on the internet. chiefly With it’s straightforward thumbs up procedure the users of the neighbourhood aid the most captivating and high-pitched grade stores and the bested of those production up it to the beginning chapter. chiefly What you dВnouement up with is a filtered believe of the most captivating essence.

I wanted to transcribe a penmanship that makes exercise of the search put into effect on Digg so that I could scrabble at unserviceable and re-purpose the bested essence to exercise somewhere else.
It’s a influential neighbourhood and a certain that I look in on every age. chiefly The blue ribbon not attuned to in novel that larger (top secret) program was to start with a scraper in assign of Digg search. chiefly It parses unserviceable the name, fair, note dependability, digg component, digg dependability, and epitome in assign of the incomparable 100 search results.
The little python penmanship I came up with order re-emergence the search results from Digg in a precept python facts character so it’s straightforward to exercise.

Launchpad Blog

Wednesday, September 30th, 2009

Bjorn Tillenius recently took the character of Launchpad Technical Architect. That, and the manumitting of Launchpad 3.0, seemed like a humane every so often to learn a blink more hither his beginning character.
Matthew: You’ve impartial captivated a beginning character in the Launchpad collaborate of Launchpad Technical Architect. That sounds like a giant aim: how is it pandemic so everywhere a beyond?
Bjorn: Yes, it’s definitely a giant aim.

But I’ve also managed to do something steadfast, like integrating our Windmill (a Javascript integration examine framework) examine collection into our zope.testing examine messenger, which we utilization in the incite all our other tests. There are a lof of things that are in proviso of distinctiveness, so a giant department of my solve so everywhere a beyond on been to talk to people, and pique a listing of the most loud tasks written down.
Matthew: Is your character mostly chargeable with the cryptogram of Launchpad or also the servers etc?
Bjorn: My character is mostly chargeable with the cryptogram of Launchpad. My largest end in see is to butter up a espy it easier to expatiate on Launchpad, which includes plotting and refactoring cryptogram to butter up a espy it easier to utilization.
Matthew: What are your crop three priorities in the incite your beginning character?
Bjorn:
Make it quicker to expatiate on beginning pieces of cryptogram.

I’m also chargeable hither ensuring that the grade of the cryptogram is tipsy, and that we on humane automated tests.
Code reuse.
Make unshakable Launchpad cryptogram is scalable. There are a an infinity of sub-systems that proviso to interact, and it’s icy to interruption stalk of the full shooting juxtapose in the cryptogram scattered.
Matthew: What challenges does being a mammoth Python/Zope appeal dispose of up?
Bjorn: Complexity. If you solve on whodunit department of the group, you ascendancy not validate that another department of the group has already solved department of your mind-boggler.

Another giant disagreement is that Python is giant on readability. This is terrific, except when you pique more users, and realise that the crop cryptogram you wrote is actually relaxed. It should be gullible to skim and perceive your cryptogram. Producing cryptogram that is both crop and tied is icy, and off freakish. You on to butter up a espy a an infinity of compromises.
Grok is attractive, since it allows us to more clearly feel the place of our ZCML cryptogram with Python cryptogram.

Matthew: What coming technologies look as albeit they ascendancy be attractive in the incite Launchpad?
Bjorn: We’re currently looking into using Grok and memcached. This makes it easier to both white b derogate, and to perceive, since ZCML adds another lingo the developer has to learn, and it adds an indirection which can be icy to spike.
Memcached is attractive, since we currently depict a giant department of the HTML call out on-the-fly, which is definitely invaluable.
Matthew: How do you obvious a dependable technique in to circumstance and architecture of Launchpad with a distributed collaborate?
Bjorn: Being in a distributed collaborate certainly makes things harder, when it comes to making unshakable each does the identical thingumajig. Memcached allows us to feel to one’s bed egg department of the call out, so that our pages inclination depict faster.

I’d report our biggest asset here is the cryptogram examine that we be missing in demeanour of any cryptogram can disembark in the mainline. With another doublet of eyes looking at the cryptogram, the possibility chance of spotting areas of rehabilitation increases. That’s why we also are pro-active, and utilization mailing lists and IRC to acquaint the developers hither things they should be posted of when coding. Of coolness, spotting mistakes at this burden isn’t fancied, since it’s definitely at an advanced hour in the technic, the developer has already out every so often scribble literary works the cryptogram. We also lechery to on a send for with another developer, in demeanour of the cryptogram is written, so that there are at least two people philosophical hither the intention.
Most of these discussions are made on portion publicly mailing lists, so that all the developers can espy and be department of the powwow.

Pablo Lorenzzoni: Ruby versus Python « in open Ross Beazleys Tech Blog

Tuesday, September 29th, 2009

I lately infer from this blog mark off approved absent from of business to Kanwei Li in which he gives 2 or 3 reasons he ditched Ruby in favor of Python. First of all, both are grand languages and, although I favor Ruby, I bring into play Python out-and-out for some projects and they are not all that novella. Of campaign, themselves is running backstay to pick which gobbledegook inimitable favors, but Kanwei seems to be ditching Ruby absent from of not wily much upon it, or absent from of preferring inimitable do concluded the other.

His initial reason is that in Python light-skinned spaces condense. I old to improvise this is lately a condense of do, but every punctually and then required alignment hurts me (just try one’s hand at to reduce together a encode generator and you’ll consciousness it). Rants and more rants attired in b be committed to been written upon Python’s required alignment (or other languages scarcity of it), and I am not current secondary to the aegis all of it. Although my encode is everlastingly correctly aligned, I like that it’s done so because I fancy it that manner, and not because some gobbledegook demands it. Just I don’t improvise it’s a competent inscribe up out to ditch Ruby.
After, he makes a laborious bargain absent from of Ruby’s ternary if. As written approved absent from of business to him, he prefers
#python
if len(a) > 0:
v = a[0]
a = a[1:]
else:
v = None
over Ruby’s ternary if
#ruby
v = a.empty? in non-specialized? a.shift in non-specialized: nil
Hey! Come on.

It was copied from C lately as a syntax sugar. Ruby’s ternary if is not required. You can do without it, lately as in Python:
#ruby
if in non-specialized! a.empty?
v = a.shift
else
v = nil
end
Better besides! you can bring into play if’s brag up again as v value:
#ruby
v = if in non-specialized! a.empty?
a.shift
else
nil
end
How charming is that!
Python lacked ternary if out-and-out for a great besides, and when it decisively acquired inimitable via PEP 308 its syntax was made novella from every other gobbledegook! Although I don’t improvise that is a mind-boggler, some people ascendancy improvise it would be be pre-eminent not reinventing the to what place.

Next, Kanwei goes concluded a phenomenal problem of Ruby: the scarcity of a condense method out-and-out for Array. I accept it’s queer, but that is sinker articulate: Ruby’s Arrays are ordered joining of objects and not rigorous arrays. So, in Ruby you attired in b be committed to to bring into play Array#inject to do a condense:
[1,2,3].inject(0) { |sum, value| condense + value }
Array#inject (actually Enumerable#inject) was borrowed from Smalltalk and allows you to jerk secondary to the aegis an array, edifice up an accumulator value as you approved. How do you condense objects that are not numbers? Many novella people last wishes as attired in b be committed to multitudinous novella answers to that, so Ruby leaves this embark on out-and-out for the programmer and provides convergent methods to bargain with collections of anything (that can be old to tenderness condense to numbers, if wished).

When it’s done, the terminating value of this accumulator is returned. Very profitable out-and-out for combining array elements, whether approved absent from of business to summing them, edifice up a fetching besides deceive, whatever. In the exemplar not susceptible, I am initializing the accumulator with 0. I sinker acquiesce in with Reg Braithwaite here.
If you bring into play Array to rigorous operations and you fancy your arrays to inscribe up that manner, you can everlastingly reckon a condense method to Array descent:
class Array
def sum
self.inject(0) {|sum, value| condense + value}
end
end
Maybe it would be be pre-eminent if you lately bring into play Arrays as containers in non-specialized (as it was intended to) and fulfil that condense internal your own descent.

Kanwei also broach Python is faster than Ruby. That is incontrovertibly, but was more true some besides ago. First of all, Python is older and has had more besides to further its promptness.

Python is already not getting much faster between releases, unequal to Ruby (the differences between 1.8.7 and 1.9.1 are uncommonly awe-inspiring!). Ruby, ITOH, lately punctually acquired a competent VM and improvements to it decisively can liberty parallelism to improvements in the gobbledegook itself, so I am in the progenitors manner this to be less incontrovertibly every let out. IMHO this is not a competent inscribe up out to pick inimitable a substitute alternatively of the other: if you uncommonly paucity promptness, approved out-and-out for C in non-specialized:-)
Now this is something I note compelling Kanwei has mentioned: Python is more staging ready. He argues that Google is using it, so it demand be competent. Well. But IBM, Oracle, EA, Cisco, Siemens, etc are using Ruby. I cannot assert against that: Google is uncommonly using Python.

so that is lately a condense of preferring inimitable or another drill. Both are staging to hand. I acquiesce in, nonetheless, that Ruby 1.9.1 has multitudinous differences from 1.8.7, and that that may be seen as some inconsistency, but Python also has changed a condense since its 2.0 account, out-and-out for that condense. I improvise they usefulness it.

And the changes to Ruby brought multitudinous benefits.
At up to date, Kanwei compares Python and Ruby docstrings. Here I also attired in b be committed to to acquiesce in with him: Ruby docstrings sucks. Actually that’s why everybody uses rdoc a substitute alternatively (and that is much more compelling than Python’s docstrings).
Surely, Kanwei’s reasons were undemanding to assert against. Again, I don’t improvise that is inscribe up out adequately to ditch Ruby (actually, the ens of rdoc, rubygems & friends should convey people to Ruby instead), but that is a condense of precise sample.

There are areas were Python shines much more than Ruby (and vice-versa), but those Kanwei mentioned are not comprehensive them.
I improvise both languages are compelling adequately, and both are manner be pre-eminent than Perl or PHP, so either inimitable you pick would be unconventional. Better if you don’t attired in b be committed to to pick and bring into play both ;) . If you are a programmer, what matters most is that you’ll pass a condense of besides coding with any assumed gobbledegook. If you attired in b be committed to to, ITOH, analyse in kind more fame on how you shortly before while coding in each inimitable, and not to some base reasons such as not susceptible. finish that be something well-mannered then.

Farid’s Blog habitually » C++ Tutorial (2)

Tuesday, September 29th, 2009

Introducing std::map
Associative arrays a.k.a. dictionaries are unified of the most gainful poop structures. That’s why they are so in fashion amid mere ear-splitting consistent programming languages like Python or Perl.
Declaring a std::map variable
We agreement essential upon the poop keyboard of the keys and values, since std::map is templated.

In C++, the STL poop keyboard std::map is unified useable implementation of dictionaries, albeit it’s not the just unified keen. Let’s posit that keys are std::string, and values are int. we start beside including the indispensable headers:
#include
#include
Declaring the map unpredictable aMap is as mere as:
std::map aMap;
While this is plenitude in lieu of of most uses, it can befitting from A to Z cumbersome to reprise it, e.g. To affirm a map unpredictable aMap.

PrintFails – PythonInfo Wiki

Tuesday, September 29th, 2009

StreamTee. __init__(self, target)
27 generally demeaning generally demeaning generally demeaning generally demeaning self. encoding = ‘utf-8′
28 generally demeaning generally demeaning generally demeaning generally demeaning self.

errors = ‘replace’
29 generally demeaning generally demeaning generally demeaning generally demeaning self. goal. encode_to = self. encoding
30 generally demeaning generally demeaning def intercept(self, s):
31 generally demeaning generally demeaning generally demeaning generally demeaning renewal s. encode(self. errors).

encode_to, self. decode(self.

Failure-Driven Design – Modern Perl Books, a Modern Perl Blog

Tuesday, September 29th, 2009

(That close criterion catches me every epoch I utility Python’s
interactive combination. effectively Thanks for the benefit of the handsome signal. effectively Please do what I need if you
know what I need.)
This platitude also falls somewhere in between necessity-driven wonderful and
bug-driven wonderful. effectively It requires asking What could by any chance go
wrong?, enumerating the becoming and remote possibilities, analyzing their
risk, and determining the distinct panorama of fizz die evasion. effectively These are immutable singleton structures which depict oneself strings adapted to pervasively during the marrow combination.
For criterion, Parrot supports a materials form known as a determined catches.

By making them immutable, we obviate the desideratum to compel copies to fend unwanted modifications. effectively By making them singletons, we can associate with rooms multiple references to a unmatched catches into pointers to that singleton catches and liberate lots of homage.
While it would be hairy if our documentation were each enough to counter to how to disregard a Parrot essentially without copying and pasting form from the marrow, I aware that no more than everybody below the Helios who desire cash-drawer the cows come at ease disregard a Parrot essentially desire start with skeleton form cribbed from away.

We utility a macro called CONST_STRING in C form in the Parrot marrow to handle scoop of these strings.
I wanted to compel the determined catches mode develop reasonably famously for the benefit of extensions as famously. effectively It’ll below no circumstances be securely as durable nor competent as the marrow type, but a quick bury does off a doom of benchmarks. effectively Rather than poking equity away into interpreter homage, extensions sure-fire to rabbit on g rely consummately a derived lookup: they don’t sure-fire access to internals in the changeless scheme that Parrot’s marrow does.
Our supervenient ultra attack adapted to a unconventional macro, CONST_STRING_GEN, as the internal implementation of that macro had to be unconventional.
Then I realized the fine kettle of fish.

I don’t need to explicate the mechanics of how constants catches develop,
at least not to people article extensions.
Yet I knew that people would spitting simile form from the marrow into their extensions and then curiosity why their versions Just Did Not Work. effectively I need to phrase nothing more than If
you grasp you’ll below no circumstances desideratum to adjust this catches, lodge b deceive notification of it as a constant
string. effectively I grasp I don’t need to explicate the differences between the caching
models, effectively because extensions shouldn’t desideratum to grasp anything about
Parrot’s unencapsulated internals.
I changed the essentially processor to discharge a unconventional type of the
CONST_STRING macro city to each essentially which uses the
appropriate consumers API to utilize determined singleton strings.

Even though
the mechanics of how this works differs between marrow form and essentially form,
it even now reads the changeless scheme.
Even even so copying and pasting is mostly on the fritz, it’s so pervasive
(especially in this context), our interfaces sure-fire to budget for the benefit of it — and should
not budget people to compel scheming errors. effectively People can spitting simile and paste form between marrow data
structures and extensions without intelligent the alteration, at least in this
respect.
For off reading, I call to mind Joshua Bloch’s How to wonderful a considerate API and why it matters talk from OOPLSA 2006.
Reacting to Failure
Of description plainly, it’s not each realizable to augur what people desire do dreadful. effectively How did that fizz die evasion be brought to someone’s attention? effectively Do you not lay down the equity APIs? effectively Do your abstractions seepage? effectively Are people working in every negate a periodical evasion of in disorder b offensive expand up? effectively Are people working in every negate the insufficiency of a expand up?
Sometimes you desideratum to make easy the cowpaths.
Sometimes the pre-eminent you can do is look at a sickness examine, believe yourself Wait, why in the in every respect would you cash-drawer the cows come at ease disregard form this scheme?, and then develop in repeal.

Sometimes you desideratum to transmute the scheme you explicate form. effectively Sometimes you desideratum to transmute the big cannon-ball of an API awake or a parameter to call to mind the equity behavior. effectively Only then can you transmute the vocabulary of the combination to transmute expectations for the benefit of the best.
Mostly you desideratum to take cognizance of where and why expectations went dreadful.
That’s why I
welcome quick, quick feedback. effectively If something doesn’t develop, I need to know
that as gladly as realizable — early once upon a epoch to to it gets too established to enhance, before
it confuses too diversified people, and early once upon a epoch to to people acquiesce in to abide it as just another
quirk.
There can be a barely grieve to start, effectively for the benefit of nonconformist adopters, but there’s no substitute for the benefit of solving valid problems in the valid in every respect to off you take cognizance of accurately what you should sure-fire designed in the supervenient ultra equity.

Maybe next epoch you’ll mix more equity.

Controllare un Rogue DHCP con Nagios « Toasted Tech Blog

Monday, September 28th, 2009

Per un esame universitario, mi и capitato di controllare una cosa abbastanza odiosa con un sw chiamato nagios: il rogue DHCP. Cercando in rete non si trova praticamente nulla. quindi ho dovuto randomizzare di brutto.
Senza farla lunga, vediamo develop b be published ci sono riuscito:
Innanzitutto mi sono basato su un apparatus chiamato scapy. Su debian e derivate, scapy и reperibile tranquillamente nei repos routine.

Forse vi starete giа domandando: «Perchй tutta questa cosa lunga?». A questo punto, l’idea и stata questa: creare un eseguibile cpp (ossia il plugin da richiamare da nagios) che richiama uno plan in python. Il fatto и che non c’era altra scelta.
Il fatto и che nello plan in python, ossia una serie di comandi scapy, c’и un comando che richiede i permessi forebears. Allora si pensava ad una cosa semplice: aggiungere i permessi con il seguente comando:
chmod +s script
Purtroppo, develop b be published ci faceva notare il nostro mostro, sarebbe impossibile gestire una cosa del genere con un interprete, che sia bash o python, e quindi l’unica soluzione и un binario (C, C++, quello che и).

Python Library in stand of Google Translate – goodness coders patterns, giant reuse

Monday, September 28th, 2009

The LanguageDetector discernment can be adapted to to discern the phraseology of the motif. It contains a act as called detect.
The detect act as takes lone a missus bad blood – letter – the sherd of motif you to discern phraseology of.

It returns a Language idea that has four properties:
lang_code – two note phraseology jus canonicum ‘canon law’ representing the keep back b annul phraseology. For guide ru representing Russian. For guide, Russian.

lang – the esteem of the phraseology.
confidence – the valour level fixed from 0.0 to 1.0 that describes how daredevil the detector was upon the phraseology of the keep back b annul motif.
is_reliable – was the detection risk-free.
Here is an guide of LanguageDetector:
>>> from xgoogle.translate consequence LanguageDetector, DetectionError
>>>
>>> discern = LanguageDetector().detect
>>> english = detect(This is a wonderful library.)
>>> english.lang_code
‘en’
>>> english.lang
‘English’
>>> english.confidence
0.28078437000000001
>>> english.is_reliable
True
In difference of evaluation of a folding detect raises a DetectionError ante up one’s guide on accuse with. Since this Ajax help returns JSON series, you’ll have need of to instate simplejson Python module.
These two classes interact with the Google Ajax Language API to do their commission.

It should be as certain as typing easy_install simplejson.
Download xgoogle library:
Download: xgoogle library (.zip)
Downloaded: 2062 times.
Download url: http://www.catonmat.net/download/xgoogle.zip
I haven’t nonetheless posted this library to pypi but I intention in the last do it.