background preloader

Programming for Everybody

Programming for Everybody

labs :: 10 Python pitfalls (or however many I'll find ;-) These are not necessarily warts or flaws; rather, they are (side effects of) language features that often trip up newbies, and sometimes experienced programmers. Incomplete understanding of some core Python behavior may cause people to get bitten by these. This document is meant as some sort of guideline to those who are new to Python. It's better to learn about the pitfalls early, than to encounter them in production code shortly before a deadline. :-} It is *not* meant to criticize the language; as said, most of these pitfalls are not due to language flaws. 1. OK, this is a cheesy one to start with. Solution: Indent consistently. 2. People coming from statically typed languages like Pascal and C often assume that Python variables and assignment work the same as in their language of choice. a = b = 3 a = 4 print a, b # 4, 3 However, then they run into trouble when using mutable objects. a = [1, 2, 3] b = a a.append(4) print b # b is now [1, 2, 3, 4] as well

Spatial Courses Online - Anytime, Anywhere | Discover Spatial When does the course start and finish? The course starts now and never ends! It is a completely self-paced online course - you decide when you start and when you finish. How long do I have access to the course? How does lifetime access sound? There's only 5 Modules! Response to the course has been incredible, which we really appreciate. To keep updated when we release new modules, head over to blog.mangomap.com and sign up for our mailing list.

labs :: Python beginner's mistakes Every Python programmer had to learn the language at one time, and started out as a beginner. Beginners make mistakes. This article highlights a few common mistakes, including some I made myself. Beginner's mistakes are not Python's fault, nor the beginner's. They're merely a result of misunderstanding the language. To put it another way, the mistakes in this article are often cases of "the wrong tool for the job", rather than coding errors or sneaky language traps. Mistake 1: trying to do low-level operations Python is sometimes described as a VHLL, a Very High-Level Language. This doesn't mean that it isn't possible to do these things with Python; but it's probably just not the right language for these jobs. Mistake 2: writing "language X" code in Python This is a mistake that is almost unavoidable. Some notorious symptoms of "language X" code, and the languages that may cause them: The point here is not to slam the language that you're used to (although that is always fun ;-).

Free GIS Programming Tutorials: Learn How to Code - GIS Geography What do successful self-taught GIS programmers eat for breakfast? A healthy dose of Python, JavaScript, SQL, VB.NET, C++, HTML, CSS… In that order are the most popular GIS programming languages. It’s not necessary to have GIS programming skills to land a job in the industry. But it’s a feather in your cap if you do. And it will certainly help. If you’re just starting out, we flaunt some of the best, free GIS programming resources available to pave your way to coding competency: GIS Programming in Applications – Python, C++, .NET, C# Python has been a standard language in GIS because Esri and open source tend to gravitate toward it. In addition to Python, C++, C# and .NET languages exist in GIS: C++ lets you work in multiple environments. We suggest to learn Python first because its usually the first language a company looks for. Here are 3 bare-boned courses to start your journey into Python programming: Programming Foundation with Python (Udacity) – Actively learn to code in Python for free.

Hands-On Python A Tutorial Introduction for Beginners Hands-On Python A Tutorial Introduction for Beginners Contents Chapter 1 Beginning With Python 1.1. You have probably used computers to do all sorts of useful and interesting things. 1.1.1. First let us place Python programming in the context of the computer hardware. z = x+y is an instruction in many high-level languages that means something like: Access the value stored at a location labeled x Calculate the sum of this value and the value stored at a location labeled y Store the result in a location labeled z. No computer understands the high-level instruction directly; it is not in machine language. Obviously high-level languages were a great advance in clarity! If you follow a broad introduction to computing, you will learn more about the layers that connect low-level digital computer circuits to high-level languages. 1.1.2. There are many high-level languages. 1.1.3. If you are not sure whether your computer already has Python, continue to Section 1.2.2 , and give it a try. Windows Linux 1.2.

Courseware | EMS Open Educational Resources The "courseware modules" linked below represent substantial portions of the resources provided to students who register in participating Penn State classes. These resources are available for reuse by teachers and learners worldwide who do not intend to apply for admission, register for classes, or pursue a certificate or degree at Penn State. The resources are freely available for non-commercial use under a Creative Commons license. Please let us know what you think! Our faculty are anxious to learn more about your interest in their open courseware! Want to Register for Academic Credit? To gain access to Penn State faculty and earn academic credit, you need to register for classes. Listing of Open Courseware by Academic Unit Department of Energy and Mineral Engineering Department of Geography GEOG 030: Geographic Perspectives on Sustainability and Human-Environment Systems Authors: Petra Tschakert, Karl Zimmerer, Brian King, Seth Baum, and Chongming Wang. Department of Geosciences

Python Introduction - Google's Python Class - Google Code Python is a dynamic, interpreted language. Source code does not declare the types of variables or parameters or methods. This makes the code short and flexible, and you lose the compile-time type checking in the source code. Python tracks the types of all values at runtime and flags code that does not make sense as it runs. (todo: link here to the companion video segment for this section) An excellent way to see how Python code works is to run the Python interpreter and type code right into it. Python Program Python source files use the ".py" extension. Here's a very simple Python hello.py program (notice that blocks of code are delimited strictly using indentation rather than curly braces -- more on this later!) #! # import modules used here -- sys is a very standard oneimport sys # Gather our code in a main() functiondef main(): print 'Hello there', sys.argv[1] # Command line args are in sys.argv[1], sys.argv[2] ... # sys.argv[0] is the script name itself and can be ignored Python Module

