Python in PHP: Applications Jon Parise 2002 International PHP Conference Frankfurt, Germany November 6, 2002.

Slides:



Advertisements
Similar presentations
Build your own PHP Extension Hanoi PHP Day 2010 Bui Dinh Ngoc AiTi-Aptech - CAH Trưng đào to Lp trình viên Quc t AiTi-Aptech.
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
A Crash Course Python. Python? Isn’t that a snake? Yes, but it is also a...
Python in PHP: Internals Jon Parise 2002 International PHP Conference Frankfurt, Germany November 6, 2002.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Classes and Objects  A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
Introduction to PHP (Part-1) Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
Applying OO Concepts Using Java. In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The.
Python 3 Some material adapted from Upenn cis391 slides and other sources.
Guide to Programming with Python Chapter Nine Working with/Creating Modules.
PHP: Hypertext Processor Fred Durao
August Chapter 1 - Essential PHP spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
V Avon High School Tech Club Agenda Old Business –Delete Files New Business –Week 18 Topics: Intro to HTML/CSS: Questions? Summer Work Letter.
PHP Overview CS PHP PHP = PHP: Hypertext Preprocessor Server-side scripting language that may be embedded into HTML One goal is to get PHP files.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
PHP H ypertext P re-processor. Unit 6 - PHP - Hello World! - Data types - Control structures - Operators.

Understanding the CORBA Model. What is CORBA?  The Common Object Request Broker Architecture (CORBA) allows distributed applications to interoperate.
PHP TUTORIAL. HISTORY OF PHP  PHP as it's known today is actually the successor to a product named PHP/FI.  Created in 1994 by Rasmus Lerdorf, the very.
Builtins, namespaces, functions. There are objects that are predefined in Python Python built-ins When you use something without defining it, it means.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
H3D API Training  Part 3.1: Python – Quick overview.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Python – Part 1 Python Programming Language 1. What is Python? High-level language Interpreted – easy to test and use interactively Object-oriented Open-source.
CIT 590 Intro to Programming First lecture on Java.
An Introduction to Python Blake Brogdon. What is Python?  Python is an interpreted, interactive, object-oriented programming language. (from python.org)
1 Cisco Unified Application Environment Developers Conference 2008© 2008 Cisco Systems, Inc. All rights reserved.Cisco Public Introduction to Etch Scott.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
By James Braunsberg. What are Modules? Modules are files containing Python definitions and statements (ex. name.py) A module’s definitions can be imported.
Python – May 11 Briefing Course overview Introduction to the language Lab.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Comments in PHP In PHP, we use // to make a singleline comment or /* and */ to make a large comment block. Comment is a part of your PHP code that will.
PHP - 1h. How it works Client requests document Server loads document in memory Server processes document with relevant module (PHP) Server sends XHTML.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
JAVA Programming “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
PHP vs. Python. Similarities are interpreted, high level languages with dynamic typing are Open Source are supported by large developer communities are.
Programming Paradigms By Tyler Smith. Event Driven Event driven paradigm means that the program executes code in reaction to events. The limitation of.
Programmeren 1 6 september 2010 HOORCOLLEGE 2: INTERACTIE EN CONDITIES PROGRAMMEREN 1 6 SEPTEMBER 2009 Software Systems - Programming - Week.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Xi Wang Yang Zhang. 1. Easy to learn 2. Clean and readable codes 3. A lot of useful packages, especially for web scraping and text mining 4. Growing popularity.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
12. MODULES Rocky K. C. Chang November 6, 2015 (Based on from Charles Dierbach. Introduction to Computer Science Using Python and William F. Punch and.
C is a high level language (HLL)
Modules. Modules Modules are the highest level program organization unit, usually correspond to source files and serve as libraries of tools. Each file.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
PHP – PHP Hypertext Processor A quick overview. How is PHP used? Embedded with HTML, e.g. Not like CGI: PHP files not an executable Used with servers.
Python PVA Prototype Siniša Veseli Software Engineer AES / Software Services Group EPICS v4 Group Meeting November 19, 2013.
1 Java Review Outline Java Primitives, Program Structure Operators, Control Flow, Loops Classes and Objects Arrays and ArrayList Most of these slides are.
Preface IIntroduction Course Objectives I-2 Oracle Complete Solution I-3 Course Agenda I-4 Tables Used in This Course I-5 The Order Entry Schema I-6 The.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
PHP Programming Language. PHP is a server-side scripting language designed for web development but also used as a general- purpose programming language.
Session 2 Basics of PHP.
Python’s Modules Noah Black.
Introduction Python is an interpreted, object-oriented and high-level programming language, which is different from a compiled one like C/C++/Java. Its.
Introduction to Python
Java Programming Review 1
An Introduction to JavaScript
 A function is a named sequence of statement(s) that performs a computation. It contains  line of code(s) that are executed sequentially from top.
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

Python in PHP: Applications Jon Parise 2002 International PHP Conference Frankfurt, Germany November 6, 2002

Python in PHP: Applications2 About This Session  Familiarity with PHP development practices is expected.  Python knowledge is not required, but familiarity will be helpful. Overview of the Python extension for PHP application developers

November 6, 2002Python in PHP: Applications3 About Me  Bachelor of Science in Information Technology from the Rochester Institute of Technology  Completing Masters of Entertainment Technology at Carnegie Mellon University  Software engineer at Maxis on The Sims Online  Long history of involvement with PHP, PEAR, and The Horde Project  Co-author of Professional PHP4 Programming  Long-time Pythonista!

November 6, 2002Python in PHP: Applications4 Ground Rules  Questions Ask for clarification at any time. Please save scope-expanding questions until the end.  Pacing Ask me to slow down if I move too quickly. I’m from New Jersey.

November 6, 2002Python in PHP: Applications5 Session Agenda  Overview  Benefits  Python Basics  Python in PHP Primer  Case Study: Mailman  PHP From Python  Goals and Considerations  Questions

November 6, 2002Python in PHP: Applications6 Confessions No documentation currently exists on this subject aside from these slides. An official release of the Python extension has yet to be made. Build configuration still needs work.

November 6, 2002Python in PHP: Applications7 What Is The Python Extension?  Embedded Python interpreter  Interface handled by PHP extension  Python-to-PHP object proxy  Handles type conversions  Exposes PHP environment to Python

November 6, 2002Python in PHP: Applications8 PHP Extension Architecture

November 6, 2002Python in PHP: Applications9 Python Extension Architecture

November 6, 2002Python in PHP: Applications10 Benefits  Integration PHP and Python can share common objects in the same system  Component Reuse Existing Python implementations don't need to be rewritten in PHP  Python Excels Python simply does some things better

November 6, 2002Python in PHP: Applications11 About Python  Python is an interpreted scripting language.  Python supports procedural, functional, and object-oriented techniques.  Like Java, nearly everything in Python is an object.  Python is actively developed.  Python is clean and comfortable.

November 6, 2002Python in PHP: Applications12 Python Basics – Indentation  Code blocks controlled by indentation PHP: if (condition) { statement; } Python: if condition: statement

November 6, 2002Python in PHP: Applications13 Python Basics – Variables PHP: $someInteger = 1; $someFloat = 3.14; $someString = 'Hello, Frankfurt!'; Python: someInteger = 1 someFloat = 3.14 someString = 'Hello, Frankfurt!'

November 6, 2002Python in PHP: Applications14 Python Basics – Sequences PHP: $someList = array(0, 1, 2, 3); Python: someTuple = (0, 1, 2, 3) someList = [0, 1, 2, 3]

November 6, 2002Python in PHP: Applications15 Python Basics – Mappings PHP: $someDict = array('one' => 1, 'two' => 2); Python: someDict = {'one' => 1, 'two' => 2}

November 6, 2002Python in PHP: Applications16 Python Basics – Functions PHP: function someFunction($arg1, $arg2) { echo "$arg1 and $arg2"; return $arg2; } Python: def someFunction(arg1, arg2): print arg1, 'and', arg2 return arg2

November 6, 2002Python in PHP: Applications17 Python Basics – Classes PHP: class someClass extends parentClass { function someClass() { echo "Constructor"; } Python: class someClass(parentClass): def __init__(self): print "Constructor"

November 6, 2002Python in PHP: Applications18 Python Basics – Modules  All variables, functions, and classes in a file belong to the same "module"  Similar to Java's "package" system Python: import sys from math import sin, cos

November 6, 2002Python in PHP: Applications19 Python in PHP Primer  All Python execution happens from within the PHP process Same permissions as PHP  The Python environment persists for the life of the PHP request  Type conversion is handled by the Python extension

November 6, 2002Python in PHP: Applications20 Executing Python Code Python: print "Hello, Frankfurt!" PHP: echo py_eval('print "Hello, Frankfurt!"'); Output: Hello, Frankfurt!

November 6, 2002Python in PHP: Applications21 Executing More Python Code Python: fruits = ['apples', 'oranges', 'pears'] for fruit in fruits: print fruit PHP: $code = <<<END fruits = ['apples', 'oranges', 'pears'] for fruit in fruits: print fruit END; py_eval($code);

November 6, 2002Python in PHP: Applications22 Calling Python Functions Python: import math print math.cos(0) PHP: echo py_call('math', 'cos', array(0)); Output: 1

November 6, 2002Python in PHP: Applications23 PHP to Python Type Conversion PHP  Boolean  Long (Integer)  Double (Float)  String  Array  Object  Null Python  Integer  Long  Double  String  Dictionary  None

November 6, 2002Python in PHP: Applications24 Python to PHP Type Conversion Python  Integer  Long  Float  String  Sequence  Mapping  Object  None PHP  Long  Double  String  Array  Associative Array  PHP Python Object  NULL

November 6, 2002Python in PHP: Applications25 About Python Objects  The Python extension proxies Python objects  Python objects are represented as instances of a "python" class in PHP PHP: object(python)(1) { [0]=> int(4) }

November 6, 2002Python in PHP: Applications26 Creating Python Objects  Python objects are creating using the Python() object constructor Python (test.py): class TestClass: def __init__(self, s): print 'TestClass:', s PHP: $test = new Python('test', 'TestClass', array('Test Argument'));

November 6, 2002Python in PHP: Applications27 Manipulating Python Objects  Python objects work like PHP objects Python (test.py): class TestClass: def __init__(self): self.name = 'Testing' def get_name(self): return self.name PHP: $test = new Python('test', 'TestClass'); echo $test->name; echo $test->get_name();

November 6, 2002Python in PHP: Applications28 Case Study – Mailman  Mailman is a popular mailing list manager  Mailman is written in Python  Let's build a PHP interface to Mailman!

November 6, 2002Python in PHP: Applications29 Mailman – Retrieving the Lists /* Add Mailman paths to sys.path. */ py_path_prepend('/usr/local/mailman'); py_path_prepend('/usr/local/mailman/pythonlib'); /* Import the Mailman.MailList module. */ py_import('Mailman.MailList'); /* Retrieve a list of all know mailing lists. */ $names = py_call('Mailman.Utils', 'list_names');

November 6, 2002Python in PHP: Applications30 Mailman – Displaying Details foreach ($names as $name) { /* Create a new MailList object. */ $list = new Python('Mailman.MailList', 'MailList', array($name, 0)); /* Display the list details. */ echo "Name: $name\n"; echo "Desc: $list->description\n"; echo "Link: $list->web_page_url\n"; echo "\n"; }

November 6, 2002Python in PHP: Applications31 Mailman – Sample Output Name: mailman Desc: Mailman Administration Link: Name: test Desc: Test Mailing List Link: Name: pip Desc: Python in PHP Mailing List Link:

November 6, 2002Python in PHP: Applications32 The PHP Python Module  Allows access to the PHP environment from within the embedded Python environment  Functionality is still very limited! PHP: $test = 'This is a test'; Python: import php print php.var('test')

November 6, 2002Python in PHP: Applications33 Python Extension INI Options python.prepend_path  Prepends a list of paths to sys.path  Just like py_path_prepend() python.append_path  Appends a list of paths to sys.path  Just like py_path_append()

November 6, 2002Python in PHP: Applications34 Building the Python Extension $ cd pear/PECL/python $ pear build running: phpize PHP Api Version : Zend Module Api No : Zend Extension Api No : Python installation directory? [autodetect] : building in /var/tmp/pear-build-jon/python-0.1 running: /home/jon/src/pear/PECL/python/configure --with-python running: make python.so copied to /home/jon/src/pear/PECL/python/python.so

November 6, 2002Python in PHP: Applications35 Goals and Considerations  Performance Multiple interpreters Threading  Exception Handling  Security File system restrictions Execution restrictions sys.path modification

November 6, 2002Python in PHP: Applications36 Questions

November 6, 2002Python in PHP: Applications37 References Presentation Slides Python in PHP Python