background preloader

A Byte of Python

A Byte of Python
You have seen how you can reuse code in your program by defining functions once. What if you wanted to reuse a number of functions in other programs that you write? As you might have guessed, the answer is modules. There are various methods of writing modules, but the simplest way is to create a file with a .py extension that contains functions and variables. Another method is to write the modules in the native language in which the Python interpreter itself was written. For example, you can write modules in the C programming language and when compiled, they can be used from your Python code when using the standard Python interpreter. A module can be imported by another program to make use of its functionality. Example (save as module_using_sys.py): import sys print('The command line arguments are:')for i in sys.argv: print i print '\n\nThe PYTHONPATH is', sys.path, '\n' How It Works First, we import the sys module using the import statement. 11.1. 11.2. 11.3. 11.4. 11.5. 11.6. 11.7.

http://www.swaroopch.com/notes/python/

Related:  PythonSTEMschool

Think Python: How to Think Like a Computer Scientist How to Think Like a Computer Scientist by Allen B. Downey PC Buying Guide > The Enthusiast's PC • Excellent performance• Heavy multitasking and everyday computing • Perfect for gaming The Enthusiast's PC incorporates the perfect blend of both the Entry-Level Rig and Luxury System, making this our most balanced build. Our intent is to keep this system within the grasp of the average computer enthusiast, essentially offering a fully loaded PC minus some of the unnecessary bells and whistles that could set you back another grand or two. Motherboard, Processor, Memory In our review, the fourth-generation Core architecture (Haswell) managed to offer a bit more performance for about the same price as Ivy Bridge. The $240 quad-core Core i5-4670K is a suitable replacement for our previous picks, the i5-2500K and i5-3570K.

How to Think Like a Computer Scientist — How to Think Like a Computer Scientist: Learning with Python 2nd Edition documentation Navigation How to Think Like a Computer Scientist¶ Learning with Python¶ 2nd Edition (Using Python 2.x) by Jeffrey Elkner, Allen B. Downey, and Chris Meyers Be careful with exec and eval in Python written on Tuesday, February 1, 2011 One of the perceived features of a dynamic programming language like Python is the ability to execute code from a string. In fact many people are under the impression that this is the main difference between something like Python and C#. That might have been true when the people compared Python to things like C. It's certainly not a necessarily a feature of the language itself. For instance Mono implements the compiler as a service and you can compile C# code at runtime, just like Python compiles code at runtime.

Think Python: How to Think Like a Computer Scientist How to Think Like a Computer Scientist by Allen B. Downey This is the first edition of Think Python, which uses Python 2. If you are using Python 3, you might want to use the second edition, which is here. Dive Into Python 3 You are here: • Dive Into Python 3 Dive Into Python 3 covers Python 3 and its differences from Python 2. Running Linux From a USB Drive As a Virtual Machine or Bootable Disk Live Linux environments work just like a typical operating system but run entirely from a CD or USB stick -- the latter being the most common choice these days. Since nothing is written to the host computer’s local storage, when you’re done all you need to do is remove the media, reboot, and everything will be exactly as it was. There are a number of uses to this, from simply test driving Linux to troubleshooting a Windows PC, or work on the go from someone else’s computer but running your own OS securely with all your personal files and settings. There are basically two options when it comes to running Linux from a USB drive: from within Windows using virtualization software such as VirtualBox, or creating a boot disk.

Computer Science Circles Variables act as "storage locations" for data in a program. They are a way of naming information for later usage. Each variable has a name; an example variable name we will use is myLuckyNumber.

Related:  Python