₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,326,468 members, 8,426,668 topics. Date: Sunday, 14 June 2026 at 05:46 PM

Toggle theme

Alexis's Posts

Nairaland ForumAlexis's ProfileAlexis's Posts

1 2 3 4 5 6 7 8 ... 48 49 50 51 52 53 54 55 56 (of 66 pages)

ProgrammingRe: Python Programming by alexis(m): 10:37pm On Nov 10, 2008
Hi Seun,

Well, I will continue to update the tutorial as time permit.

I have a good friend that has taken keen interest in cherrypy - I think he has built a couple of apps with them i.e. a system for searching of hotels in west africa and a couple of others. I downloaded and tried it, pretty neat.
PoliticsRe: Naval Officers Beat Up A Lady And Stripped Her - Watch Video by alexis(m): 7:07pm On Nov 06, 2008
If this would have happened in Warri or where we have some of the militants - you can be sure that these so called "naval ratings" would have been attacked. Hard Justice? - I don't care as far as they get what they deserve

A soldier is to defend his fellow country men & his country - these assholes have no honor and dignity. A man is not a man that beats a woman.

I attended a navy school and I know how it is. These guys have no combat training, no code of honor and worst of all; all they know how to do is shoot a gun - we all can do that.
ProgrammingRe: Python Programming by alexis(m): 5:22pm On Nov 06, 2008
Hi Guys,

In our last tutorial, we made use of Python variables, operators, strings etc. Today, we will be dealing with Branching, while Loops, and Program Planning. These are some of the stuffs you will learn:

1. Using randrange() to generate random numbers
2. Use if structures to execute code based on a condition
3. Use if-else structures to make a choice based on a condition
4. Use if-else-elif structures to make a choice based on several conditions
5. Use while loops to repeat parts of your program

GENERATING RANDOM NUMBERS

Sometimes we wonder how a game can change it's strategy or an alien appears out of nowhere. Random numbers can supply this element of surprise. Python provides an easy way to generate random numbers.

Let us simulate the roll of two, six-sided dice. The program will display the value of each dice and their total. To determine the dice values, the program uses a function that generates random numbers.

Here is the Python Code

# This Program demonstrates random number generation
# Alex Dehaini - November 5th, 2008 - (The day Obama won the elections, hehe)

import random

# generate random numbers 1 - 6
die1 = random.randrange(6) + 1
die2 = random.randrange(6) + 1

total = die1 + die2

print "You rolled a", die1, "and a", die2, "for a total of", total

raw_input("\n\nPress the enter key to exit."wink


EXPLANATION

Using the import Statement
The first line of code in the program introduces the import statement. The statement allows you to import, or load, modules, in this case the random module in:

import random

Modules are files that contain code meant to be used in other programs. These modules usually group together a collection of programming related to one area. The random module contains functions related to generating random numbers and producing random results.

Once you import a module, you can use its code. Then, it just becomes a matter of accessing it.

Accessing randrange()
The random module contains a function, randrange(), which produces a random integer. The program accesses randrange() through the following function call:

random.randrange(6)

You'll notice the program doesn't directly call randrange(). Instead, it's called with random.randrange(), because the program accesses randrange() through its module, random. In general, you can call a function from an imported module by giving the module name, followed by a period, followed by the function call itself. This method of access is called dot notation. Dot notation is like the possessive in English. In English, "Mike's Ferrari" means that it's the Ferrari that belongs to Mike. Using dot notation, random.randrange() means the function randrange() that belongs to the module random. Dot notation can be used to access different elements of imported modules.

Now that you know how to access randrange(), you need to know how to use it.

Using randrange()
There are several ways to call randrange(), but the simplest is to use a single, positive, integer argument. Called this way, the function returns a random integer from, and including, 0, up to, but not including, that number. So the call random.randrange(6) produces either a 0, 1, 2, 3, 4, or 5. Alright, where's the 6? Well, randrange() is picking a random number from a group of six numbers—and the list of numbers starts with 0. You may think this is odd, but you'll find that most computer languages start counting at 0 instead of 1. So, I just added 1 to the result to get the right values for a die:

die1 = random.randrange(6) + 1

Now, die1 gets either a 1, 2, 3, 4, 5, or 6.

Oya, save your file as random.py and run in on your command line or terminal. Coll huh?
ProgrammingRe: Web Development Opportunity In Python And Django by alexis(m): 1:23pm On Nov 01, 2008
There are Nigerian Python programmers, maybe not in Nigeria at the moment but Nigerians none-the-less. I will answer why I use Django in our earlier thread.
ProgrammingRe: How Well Do You Thik You Can Apply "programmers" ? by alexis(m): 1:07pm On Nov 01, 2008
Why should we do other people's work for them. Asking for directions and advice is one thing but asking others to do your work is plain laziness.
ComputersRe: Which Os Can You Use Efficiently? by alexis(m): 10:22am On Oct 31, 2008
Hmmm,

Where do I start

1. MAC - been using MAC since panther came out, feel in love with it once I saw the BSD core. Sweet OS
2. Unix - FreeBSD, rock-solid unix OS. Run a couple of our server on freeBSD i.e. DNS, firewall, bandwidth manager
3. Linux - Centos, Debian, Fedora. Love Centos and use it extensively. Direct replica of Redhat Enterprise/Advanced Server. Heck, you can even run redhat rpms on Centos.
4. Windows - In my opinion, Windows 2000 & 2000 Server & advanced Server are the most stable in the windows family. If you lock them down pretty well, they will run fine.
ProgrammingRe: Python Programming by alexis(m): 10:11am On Oct 31, 2008
I don't see why one can't use a python framework web server, there is nothing wrong with it. However, when it comes to scalability and flexibility - it is advisable to proxy a framework web server through Apache.

My reasons are simple

1. Apache is well known and most people know how to use it
2. Pretty stable and you can scale well.

@pystar

I do a lot of internal web stuff. We have funny requirements where I work. I mainly use python to write network scripts and recently started using web2py and django

On Google App Engine
web2py is the only framework that allows to develop on your own platform and then run the app, unmodified on the Google App Engine (with the limitations imposed by the App Engine). No need to rewrite the model since the web2py database abstraction layer supports the Google Query Language.

@WordSmith
Nope, haven't written any desktop app so I can't advice in this area. What kind of GUI app would you like to build?
ProgrammingRe: Python Programming by alexis(m): 9:54am On Oct 31, 2008
@dami9ja,

I am sorry jare, been so busy. I haven't been following the thread, just checked it yesterday. I am excited that we have people that love python. I have listed the pros and cons of python in my earlier post. I will start the tutorial again but let me answer a few questions.

@Seun

Like I said, never used CherryPy but I am aware it is a object-oriented HTTP framework. So, I am kind of surprised you don't do OOP but hey - it's flexible to allow you code in the way you want. There are many reasons we use different frameworks, you mentioned what you like in a framework. web2py satisfy the requirements you mentioned and much more.

1) web2py is very stable since day one so it performs very well
2) Similar to Django. All request data is in one place. You can use .get_vars and .post_vars instead of .vars to be more specific.
3) CherryPy works very much like Rails and default mapping between URL and action can be overwritten. Similar to Rails and CherryPy but, by default the URL requires that you specify the name of the app. This allows web2py to run multiple apps without using routes. Web2py has its own version of routes that supports two different syntax's (with and without regular expression) to overwrite the mapping and reverse mapping as well.

Reasons I like web2py

1) Model-View-Controller design - Web frameworks implement MVC support in different ways and as a result, they might force you to do things in certain ways i.e. I learned that from CakePHP.
2) Does not require any third party library. Only Python 2.5 standard libraries.
3) Designed for security. URLs are validated, forms are validated, template variables are escaped, SQL is escaped, no client side storage (other than session cookie) and it never exposes application code. FORMs enforce navigation and prevent double submission.
4) A database administrative interface to browse, insert, edit, update and delete records. It also allows import/export in csv.
5) Database Abstraction Layer for interfacing the database in Python without SQL
6) View/Template language with full Python support but with no indentation requirements
7) Full web based application development, deployment and administration
cool Zero installation - I love this
9) Web based Module Designer - Sweeeeeeet!
10) Caching - Can specify where to cache and what to cache

web2py is wsgi compliant.comes with the cherrypy wsgi fast and ssl-enabled web server. It runs with apache and mod_proxy or mod_rewrite or mod_wsgi. It runs with lightpd with FastCGI. It runs as CGI script.

It is very well documented. I will talk about Django in my next post.

Again, I am excited I am talking to other python developers. Heard Python 3 is coming out, can't wait.
ProgrammingRe: Python Programming by alexis(m): 1:03pm On Oct 13, 2008
If you use cherrypy, then you will love web2py http://mdp.cti.depaul.edu/.

Then there is django http://www.djangoproject.com/

Seun - done any work with python?
ProgrammingRe: Ready To Help On Your Programming, Just by alexis(m): 4:35pm On Oct 10, 2008
It appals me that after 4-5 years in a university in Nigeria as a Computer Science student, people come on public forums asking other people to code their final year projects.

What happens if you were given the same project on your job, what would you do?
Tech JobsRe: Programmers In C++ Needed Urgently by alexis(m): 4:31pm On Oct 10, 2008
If there is code document, kindly let me see it.
ProgrammingRe: Python Programming by alexis(m): 4:09pm On Oct 10, 2008
I haven't done anything with python on the public domain. All my work are internal to the companies I have worked for. But I can share some source code and perhaps start a short tutorial on python

PYTHON TUTORIAL

SETTING UP PYTHON

Setting up or installing python is pretty simple. Go to http://www.python.org/download/ and download the python version for your OS. I reckon most people use windows. Download the Windows installer, once the download is completed, install python as you would install any other windows application.

For other OS users i.e. Linux and MAC - most times python comes installed by default. If not, don't panic - python is a breeze to install. For linux users, it depends on the flavor you are running. For Ubuntu and debian fans, a simple apt-get install python does the trick (You have to be connected the internet). For redhat/centos fans - yum does the trick, i.e yum install python. Again you have to be connected to the Internet.

I rather you compile from source, so download tarball from python website and compile it yourself.

For MAC users, please refer to [url]http://homepages.cwi.nl/~jack/macpython/index.html[/url] for your download and install.

Now, we have have python downloaded and installed, what next? Test to see if python is working. How do you do that. For all ya unix/linux/mac users, fire up your shell/terminal and type python, hit enter. If python is installed correctly, you will enter the python interactive shell. The same works on windows, load your command prompt and type python and press enter; it should load the Python interactive shell.

Now we have python and it's interactive shell working. Oya - clap for yourself  wink.

I hear you asking, so how do I write a python program - don't worry my dear friend because python programs are just bunch of text files saved with a .py extension. You can use your favorite text editor to write your python program but I recommend notepad++ (http://notepad-plus.sourceforge.net) for windows, textmate for MAC (http://macromates.com) or textwrangler (http://www.barebones.com/products/textwrangler/). For linux/unix, there is plain old emacs (http://www.gnu.org/software/emacs/).

So let us write our very first python program. We all know the Hello World program you see in most programming books right? Well, let's do something different. We will code python to ask for your name, your age and who was your childhood super hero. Ready?

Guess what - we can write the entire program using just 7 lines of code. So, fire-up your text editor and type in the following and save it as program1.py. Create a folder/directory anywhere on your computer and name it codes, save program1.py in it.

# A Simple program to demonstrate how easy it is to use python
# Alex Dehaini - 10/10/2008

# Get name from user
name = raw_input("What is your name: "wink #Line 1

# Get user age
age = raw_input("How old are you: "wink #Line 2

# Ask the user for their favorite childhood super hero
superhero = raw_input("\nWho is your favorite childhood super hero: "wink #Line 3

# Print output to the users screen

print "Hi, " + name  #Line 4
print "You are", age  #Line 5
print "Your childhood hero", superhero, "is very very strong"  #Line 6

raw_input("\n\nPress enter to exit "wink  #Line 7


I added several comments and lines but the actual program is just 7 line.


HOW TO RUN THE PROGRAM

Use your command prompt or terminal  - go into your codes folder and type program1.py and hit enter. Enter your name, age and your favorite super hero and watch python answer you.

Don't worry if you don't understand the program for now, I will explain in subsequent post. However, the program is self-explanatory. See if you can make sense out of it.

Enjoy!
ProgrammingRe: Python Programming by alexis(m): 10:01am On Oct 09, 2008
Anyone has any public work in python, scripts and program they can share. Or lets' code short and simple snippets in python, what say you guys?
ProgrammingRe: Python Programming by alexis(m): 9:51am On Oct 09, 2008
Python - I finally fell truly in love when I met you in 2006, where have you been? If only my instructor introduced me to you earlier instead of those ugly girls called QBasic, Fotran, Pascal. C looked kind of pretty, she was always smiling. Java was a strict babe with a label "You must do it my way". But then you came along and swept me off my feet.

Python is a powerful yet easy to use programming language developed by Guido van Rossum, first released over a decade ago in 1991. With Python, you can quickly write a small project. But Python also scales up nicely and can be used for mission-critical, commercial applications.

Python doesn't offer revolutionary new features. Rather, it combines many of the best design principles and ideas from many different programming languages. It's simple and powerful. More than any other language, it gets out of the way so that you can think about the problem, not the language. Programming in Python just feels right.

So, what's the big deal about python as compared to other languages.

1. Python is freaking easy to use - The major goal of any programming language is to bridge the gap between the programmer's brain and the computer. Most of the popular languages you've probably heard of, like C, C++, C#, and Java, are considered high-level languages, which means that they're closer to human language than machine language. And they are. But Python, with its clear and simple rules, is even closer to English than any of these. Creating Python programming is so straightforward that it's been called "programming at the speed of thought."

Python's ease of use translates into productivity for professional programmers. Python programs are shorter and take less time to create than programs in many other popular languages. In fact, Python programs are typically 3 to 5 times shorter than equivalent Java programs, and often 5 to 10 times shorter than equivalent C++ programs. There's even some evidence to suggest that a single Python programmer can finish in two months what takes two C++ programmers more than a year to complete.


2. Python is POWERFUL - Python is powerful enough to attract hundreds of thousands of programmers from around the world as well as companies such as Google, Hewlett-Packard, IBM, Industrial Light + Magic, Microsoft, NASA, Red Hat, Verizon, Xerox, and Yahoo!. Python is also used as a tool by professional game programmers. Activision, Electronic Arts, and Infogrames all publish games that incorporate Python.


3. Python Is Object-Oriented - OOP is basically a shift in the way programmers think about solving problems with computers. It embodies an intuitive way of representing information and actions in a program. It's not the only way to write programs, but for most large projects, it's the way to go.

Languages like C#, Java, and Python are all object-oriented. But Python does them one better. In C# and Java, OOP is not optional. This makes short programs unnecessarily complex, and it requires a bunch of explanation before a new programmer can do anything significant. Python takes a different approach. In Python, using OOP techniques is optional. You have all of OOP's power at your disposal, but you can use it when you need it. Got a short program that doesn't really require OOP? No problem. Got a large project with a team of programmers that demands OOP? That'll work too. Python gives you power and flexibility.


4. Python Is a "Glue" Language - Python can be integrated with other languages such as C, C++, and Java. This means that a programmer can take advantage of work already done in another language while using Python. It also means that he or she can leverage the strengths of other languages, such as the extra speed that C or C++ can offer, while still enjoying the ease of development that's a hallmark of Python programming. Python can call native codes in other languages and receive output back, gosh - it's sweet.


5. Python Runs Everywhere - SO, your Computer instructor told you only java is platform independent eh?, well, he lied!, grin. Python runs on everything from a Palm to a Cray. And if you don't happen to have a supercomputer in the den, you can still run Python on Windows, DOS, Macintosh®, or Linux machines. And that's just the top of the list. Python can run on practically every operating system in existence.

Python programs are platform independent, which means that regardless of the operating system you use to create your program, it'll run on any other computer with Python. So if you write a game on your PC, you can e-mail a copy to your friend who runs Linux or to your aunt who has a Mac, and the program will work (as long as your friend and Aunt have Python on their computers).


6. Python Has a Strong Community - You will be amazed at the number of people and companies that use python i.e. google, yahoo and even plain old microsh$t.


7. Python Is Free and Open Source - Python is free. You can install it on your computer and never pay a penny. But Python's license lets you do much more than that. You can copy or modify Python. You can even resell Python if you want (but don't quit your day job just yet). Embracing open-source ideals like this is part of what makes Python so popular and successful.


Let me not take up a lot of space in one post. Python is unique!.
ProgrammingRe: Greatest Programming Books (Must Have!) by alexis(m): 9:22am On Sep 29, 2008
How do we get some of these books?
ProgrammingRe: Linux Application And Security by alexis(m): 7:47pm On Sep 16, 2008
check the linux/unix section at http://knowfree.net
Dating And Meet-up ZoneRe: What Is So Fascinating About Facebook? by alexis(m): 5:38pm On Sep 11, 2008
All my friends are hardcore java programmers, facebook is one of the biggest social networking apps built in php - my favorite language of course.
ProgrammingRe: Which Web Framework Do You Use? by alexis(op): 1:17pm On Aug 03, 2008
Heard zend is good, haven't tried it yet. Is joomla a framework, always thot of it as a CMS. Have you ever used wesitebaker? that's a super CMS.
ProgrammingRe: Which Web Framework Do You Use? by alexis(op): 11:23pm On Jul 30, 2008
Zend is good, never tried it yet, loving cakephp and every part of it. Let me kow how it goes.
ProgrammingWhich Web Framework Do You Use? by alexis(op): 1:34pm On Jul 29, 2008
Hi guys,

I am certain a couple of us make use of the numerous web frameworks in various languages out there, please list the web framework you use and why you like it. It can be in any language. Also include the link to the web framework

I use

cakephp = www.cakephp.org. Cake makes building web apps a breeze, it follows the MVC paradigm so that you can structure and scale your app. It uses no complex XML config files to edit, cake directory structure is simple, you put cake in your webroot and you are rocking, it uses both php4 and php5, No Configuration - Set-up the database and let the magic begin, OO - Whether you are a seasoned object-oriented programmer or a beginner, you'll feel comfortable.

I use a two other frameworks but I will list them later.
ProgrammingRe: Java Rocks: Java Rules by alexis(m): 12:24pm On Jul 29, 2008
did u see that jruby performs better than ruby? i wonder if its because of the J in it?
Ruby is single-threaded, java is multi-threaded hence it makes sense to compile ruby code to java class files. That is the primary reason guys use jruby. The ease and development speed of the ruby language combined with the scalability and robustness of the JVM.
ProgrammingRe: What Programming Language Did You Learn First? by alexis(m): 12:14pm On Jul 29, 2008
c
ProgrammingRe: Defend Your Programming Language by alexis(m): 12:00pm On Jul 29, 2008
As programmers, I think you should know a bit about everything.

Personally, I love python; it's a sweet language, straightforward, you can produce with it is one of the best when prototyping.
I have also tried erlang mainly because of concurrent programming, it looks good.
For me, I look at java as a platform than a programming language - there are new languages that rides on top of the JVM, these languages allows you to express yourself in ways java will not i.e. scala.
I still fancy my C and plain old PHP, I love you guys
Then there is ruby

These are just my views anyways but go to russia and ask some coder there and he will tell you that "assembly language is the best", lol.
ComputersRe: How Do I Password My System To Request For A Password To Boot/@ Boot Time. by alexis(m): 5:08pm On Jul 21, 2008
okay, what do you suggest? I don't see why someone will open my laptop and take out my CMOS battery because it is my computer
CareerRe: Salary Of A Programmer Or Database Administrator by alexis(m): 5:04pm On Jul 21, 2008
Depends on your client ell and your skill level if you were a consultant. As a employee, it still depends on your skill level and what you are actually working on. I think anything from $700 for an entry level position should be alright. A technical Architect can command more than $5,000 or more a month.
ProgrammingRe: How Long Did It Take U'all To Learn Programming? 10 Years? by alexis(m): 1:22pm On Jul 21, 2008
10 years to learn a language, gezzzzz, now that is too much. Writing 100 lines a code as a beginner for the next 90 days can make you get you up to speed even if you are writing HTML. Read wide, explore, research, specialize and most of all, GOOGLE IT, google is a freaking CIA tool man.
ProgrammingRe: Rich Internet Applications - What Do They Mean? by alexis(m): 5:27pm On Jul 18, 2008
I think they are trying to create something similar to the JVM. You can write an app and run it as a web app and as a desktop app.
ComputersRe: Software That Can Allow 2 Os'es To Be Used Simulataneously @ The Same Time by alexis(m): 4:37pm On Jul 18, 2008
there is parallels for MAC, hehe grin
ComputersRe: How Do I Password My System To Request For A Password To Boot/@ Boot Time. by alexis(m): 4:13pm On Jul 18, 2008
Set a BIOS password dude
ProgrammingRe: Java & .net Fighters Read This Blogs by alexis(m): 11:25am On Jun 12, 2008
I will not comment about the pros and cons of both languages. I haven't used C# but my girlfriend has and she makes a lot of noise about it.

I want us to start looking away from what this language can do and what it can't do debate. I want us to look at the new possibilities that both languages offer us.

The JVM is going to be around for a long long time, amazing languages are been created that runs on the JVM. These languages offer features, strengths and flexibility that both Java or C# don't offer us. Look at

www.scala-lang.org - Scala, a new functional and OOP language
http://clojure.sourceforge.net/ - You will love this if you use LISP

Personally, I am a python and C guy but like javarules said "What does it matter?", at the end of the day, the client want a working software.
ProgrammingRe: C++ Compiler, Anybody, Plz Help Me by alexis(m): 12:31pm On May 14, 2008
Tech JobsRe: Good Software Programming Books by alexis(m): 5:51pm On Apr 16, 2008
efeboy,

Start with C and move move to other higher level languages like Java or C++. It is your choice though but I will recommend C to start with.

Check out http://knowfree.net for free ebooks on most programming languages

1 2 3 4 5 6 7 8 ... 48 49 50 51 52 53 54 55 56 (of 66 pages)