E N D
News Aggregator • A news aggregator refers to a system including software application, webpage or service that collects syndicated content using RSS and other XML feeds from weblogs and mainstream media sites. Aggregators improve upon the time and effort needed to regularly check websites of interest for updates, creating a unique information space or "personal newspaper." An aggregator is able to subscribe to a feed, check for new content at user-determined intervals, and retrieve the content. The content is sometimes described as being "pulled" to the subscriber, as opposed to "pushed" with email or other channels. Unlike recipients of some "pushed" information, the aggregator user can easily unsubscribe from a feed. • Software which allows syndicated news content (such as RSS feeds) to be brought together and displayed.
Introduction of Python For Engr 101 5-Week News Aggregator Module Fall 2010 Instructor: Tao Wang
Software / Programs • Computer Programs instruct the CPU which operations it should perform/execute • Programmers write the code for the tasks a computer program performs • But computers only understand binary (1’s and 0’s) • Programmers need a language to write computer code
Types of Programming Languages Low-Level Languages • Machine Languages • CPU instructions are binary strings of 1’s and 0’s [10010000] • Each kind of CPU has different instruction sets • Programs are not portable across CPU’s architectures • Difficult for programmers to read/write • Assembly Languages • Use English-like abbreviations to represent CPU instructions • A bit easier to understand [MOV AL, 42h] • Converted to machine language using an assembler • Still not portable
Types of Programming Languages High-Level Languages • C/C++, Java/C#, Python, Ruby, many more... • These languages abstract hardware implementation details • Provides programmers a logical computer model • Allows programmer to focus on solving problems instead of low-level hardware details • Use English-like keywords and statements to write code • Use a compiler or interpreter that translates code to machine language • Makes code portable across different CPU’s and platforms • Programmer does not have to learn each CPU’s instructions
Compiled vs. Interpreted • Both Compilers and Interpreters translate source code to machine language • Compiled • Must compile program on each target CPU architecture prior to execution. • Interpreted • Code can be directly run on any platform that has an available interpreter
About Python • Designed by Guido van Rossum in late 1980’s • Interpreted programming language • Imperative, Dynamic, and Object-Oriented • Python Programs • are a sequence of instructions written in Python language • interpreter executes the instructions sequentially, in order • programs can take inputs and send data to outputs • programs can process and manipulate data • programs may read and write data to RAM, Hard Drive, ... • First Program • print “Welcome to learning Python.“
PYTHON: LETS BEGIN • The Python Shell (2.6) • You type commands • It does stuff • It converts python to machines instructions and runs them right now
Python as Calculator >> 2 + 2 # add 4 >> 2 * 3 # muliply 6 >> 3**2 # powers 9 >> 12 % 11 #modulo (remainder) 1
Division • Integer division • 1/4 #Integer division, no decimals • 0 • Float division • 1.0/4.0 #float number division • 0.25
Literals, Data Types Numbers • Integers are natural numbers: ..., -2, -1, 0, 1, 2, ... (32 bits) • Floats contain decimals: 4.5, 67.444443335, 7E2... • Booleans: True, False • Long int’s that exceed 32 bit capacity • Complex numbers: 4.5, 1j * 1j = -1 + 0j Strings • Strings are used to represent words, text, and characters • examples (can use single, double or triple quotes): • “I am learning python.“ • 'hello.'
Variables • Literals are data values that our program use • Data is stored in memory, and we need a way to access it • We use variables to name our data in memory • We can retrieve data by calling the name that refers to it • student_name = “Ben” • print student_name • = is the assignment operator, assigns a data value to a variable
Variables Syntax Rules • Variable names must begin with a letter (uppercase or lowercase) or underscore (_) • * good programming convention: variables should not start with uppercase letters, commonly used for something else • remainder of name can contain letters, (_), and numbers • names may not contain spaces or special characters • names are case sensitive and must not be a reserved python keyword • myVariableandmyvariablerefer to different data
Statements and Expressions • Statement perform a task; do not return a value • x = 2 • y = 3 • print y • Expression return a value • >> x+ y • 5
Expressions (evaluate to values) • Math expressions • >> 10 * 2 + 3 • >> 10 * (2.0 + 3) • Boolean expressions • >> 10 < 2 # False • >> 10 >=10 # True • Combined with logic operators • >> (10<2) or (10==10) • Can combine • >> (a*c+d) > (d*a-c)
Expressions (evaluate to values) • String expressions • >> “hel” + “lo” # ‘hello’ • >> “Hi” * 3 # ‘HiHiHi’ • Operator Precedence • Parentheses • Exponentiation • Multiplication and Division • Addition and Subtraction
Data Types • Finding out a data type
Data Types • What if data types don’t match? • STRONG TYPES no automatic conversion (for non number types)
Data Types • Explicit conversion
Python Keywords • RESERVED: do not use as variable names
User Input • Create interactive programs by requesting user input
Branching / Conditional Statements • Decision making
if - statement if a < 0: print “a is negative”
if - elif - else • If one test fails, perform next test
Modules • Python Strength: large collection of open source modules • •Modules are collections (packages) of useful (tested) code you can reuse • Common modules: random, math • The modules we use for the project: • urllib, xml
Modules • Python Standard Library (packages included with most python distributions) • http://docs.python.org/library/index.html • PyPI (Python Package Index) • http://pypi.python.org/pypi • repository of optional modules available (11,000+)
Using Modules • Math module contains many useful functions and values: math.sin, math.cos, math.pow, math.sqrt, ... • Using modules:
Getting help • In python interpreter you can get documentation
Repetition • selection statements (if-elif-else) let us make simple decisions • repeating statements and decisions let us build more complex programs
break statement • break immediately ends loops • DO NOT overuse; Can be difficult to read/understand logic
range(...) • Built in function; produces a sequence (list) • range(0, 3) [0, 1, 2] • range(3) [0, 1, 2] • range(1, 3) [1, 2] • range(1,7,2) [1, 3, 5]
for • The for loop is used for iteration
continue statement • break and continue work in both while and for loops
Nesting Control Structures • We can nest control structures (if, while, for) • We can nest many times while … while … while … If … for ... • There is a limit; If you reach it, something is WRONG • Abuse makes code unreadable; Use functions instead... (more in a bit)