Building Your GIS Skills: Anytime, Anywhere | Research Commons Call me biased, but I think the best time for learning more about GIS is… anytime! For many, it seems like the summer is a prime time for seeking out resources to build up skills using Geographic Information Systems (GIS). Over the past few weeks, I’ve received numerous requests from OSU faculty, staff, and students asking about self-paced training modules available for ArcGIS Desktop in particular. ArcGIS Desktop is available for free to all OSU faculty, staff and students through an Esri site license managed by the OCIO and can be downloaded through the OCIO self-service catalog. Once you’re ready to get started, you can choose from a variety of great self-paced training modules provided by Esri: 1) Learn ArcGIS Lessons Esri’s Learn ArcGIS lesson gallery provides “guided lessons based on real-world problems,” including Bridging the Breast Cancer Divide and Find Areas at Risk of Flooding in a Cloudburst. 2) SpatiaLABS 3) Getting to Know ArcGIS

Python In One Easy Lesson Nick Parlante Nov 2010 This is a one-hour introduction to Python used for Stanford's CS107. This material should work as an introduction for any experienced programmer. Python is a popular open source, cross-platform language in the "dynamic language" niche, like Javascript, Ruby, Lisp, and Perl. Unlike C/C++, Python defers almost everything until runtime. This is how Python works, in contrast to the C/C++ style of knowing the type of every variable and using that for compile time code generation. x = x + x In Python, x could be an int, or a string, or who knows what. Interpreter and Variables You can run the Python interpreter and type code directly in to it -- a good way to try little experiments. Strings Strings are delimited with ' or " or """, and are immutable. >>> a = 'hello' >>> len(a) 5 >>> a[0] 'h' >>> a + '!!!' Lists [ ], For Loop List literals are enclosed in square brackets. Program syntax, if/else, Indentation #! Dict { } Hash Table Sorting Custom sorting Lambda (optional)

A Python Book: Beginning Python, Advanced Python, and Python Exercises 2.2 Regular Expressions For more help on regular expressions, see: 2.2.1 Defining regular expressions A regular expression pattern is a sequence of characters that will match sequences of characters in a target. The patterns or regular expressions can be defined as follows: Literal characters must match exactly. Because of the use of backslashes in patterns, you are usually better off defining regular expressions with raw strings, e.g. r"abc". 2.2.2 Compiling regular expressions When a regular expression is to be used more than once, you should consider compiling it. import sys, re pat = re.compile('aa[bc]*dd') while 1: line = raw_input('Enter a line ("q" to quit):') if line == 'q': break if pat.search(line): print 'matched:', line else: print 'no match:', line Comments: We import module re in order to use regular expresions.re.compile() compiles a regular expression so that we can reuse the compiled regular expression without compiling it repeatedly. 2.2.3 Using regular expressions Notes:

Non-Programmer's Tutorial for Python 3 Authors Contributors to this book Front matter Initial remarks Intro Installing and using Python – where to get help Hello, World The famous first program – screen output – variables – numbers and calculations Who Goes There? Interactive input – strings Count to 10 while loops Decisions if statements Debugging Finding out what goes wrong Defining Functions Structuring programs with the use of functions Advanced Functions Example (Almost) mind-blowing example of how programmers can think Lists Variables containing more than one value For Loops A second kind of loop Boolean Expressions Computer logic – True and False – and and or – not Dictionaries Variables containing key/value pairs Using Modules Extensions to the standard set of functionality More on Lists Using elements or parts of lists Revenge of the Strings More advanced text manipulations File IO Reading from files and writing to files Dealing with the imperfect How to handle errors Recursion Recursive Functions Intro to Object Oriented Programming in Python 3 The End

Google's Python Class - Educational Materials Welcome to Google's Python Class -- this is a free class for people with a little bit of programming experience who want to learn Python. The class includes written materials, lecture videos, and lots of code exercises to practice Python coding. These materials are used within Google to introduce Python to people who have just a little programming experience. The first exercises work on basic Python concepts like strings and lists, building up to the later exercises which are full programs dealing with text files, processes, and http connections. The class is geared for people who have a little bit of programming experience in some language, enough to know what a "variable" or "if statement" is. To get started, the Python sections are linked at the left -- Python Set Up to get Python installed on your machine, Python Introduction for an introduction to the language, and then Python Strings starts the coding material, leading to the first exercise.

Python Programming Python Programming From Wikibooks, open books for an open world Jump to: navigation, search This book describes Python, an open-source general-purpose interpreted programming language available for a broad range of operating systems. There are currently three major implementations: the standard implementation written in C, Jython written in Java, and IronPython written in C# for the .NET environment. Contents[edit] Intro[edit] Overview Getting Python Setting it up Interactive mode Self Help Basics[edit] Creating Python programs Variables and Strings Basic syntax Sequences (Strings, Lists, Tuples, Dictionaries, Sets) Data types Numbers Strings Lists Tuples Dictionaries Sets Basic Math -- redundant to "Operators" Operators Control Flow Decision Control Conditional Statements Loops Functions Scoping Input and output Files Text Modules Classes Exceptions Errors Source Documentation and Comments Idioms Advanced[edit] Decorators Context Managers Reflection Metaclasses Namespace Tips and Tricks Modules[edit] Standard library modules[edit]

The Python Tutorial Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms. The Python interpreter and the extensive standard library are freely available in source or binary form for all major platforms from the Python Web site, and may be freely distributed. The same site also contains distributions of and pointers to many free third party Python modules, programs and tools, and additional documentation. The Python interpreter is easily extended with new functions and data types implemented in C or C++ (or other languages callable from C). This tutorial introduces the reader informally to the basic concepts and features of the Python language and system.

Related: