Oktatás * Programozás 2 * Szkriptnyelvek * levelezősök Félévek Linkek * kalendárium |
Py3 /
20130920aKis- és nagybetűk felcserélve Játékos Jancsika már megint figyelmetlen volt. Angolból esszét kellett írnia a Python programozási nyelvről, s ehhez a fater "The Art of Unix Programming" c. könyvéből kimásolta az idevágó fejezetet. Viszont nagy igyekezetében nem vette észre, hogy az első paragrafus végén véletlenül lenyomta a Caps Lock billentyűt. Csak a végén döbbent rá, hogy baj van, de az egész szöveget már nem akarta újra bepötyögni. Egy kétségbeesett levélben elküldte nekünk a szöveget, s a segítségünket kéri. Az esszé beküldési határideje éjfél, s Jancsika levelét 23.40-kor kaptuk meg. Tudunk segíteni Jancsikának, hogy meglegyen az aláírása? Íme a mellékelt szöveg: Python Python is a scripting language designed for close integration with C. It can both import data from and export data to dynamically loaded C libraries, and can be called as an embedded scripting language from C. Its syntax is rather like a cross between that of C and the Modula family, but has the unusual feature that block structure is actually controlled by indentation (there is no analog of explicit begin/end or C curly brackets). Python was first publicly released in 1991. tHE pYTHON LANGUAGE IS A VERY CLEAN, ELEGANT DESIGN WITH EXCELLENT MODULARITY FEATURES. iT OFFERS DESIGNERS THE OPTION TO WRITE IN AN OBJECT-ORIENTED STYLE BUT DOES NOT FORCE THAT CHOICE (IT CAN BE CODED IN A MORE CLASSICALLY PROCEDURAL c-LIKE WAY). iT HAS A TYPE SYSTEM COMPARABLE IN EXPRESSIVE POWER TO pERL'S, INCLUDING DYNAMIC CONTAINER OBJECTS AND ASSOCIATION LISTS, BUT LESS IDIOSYNCRATIC (ACTUALLY, IT IS A MATTER OF RECORD THAT pERL'S OBJECT SYSTEM WAS BUILT IN IMITATION OF pYTHON'S). iT EVEN PLEASES lISP HACKERS WITH ANONYMOUS LAMBDAS (FUNCTION-VALUED OBJECTS THAT CAN BE PASSED AROUND AND USED BY ITERATORS). pYTHON SHIPS WITH THE tK TOOLKIT, WHICH CAN BE USED TO EASILY BUILD gui INTERFACES. tHE STANDARD pYTHON DISTRIBUTION INCLUDES CLIENT CLASSES FOR MOST OF THE IMPORTANT iNTERNET PROTOCOLS (smtp, ftp, pop3, imap, http) AND GENERATOR CLASSES FOR html. iT IS THEREFORE VERY WELL SUITED TO BUILDING PROTOCOL ROBOTS AND NETWORK ADMINISTRATIVE PLUMBING. iT IS ALSO EXCELLENT FOR wEB cgi WORK, AND COMPETES SUCCESSFULLY WITH pERL AT THE HIGH-COMPLEXITY END OF THAT APPLICATION AREA. oF ALL THE INTERPRETED LANGUAGES WE DESCRIBE, pYTHON AND jAVA ARE THE TWO MOST CLEARLY SUITED FOR SCALING UP TO LARGE COMPLEX PROJECTS WITH MANY COOPERATING DEVELOPERS. iN MANY WAYS pYTHON IS SIMPLER THAN jAVA, AND ITS FRIENDLINESS TO RAPID PROTOTYPING MAY GIVE IT AN EDGE OVER jAVA FOR STANDALONE USE IN APPLICATIONS THAT ARE NEITHER HUGELY COMPLEX NOR SPEED CRITICAL. aN IMPLEMENTATION OF pYTHON IN jAVA, DESIGNED TO FACILITATE MIXED USE OF THESE TWO LANGUAGES, IS AVAILABLE AND IN PRODUCTION USE; IT IS CALLED jYTHON. pYTHON CANNOT COMPETE WITH c OR c++ ON RAW EXECUTION SPEED (THOUGH USING A MIXED-LANGUAGE STRATEGY ON TODAY'S FAST PROCESSORS PROBABLY MAKES THAT RELATIVELY UNIMPORTANT). iN FACT IT'S GENERALLY THOUGHT TO BE THE LEAST EFFICIENT AND SLOWEST OF THE MAJOR SCRIPTING LANGUAGES, A PRICE IT PAYS FOR RUNTIME TYPE POLYMORPHISM. bEWARE OF REJECTING pYTHON ON THESE GROUNDS, HOWEVER; MOST APPLICATIONS DO NOT ACTUALLY NEED BETTER PERFORMANCE THAN pYTHON OFFERS, AND EVEN THOSE THAT APPEAR TO ARE GENERALLY LIMITED BY EXTERNAL LATENCIES SUCH AS NETWORK OR DISK WAITS THAT ENTIRELY SWAMP THE EFFECTS OF pYTHON'S INTERPRETIVE OVERHEAD. aLSO, BY WAY OF COMPENSATION, pYTHON IS EXCEPTIONALLY EASY TO COMBINE WITH c, SO PERFORMANCE-CRITICAL pYTHON MODULES CAN BE READILY TRANSLATED INTO THAT LANGUAGE FOR SUBSTANTIAL SPEED GAINS. pYTHON LOSES IN EXPRESSIVENESS TO pERL FOR SMALL PROJECTS AND GLUE SCRIPTS HEAVILY DEPENDENT ON REGULAR-EXPRESSION CAPABILITY. iT WOULD BE OVERKILL FOR TINY PROJECTS, TO WHICH SHELL OR tCL MIGHT BE BETTER SUITED. lIKE pERL, pYTHON HAS A WELL-ESTABLISHED DEVELOPMENT COMMUNITY WITH A CENTRAL WEBSITE CARRYING A GREAT MANY USEFUL pYTHON IMPLEMENTATIONS, TOOLS AND EXTENSION MODULES. tHE DEFINITIVE pYTHON REFERENCE IS pROGRAMMING pYTHON [lUTZ]. eXTENSIVE ON-LINE DOCUMENTATION ON pYTHON EXTENSIONS IS ALSO AVAILABLE AT THE pYTHON WEBSITE. pYTHON PROGRAMS TEND TO BE QUITE PORTABLE BETWEEN uNIXES AND EVEN ACROSS OTHER OPERATING SYSTEMS; THE STANDARD LIBRARY IS POWERFUL ENOUGH TO SIGNIFICANTLY CUT THE USE OF NONPORTABLE HELPER PROGRAMS. pYTHON IMPLEMENTATIONS ARE AVAILABLE FOR mICROSOFT OPERATING SYSTEMS AND FOR mACos. cROSS-PLATFORM gui DEVELOPMENT IS POSSIBLE WITH EITHER tK OR TWO OTHER TOOLKITS. pYTHON/c APPLICATIONS CAN BE ‘FROZEN’, QUASI-COMPILED INTO PURE c SOURCES THAT SHOULD BE PORTABLE TO SYSTEMS WITH NO pYTHON INSTALLED. sUMMING UP: pYTHON'S BEST SIDE IS THAT IT ENCOURAGES CLEAN, READABLE CODE AND COMBINES ACCESSIBILITY WITH SCALING UP WELL TO LARGE PROJECTS. iTS WORST SIDE IS INEFFICIENCY AND SLOWNESS, NOT JUST RELATIVE TO COMPILED LANGUAGES BUT RELATIVE TO OTHER SCRIPTING LANGUAGES AS WELL. a sMALL pYTHON cASE sTUDY: IMGSIZER iMGSIZER IS A UTILITY THAT REWRITES www PAGES SO THAT IMAGE-INCLUSION TAGS GET THE RIGHT IMAGE SIZE PARAMETERS AUTOMATICALLY PLUGGED IN (THIS SPEEDS UP PAGE LOADING ON MANY BROWSERS). yOU CAN FIND SOURCES AND DOCUMENTATION IN THE url www TOOLS SUBDIRECTORY OF THE IBIBLIO ARCHIVE. IMGSIZER WAS ORIGINALLY WRITTEN IN pERL, AND WAS A NEARLY IDEAL EXAMPLE OF THE SORT OF SMALL, PATTERN-DRIVEN TEXT-PROCESSING TOOL AT WHICH pERL EXCELS. iT WAS LATER TRANSLATED TO pYTHON TO TAKE ADVANTAGE OF pYTHON'S LIBRARY SUPPORT FOR http FETCHING; THIS ELIMINATED A DEPENDENCY ON AN EXTERNAL PAGE-FETCHING UTILITY. oBSERVE THE USE OF FILE(1) AND iMAGEmAGICK IDENTIFY(1) AS SPECIALIST TOOLS FOR EXTRACTING THE PIXEL SIZES OF IMAGES. tHE DYNAMIC STRING HANDLING AND SOPHISTICATED REGULAR-EXPRESSION MATCHING REQUIRED WOULD HAVE MADE IMGSIZER QUITE PAINFUL TO WRITE IN c OR c++; THAT VERSION WOULD ALSO HAVE BEEN MUCH LARGER AND HARDER TO READ. jAVA WOULD HAVE SOLVED THE IMPLICIT MEMORY-MANAGEMENT PROBLEM, BUT IS HARDLY MORE EXPRESSIVE THAN c OR c++ AT TEXT PATTERN MATCHING. a mEDIUM-sIZED pYTHON cASE sTUDY: FETCHMAILCONF iN cHAPTER 11 WE EXAMINED THE FETCHMAIL/FETCHMAILCONF PAIR AS AN EXAMPLE OF ONE WAY TO SEPARATE IMPLEMENTATION FROM INTERFACE. pYTHON'S STRENGTHS ARE WELL ILLUSTRATED BY FETCHMAILCONF. FETCHMAILCONF USES THE tK TOOLKIT TO IMPLEMENT A MULTI-PANEL gui CONFIGURATION EDITOR (pYTHON BINDINGS ALSO EXIST FOR gtk+ AND OTHER TOOLKITS, BUT tK BINDINGS SHIP WITH EVERY pYTHON INTERPRETER). iN EXPERT MODE, THE gui SUPPORTS EDITING OF ABOUT SIXTY ATTRIBUTES DIVIDED AMONG THREE PANEL LEVELS. aTTRIBUTE WIDGETS INCLUDE A MIX OF CHECKBOXES, RADIO BUTTONS, TEXT FIELDS, AND SCROLLING LISTBOXES. dESPITE THIS COMPLEXITY, THE FIRST FULLY-FUNCTIONAL VERSION OF THE CONFIGURATOR TOOK ME LESS THAN A WEEK TO DESIGN AND CODE, COUNTING THE FOUR DAYS IT TOOK TO LEARN pYTHON AND tK. pYTHON EXCELS AT RAPID PROTOTYPING OF gui INTERFACES, AND (AS FETCHMAILCONF ILLUSTRATES) SUCH PROTOTYPES ARE OFTEN DELIVERABLE. pERL AND tCL HAVE SIMILAR STRENGTHS IN THIS AREA (INCLUDING THE tK TOOLKIT, WHICH WAS WRITTEN FOR tCL) BUT ARE HARD TO CONTROL AT THE COMPLEXITY LEVEL (APPROXIMATELY 1400 LINES) OF FETCHMAILCONF. eMACS lISP IS NOT SUITED FOR gui PROGRAMMING. cHOOSING jAVA WOULD HAVE INCREASED THE COMPLEXITY OVERHEAD OF THIS PROGRAMMING TASK WITHOUT DELIVERING SIGNIFICANT BENEFITS FOR THIS NONSPEED-INTENSIVE APPLICATION. a lARGE pYTHON cASE sTUDY: pil pil, THE pYTHON iMAGING lIBRARY, SUPPORTS THE MANIPULATION OF BITMAP GRAPHICS. iT SUPPORTS MANY POPULAR FORMATS, INCLUDING png, jpeg, bmp, tiff, ppm, xbm, AND gif. pYTHON PROGRAMS CAN USE IT TO CONVERT AND TRANSFORM IMAGES; SUPPORTED TRANSFORMATIONS INCLUDE CROPPING, ROTATION, SCALING, AND SHEARING. pIXEL EDITING, IMAGE CONVOLUTION, AND COLOR-SPACE CONVERSIONS ARE ALSO SUPPORTED. tHE pil DISTRIBUTION INCLUDES pYTHON PROGRAMS THAT MAKE THESE LIBRARY FACILITIES AVAILABLE FROM THE COMMAND LINE. tHUS pil CAN BE USED EITHER FOR BATCH-MODE IMAGE TRANSFORMATION OR AS A STRONG TOOLKIT OVER WHICH TO IMPLEMENT PROGRAM-DRIVEN IMAGE PROCESSING OF BITMAPS. tHE IMPLEMENTATION OF pil ILLUSTRATES THE WAY pYTHON CAN BE READILY AUGMENTED WITH LOADABLE OBJECT-CODE EXTENSIONS TO THE pYTHON INTERPRETER. tHE LIBRARY CORE, IMPLEMENTING FUNDAMENTAL OPERATIONS ON BITMAP OBJECTS, IS WRITTEN IN c FOR SPEED. tHE UPPER LEVELS AND SEQUENCING LOGIC ARE IN pYTHON, SLOWER BUT MUCH EASIER TO READ AND MODIFY AND EXTEND. tHE ANALOGOUS TOOLKIT WOULD BE DIFFICULT OR IMPOSSIBLE TO WRITE IN eMACS lISP OR SHELL, WHICH DON'T HAVE OR DON'T DOCUMENT A c EXTENSION INTERFACE AT ALL. tCL HAS A GOOD c EXTENSION FACILITY, BUT pil WOULD BE AN UNCOMFORTABLY LARGE PROJECT IN tCL. pERL HAS SUCH FACILITIES (pERL xs), BUT THEY ARE AD-HOC, POORLY DOCUMENTED, COMPLEX, AND UNSTABLE BY COMPARISON TO pYTHON'S AND USE OF THEM IS RARE. jAVA'S nATIVE mETHOD iNTERFACE APPEARS TO PROVIDE A FACILITY ROUGHLY COMPARABLE TO pYTHON'S; pil WOULD PROBABLY HAVE MADE A REASONABLE jAVA PROJECT. tHE pil CODE AND DOCUMENTATION IS AVAILABLE AT THE PROJECT WEBSITE. Megjegyzés: oldjuk meg Pythonban is a problémát, de gondolkozzunk el más megoldási lehetősége(ke)n is. Tipp: nézzük meg, hogy egy sztringnek van-e valamilyen |
Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |