GLBasic forum

Main forum => Off Topic => Topic started by: Hemlos on 2012-Nov-09

Title: Python 2.7.3 Discussion
Post by: Hemlos on 2012-Nov-09
   :offtopic:

:happy:

I am taking a course at edx.org, the intro to computer science from MIT 6.00x.
This is just a bit of feedback from what ive gotten so far from the first 6 weeks:
Just one word, wow.

Enough ranting, i wanted to get a discussion going here about python and its value especially concerning GLBasic.
The computational power of python is extraordinary, simple yet sophisticated in so many ways.
Its not just OOP style code making me wow, its the way you can manipulate data with such amazing ease and depth.

IDLE is a command interpretter for python. If im not mistaking you can use command line inputs.
The python can manipulate data, and store it in files, or even call commands.
From what i understand there is a c++ api also.

In the next few weeks i will be sharing some bits and pieces of what im working on in class, stuff i write.
I will also be thinking of ways to introduce python into GLBasic...perhaps databases are something useful.

edit:

link to the program, (note mit is teaching python 2.7, which is an option in this download) http://www.enthought.com/products/epd_free.php (http://www.enthought.com/products/epd_free.php)
Title: Re: Python 2.7.3 Discussion
Post by: mentalthink on 2012-Nov-09
Yes I´m interested too, I want learn but the time... always the time... Python I read in some book, for pupils in USA, comment something like "Python it´s the language everyone have to learn"... for me in 3D comes fantastic in 3D industry the common lenguaje for all Suites it´s python, from blender to Lw or Cinema 4d... now sees it´s an Standard...

But anything you want program can do it , for web, 3d, I think Arduino can be programed too...

Good luck whit the course!!!
Title: Re: Python 2.7.3 Discussion
Post by: erico on 2012-Nov-09
I´m really curious about scripting languages, what would be the difference between python and lua?
They both seem to be the standard nowadays, and as mental stated, they are really into many applications.

All this brings me back to Arexx on the amiga... 8)
Title: Re: Python 2.7.3 Discussion
Post by: Hemlos on 2012-Nov-09
the idle runs in a terminal, outright it has no graphics but it can do graphics certainly.
i dont think that is the main reason for using a computational program.

First, python is really really simple in the sense when you read the code, its almost like a spoken language.

Second, and i think more important, is the flexibility it has with variables, functions, classes and inheritance.

Truely an amazing language when it comes to manipulating integers, floats, and string....which can all be contained in different object types and individual elements....lists, tuples, sets, dictionaries, each of these can store each other.

a list, for example, is an array, which can store any data type combinations.
you can apply commands to the list like this:
.append()
.insert()
.pop()
.remove
.count() - counts instances
len(list) returns index count
it can do more operations than listed here, its just a short example.

Some key projects dealing with large amounts of data:
One of my projects was the 'towers' of hanoi' puzzle.
another project was cipher encryption.
and now at week 6 we are doing rss feeds

heres something funny about python: http://xkcd.com/353/
also im adding a link to the program itself in the top messag of this thread.
Title: Re: Python 2.7.3 Discussion
Post by: mentalthink on 2012-Nov-09
Yes how told Erico Lua and Python and I think Ruby in Rails are used very common... I think Python and Lua commes from Ruby?¿...

I take a bit Lua for use the Shiva 3D, in principle it´s a bit confuse... I never programed using Scripting languaje, but after a While it´s very cool, I think it´s something when yo do Types "Clases" in GLbasic...

PS; 1 Question Hemlos, when I touch Python under Eclipse... I don´t see any mode to say a veriable something id it´s float integer or something... I think if you put var_A can be anything in python, this it´s correct?¿...

Title: Re: Python 2.7.3 Discussion
Post by: Hemlos on 2012-Nov-09
Int float strings are declared by thier first input
Then you can"print type(var)" to see the type or value = type(var)
Also Boolean if type(var) == Int, or even type(var) != String || type(var2) == Float .. Which is bool OR
Sorry so sloppy on my ipod
Title: Re: Python 2.7.3 Discussion
Post by: Moebius on 2012-Nov-09
Python is a very powerful language, interesting in that nothing is statically typed.  Scripting support from within GLB would be interesting...
If you're interested in learning it, CS212 on Udacity is a very good course, and it gave me my favourite snippet:
Code (glbasic) Select

def memo(f):
   cache = dict()
   def wrap(*args):
      if args not in cache: cache[args] = f(*args)
      return cache[args]
   return wrap

memo:  A function that takes in a function, and returns a function that has an inbuilt cache that stores the results of previous calls.

so:
Code (glbasic) Select
f = lambda x: x**2
f = memo(f)
# or this achieves the same thing:
@memo
def f(x):
   return x**2
Title: Re: Python 2.7.3 Discussion
Post by: Hemlos on 2012-Nov-09
@ocean: i was looking at the wiki for freecad, it is using python for almost everything apparently.
It depends on the python to do all the graphics numeric representation calculations for 2d and 3d models, the math.
Its interesting because it has a huge python api, which means its very modular and extendable.

@mental:
agreed, everyone should learn python; for its ease of computational power.
i looked into ruby on rails, its more of cloud app design system, and rather redundant imo, but perhaps i havent seen its real value?

@moebius
i like the mit course because they offer a certificate from mit, and they dont just teach python in the course, its more about understanding the fundamentals of computer science.
All thier lectures are on youtube too. Same for berkelys ai and opengl graphics courses.

here is thier silly-bus from cs6.00:


Code (glbasic) Select
Lecture 1 – Introduction:
• What a computer does
• Computational thinking
• Basic machine architecture and programming languages
Lecture 2 – Core elements of programs:
• Kinds of languages
• Objects, expressions, operators
• Abstraction by naming
• Strings
• Scripts
• Straightline programs
• Branching programs
Lecture 3 – Simple algorithms:
• Iteration
• Exhaustive enumeration
• Guess and check
• For and while loops
• Approximate solutions
• Bisection search
• Newton-Raphson
Lecture 4 – Functions:
• Function syntax
• Abstraction by specification
• Functions and scoping
• Specifications
• ModulesLecture 5 – Recursion:
• Recursion
• Inductive reasoning
• Divide and conquer
Lecture 6 – Objects:
• Structure types and mutability
• Tuples
• Lists and mutability
• Functions as objects
• Dictionaries
Lecture 7 – Debugging:
• Testing and debugging
• Black box testing
• Glass box testing
• Integration testing and unit testing
• Debugging approaches
Lecture 8 – Efficiency and orders of growth:
• Complexity
• How to measure complexity
• Asymptotic notation
• Classes of algorithmic complexity
Lecture 9 – Memory and search:
• Memory storage
• Indirection
• Search and sort methods
• Hashing
Lecture 10 – Classes:
• Definition of classes
• Classes versus instances
• Methods
• Bindings of values
• Exceptions
Lecture 11 – Object Oriented Programming:
• Inheritance
• Object oriented programming
• Specifications
• Iterators
• Debugging with classes
Lecture 12 – Plotting:
• Plotting techniques
• Methods for using plotting to understand programs
Lecture 13 – Simulations and random walks:
• Stochastic programs and probability
• Random walks
• Variations on random walks
Lecture 14 – Sampling and Monte Carlo methods:
• Monte Carlo simulations
• Inferential statistics
Lecture 15 – Statistical thinking:
• Statistics
• Histograms
• Statistical measures
Lecture 16 – Using randomness to solve non-random problems:
• Distributions
• Examples of Monte Carlo problems
Lecture 17 – Curve fitting:
• Understanding data
• Data fitting methods
• Coefficient of determination
Lecture 18 – Optimization:
• Optimization problems
• Knapsack problems
• Solution methods for knapsack problems
Lecture 19 – Graphs:
• Graph search
• Breadth first search
• Depth first search
• Shortest path problems
Lecture 20 – Graphs:
• Additional graph problems
• Cliques
• Min-cut methods
Lecture 21 – Dynamic programming:
• Dynamic programming
• Example problems
Lecture 22 – Statistical fallacies:
• Statistical fallacies
• Careful use of statistical methods
Lecture 23 – Simulation example:
• Large scale simulation
Title: Re: Python 2.7.3 Discussion
Post by: 8bitBoss on 2012-Nov-09
I started with Python 2011 and since then wherever I can use Python, I use Python.
It can do number cruching, crawling the web, backend programing (Google App Engine), GUI, etc.

The only real downside is that it's pretty hard to do cross platform games in it that run on Win, Mac, Linux, iOS, Android, etc.
But then again, that's what GLBasic is for ;)
Title: Re: Python 2.7.3 Discussion
Post by: fuzzy70 on 2012-Nov-09
Python is definitely on my todo list as found some good code resources on pygame, also I use Cinema4D which has a python menu but have not found any real docs on how to use it (not tried very hard yet though).

What I need to discover is python versions. For example I have python 2.6 & 2.7 on my machine as some programs required one version & some the other so that confuses me lol (not found anything that requires python 3 yet thank God as that would just confuse me more).

Lee

btw on pygame site a rather nice Perlin island generator http://www.pygame.org/project-Island+Generator-2446-.html (http://www.pygame.org/project-Island+Generator-2446-.html)
Sent from my GT-I5700 using Tapatalk 2
Title: Re: Python 2.7.3 Discussion
Post by: Hemlos on 2012-Nov-10
Yes, the biggest flaw python has, it is not backward compatible.  :x

Im not sure, yet, why it is not cross platform compatible.
I have ripped stuff made for linux fedora, and it worked fine on windows xp.
Im going to make a guess here, some builtin commands are not useable by different platforms.

Title: Re: Python 2.7.3 Discussion
Post by: jestermon on 2012-Nov-10
It's always great to see folks moving to Python. It really is an awesome language with just about anything you need. I've used if for over 15 years, developing from credit card systems for banks, web CRM for network management and tracking to full on multi-user 3D simulations. I have not found anything it cannot do. For 3D - Panda3D, Blender, MakeHuman, and such. for GUI - WxPython... the list goes on and on.

There certainly is a backward compatibility issue with newer versions of Python. 3.+ and 2.+ have a massive incompatibility. But the idea is to move forward and use the latest and greatest when opportunity presents itself. To test cross-platform, it's always better to use the same version for that, and you get about 98% compatibility. Any OS has it's own niggly requirements, and some tweaking to get that 100%. Of course a Python ODBC call won't work on Linux, nor an Informix DB call on Window$.. so a bit of common sense is required.

Python has been around like forever, and is stable and mature. Comparing it to Lua, Ruby and other scripting language is like comparing c++ to Java. It's a matter of personal preference, not functionality, since they all offer more or less the same (well almost).

As far as integrating Python into GLBasic, it's simply a matter of using some INLINE c++, and it becomes seamless.

Here's a simple c example for embedding Python.
Quote#include <Python.h>

int main(int argc, char *argv[])
{
  Py_Initialize();
  PyRun_SimpleString("from time import time,ctime\n"
                     "print 'Today is',ctime(time())\n");
  Py_Finalize();
  return 0;
}
Title: Re: Python 2.7.3 Discussion
Post by: fuzzy70 on 2012-Nov-10
I think I will be learning the 2.x series rather than the 3.x series of python due to none of my apps I use have the 3.x series as a requirement. It would be preferable if I could learn the latest version but like it states on python's own site the 2.x version is what is shipped by default on linux/mac plus like I mentioned my apps like Cinema4D are 2.x based. I don't really want to learn something that would cause me problems if I needed to implement it in my current setup.

Sure once I get familiar & gain more knowledge/experience of 2.x then perhaps I will look into 3.x & what differences exist, just at the present time I think it would just cause confusion for me.

Integrating python into GLBasic I cannot really comment on due to not knowing python & what it can provide to GLBasic, but if it provides useful additions then it can only be good thing.

Lee
Title: Re: Python 2.7.3 Discussion
Post by: Hemlos on 2012-Nov-10
I think pythons advantage is the development sense, making libraries, and testing them immediately, and directly through a command line prompt. By simply loading a script all the functions become interactive at the prompt, you can even write them locally at the prompt.

Ive already converted some algorithms no problem. But tbh i dont know what good using pythons in glbasic would be other than importing huge libraries perhaps.

Title: Re: Python 2.7.3 Discussion
Post by: jestermon on 2012-Nov-10
Implementing Python scripting in GLBasic is a matter of game design, more than anything else. I'd not use it for games that run on tablets or phones - though there are Python versions for most of them.
I would embed Python for allowing users to implement external AI logic to a game, or for complex database driven scenarios, since it is ideal for such things. It would be a bit of an overkill for a small indie game, since external definitions can just as easily be done with a simple text file.
Walk-through 3D simulations, where a client may wish to tweak the environment and game logic, is an ideal scenarion for using Python with GLBasic.
Title: Re: Python 2.7.3 Discussion
Post by: 8bitBoss on 2012-Nov-10
Quote from: Hemlos on 2012-Nov-10
Yes, the biggest flaw python has, it is not backward compatible.  :x

Im not sure, yet, why it is not cross platform compatible.
I have ripped stuff made for linux fedora, and it worked fine on windows xp.
Im going to make a guess here, some builtin commands are not useable by different platforms.
I think every built in command is supported on every platform with a standard Python implementation, including Windows, Linux and OSX.
Title: Re: Python 2.7.3 Discussion
Post by: okee on 2012-Nov-11
The authors of legend of Grimrock had an interesting post about using LUA for their game
http://www.grimrock.net/2012/07/25/making-of-grimrock-rapid-programming/

Can Python be used in the same way ?
Title: Re: Python 2.7.3 Discussion
Post by: Hemlos on 2012-Nov-12
Any language can im sure, its a scripted game if theyre using lua.
Title: Re: Python 2.7.3 Discussion
Post by: jestermon on 2012-Nov-12
The Grimrock post was interesting, but it brings up the age-old argument of compiled versus interpreted.
I agree that interpreters are real RAD, and it has many advantages. For example a Python program takes about 1/20th of the time to write than a c++ program of the same complexity. A Java program takes almost three times as long. I'm talking about a real program - Something with the complexity of a small text editor.
It's really a trade off runtime speed versus runtime flexibility. The interpreted byte code gives the flexibility, the pure binary gives the speed.
Writing and changing programs at runtime is an old thing. It's been done in Disney's Panda3D (Python) for years. No mess, no fuss - Just change the code at runtime, and tweak while you are developing. I guess because the newer WYSISYG game editors like Unity are very popular, because of the quick iteration of interpreted code in the development cycle. (obviously the world builder adds to the gimmick)
Whether it's Lua, Python or Ruby - they are much the same. So there's nothing new here. Just redeployment of old ideas in a newer interpreter.
Title: Re: Python 2.7.3 Discussion
Post by: Hemlos on 2012-Nov-27
Easy as  123, h tee tee pee....7 lines, permanent http server.
I just tried this on the local network...awesome.
Also i punched my firewall, and voila, website on my desktop.
http is one of many supported protocols, it even handles mail i think...theres so much to read.
Heres the libraries listed for the help file:
http://docs.python.org/2/library/index.html

Code (glbasic) Select
#The SimpleHTTPServer module can be used in the following manner in order
#to set up a very basic web server serving files relative to the current directory.

import SimpleHTTPServer
import SocketServer

PORT = 80

Handler = SimpleHTTPServer.SimpleHTTPRequestHandler

httpd = SocketServer.TCPServer(("", PORT), Handler)

print "serving at port", PORT
httpd.serve_forever()
Title: Re: Python 2.7.3 Discussion
Post by: Hemlos on 2012-Nov-27
i was playing with sounds.
this function controls the computer beep speaker and fluxuates very high pitch sounds, my dog hates it.

Code (glbasic) Select

import winsound
#computer beep
# val1 is freq 37-32767, val2 is time in milliseconds
while True:
    for eachsound in range(12000,14000,100):
        winsound.Beep(eachsound, 100)
    for eachsound in range(14000,12000,100):
        winsound.Beep(eachsound, 100)