PDA

View Full Version : learning python?



largo_winch
25-11-2011, 13:08
http://python.org/
http://www.python.org/getit/

Is there any interest for thinbasic user to learn python or using it for thinbasic? I have no experience with that object oriented scripting language, but I am interested in learning python.

new edit: I saw at another board, that syntax of python language is like horrible one, so I don't think it's a good idea for going on with that language here.

bye, largo

matthew
25-11-2011, 19:40
Python can be extremely useful once you've learnt how to use it. :)

About a year ago I made this (http://bmatthew1.blogspot.com/2010/12/pyopengl-py2exe.html) post on my blog where I used Python to create a small OpenGL app.

http://matthew-4gl.wikispaces.com/file/view/thinbasic.python.image.png/279026962/thinbasic.python.image.png

Aurel
25-11-2011, 21:53
I dont like python at all,many resons....ahhhOne of them is that ,that i don't see any good reason why use python over any other good programming language around.Only one case - maybe if you have in plan to be linux user, but just maybe...Another ugly fact is - python users hate BASIC as programming language and think that BASIC is only a toy language.What a lie !One language which i tried few days back is REXX and i can say that this language is very very cool for me.

John Spikowski
26-11-2011, 01:32
Another ugly fact is - python users hate BASIC as programming language and think that BASIC is only a toy language.

I would love to know where you get your demographics and facts from.

Python is a good scripting language with a large following. It's earned it's place on the shelf and is much better than PHP if I had to choose. I'm more than happy with ScriptBasic as my scripting engine so Python, PHP and Perl are just languages I used to run open source applications, (forums, wikis, blogs, ...) not develop in them.

lydia_sp
28-11-2011, 11:54
I only know that python is scripting language (or plugin) for blender 3d or other important 3d animation programs since around two, three years. there might be enough power for this language and it's famous amoung users there I know from other students here at university. but I cannot imagine if there's a big sense to convert (mothy python's) python to thinbasic. I see no big interest here at this forum (my opinion). nice week, regards, -lydia

peter
28-11-2011, 16:26
Hi,

forget Phyton, soon is Christmas and you can get another language instead of Phyton horror.
trust in Santa Claus!

zak
28-11-2011, 18:06
Largo since i know you like Graphics, there is a laguage called processing http://processing.org/ in the description :[[Processing is an open source programming language and environment for people who want to create images, animations, and interactions, Today, there are tens of thousands of students, artists, designers, researchers, and hobbyists who use Processing for learning, prototyping, and production. ]]
who wants to download it download the 85 MB (with java jdk) and not the smaller one (without java), or just click on the "play with examples" online (java run time must be installed)
available for Windows, Linux, MacOsx
there are tons of examples in the package. even the examples from books.
books:
*Learning Processing A Beginner's Guide to Programming Images, Animation, and Interaction
*Aesthetic Computing
*Processing Creative Coding and Computational Art
*Processing A Programming Handbook for Visual Designers and Artists
*Visualizing Data

danbaron
29-11-2011, 07:25
MIT (the Massachusetts Institute of Technology) is probably the number one technological university in the United States.

I think it was in 2009, that it changed from Scheme to Python, for its undergraduate computer science students.

http://cemerick.com/2009/03/24/why-mit-now-uses-python-instead-of-scheme-for-its-undergraduate-cs-program/

Most likely, the change was made because Python is such an inadequate, terrible language, yeah?

That must be why there are so few books about it.

http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Dstripbooks&field-keywords=python+LANGUAGE&x=0&y=0

And numerics? - nothing.

http://www.numpy.scipy.org

http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Dstripbooks&field-keywords=python+numerical&x=0&y=0

Look at its website, no activity!

http://www.python.org/

And, the Windows installer (with just a simple IDE) is just 17 MB, it must only be for baby programmers, right?

Additionally, it has only existed since 1989, how mature/advanced could it be?!

http://en.wikipedia.org/wiki/Python_(programming_language) (http://en.wikipedia.org/wiki/Python_%28programming_language%29)

I wonder why these three companies sell commercial IDEs for Python.

They must be really dumb!!

http://wingware.com/

http://www.jetbrains.com/pycharm/

http://www.activestate.com/komodo-ide

Aurel
29-11-2011, 21:02
forget Phyton, soon is Christmas and you can get another language instead of Phyton horror.
trust in Santa Claus!
Good point Peter..;)

And i agree with Dan to,windows version comes without IDE then 3companies offer comercial IDE
for this freaking open source language.
From my point of view this language is total dissaster and i don't know why some people recomend
this language for beginners,what a ilussion...
Python is pushed on every linux distro around..
maybe because of this Linux still is not very much popular....
as Peter say forget Python...

matthew
29-11-2011, 22:28
@Aurel I think Dan was writing in support of Python. ;)

Anyway Python can be downloaded with an IDE called IDLE (http://en.wikipedia.org/wiki/IDLE_(Python)) & if you want to use a different one for free you could use DrPython (http://sourceforge.net/projects/wxpython).

Watch these (http://showmedo.com/videotutorials/series?name=pythonJensFromKidsSeries) videos showing some children using Python & EasyGUI to see how easy it can be.

Part of the enjoyment I get from programming is using & learning new languages so I don't know where all the criticism for Python is coming from.

John Spikowski
29-11-2011, 22:40
I don't know where all the criticism for Python is coming from.

You would think it was written in Kryptonite.

http://upload.wikimedia.org/wikipedia/en/thumb/d/da/Kryptonite.JPG/250px-Kryptonite.JPG

danbaron
30-11-2011, 07:42
@Aurel I think Dan was writing in support of Python. ;)

Part of the enjoyment I get from programming is using & learning new languages
Me too.

7663
"You can't stop me from using Python, Superman!"

REDEBOLT
01-12-2011, 04:44
Ok Dan,

You forced me to do it again! :diablo:

You've driven me to :drink:


MIT (the Massachusetts Institute of Technology) is probably the number one technological university in the United States.

So I linked to MIT and found SICP (http://mitpress.mit.edu/sicp/):


Wizard Book n. Hal Abelson's, Jerry Sussman's and Julie
Sussman's Structure and Interpretation of Computer Programs (MIT Press,
1984; ISBN 0-262-01077-1), an excellent computer science text used in
introductory courses at MIT. So called because of the wizard on the jacket. One
of the bibles of the LISP/Scheme world. Also, less commonly, known as the Purple
Book.
from The New Hacker's Dictionary, 2nd edition
(MIT Press, 1993)

So I downloaded the video lectures (http://groups.csail.mit.edu/mac/classes/6.001/abelson-sussman-lectures/)and Scheme and DrRacket.

I will be really busy for a while.

:friends:
Bob

John Spikowski
01-12-2011, 08:00
So I downloaded the video lectures (http://groups.csail.mit.edu/mac/classes/6.001/abelson-sussman-lectures/)and Scheme and DrRacket.

I will be really busy for a while.


Those videos were released in 1985. Are you sure the subject matter is still relevant?

danbaron
01-12-2011, 08:21
Hi Bob.

I wouldn't know anything about SICP or the lectures, if not for jack (Johan).

I think the lectures were made in 1986, for a group of employees from Hewlett Packard.

I don't think I can say enough good things about Racket, DrRacket (the IDE), or the help system in DrRacket.

You can learn Racket just from the help system.

And in DrRacket, it is really really nice to be able to make a function/program at the top of the page, and immediately test it at the bottom.

Here is an example.

From inside DrRacket, copy the code shown below, into the top half of the page (the editor).

From the "File" menu, choose, "Save Definitions".

You can save it as, "factorial.rkt".

From the "Racket" menu, choose, "Run".

Go to the bottom half of the page to the prompt (">") in the REPL (read-eval-print loop).

Type what is shown at each prompt below, and press "Enter", and you should get the same output (except for the time).

If you want to start the REPL over again, just go back to the "Racket" menu, and choose "Run" again.

(While you're editing code, you can make it look nice any time you want, by going to the "Racket" menu, and choosing, "Reindent All".)

Dan


; code ----------------------------------------------------------------------------------------------------------------------------------------

#lang racket

(define value 0)

; Here's a comment.

(define (num-digits n)
(add1 (order-of-magnitude n)))

(define (time-function f n)
(let ((t1 (current-milliseconds)))
(set! value (f n))
(let ((t2 (current-milliseconds)))
(let ((tt (/ (- t2 t1) 1000.0)))
tt))))

(define (fact n)
(define prod 1)
(define (loop m)
(cond
((> m n) prod)
(else
(set! prod (* prod m))
(loop (+ m 1)))))
(loop 1))

(define (num-right-end-zeroes n)
(define sum 0)
(define (loop m)
(cond
((= (remainder m 10) 0)
(set! sum (add1 sum))
(loop (/ m 10)))
(else
sum)))
(loop n))

; REPL interactions ---------------------------------------------------------------------------------------------------------------------------

Welcome to DrRacket, version 5.1 [3m].
Language: racket.
> (time-function fact 1000)
0.005
> value
40238726007709377354370243392300398571937486421071463254379991042993851239862902059204420848696940480047998861019719605863166687299480855890132382966994459099742450408707375991882
36277271887325197795059509952761208749754624970436014182780946464962910563938874378864873371191810458257836478499770124766328898359557354325131853239584630755574091142624174743493
47553428646576611667797396668820291207379143853719588249808126867838374559731746136085379534524221586593201928090878297308431392844403281231558611036976801357304216168747609675871
34831202547858932076716913244842623613141250878020800026168315102734182797770478463586817016436502415369139828126481021309276124489635992870511496497541990934222156683257208082133
31861168115536158365469840467089756029009505376164758477284218896796462449451607653534081989013854424879849599533191017233555566021394503997362807501378376153071277619268490343526
25200015888535147331611702103968175921510907788019393178114194545257223865541461062892187960223838971476088506276862967146674697562911234082439208160153780889893964518263243671616
76217916890977991190375403127462228998800519544441428201218736174599264295658174662830295557029902432415318161721046583203678690611726015878352075151628422554026517048330422614397
42869330616908979684825901254583271682264580665267699586526822728070757813918581788896522081643483448259932660433676601769996128318607883861502794659551311565520360939881806121385
58600301435694527224206344631797460594682573103790084024432438465657245014402821885252470935190620929023136493273497565513958720559654228749774011413346962715422845862377387538230
48386568897646192738381490014076731044664025989949022222176590433990188601856652648506179970235619389701786004081188972991831102117122984590164192106888438712185564612496079872290
85192968193723886426148396573822911231250241866493531439701374285319266498753372189406942814341185201580141233448280150513996942901534830776445690990731524332782882698646027898643
21139083506217095002597389863554277196742822248757586765752344220207573630569498825087968928162753848863396909959826280956121450994871701244516461260379029309120889086942028510640
18215439945715680594187274899809425474217358240106367740459574178516082923013535808184009699637252423056085590370062427124341690900415369010593398383577793941097002775347200000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000
> (num-digits value)
2568
> (num-right-end-zeroes value)
249
>

REDEBOLT
01-12-2011, 08:40
Those videos were released in 1985. Are you sure the subject matter is still relevant?

I figured I had to start somewhere to learn the basic concepts.
I learned calculus some fifty years ago, and it is still relevant,
even though much has been added since then.

REDEBOLT
01-12-2011, 09:07
Hi Dan

Thanks for the example.

Here are my results:

Language: racket; memory limit: 128 MB.
> (time-function fact 1000)
0
> (time-function fact 10000)
0.733
> (time-function fact 100000)
87.828
> (num-digits value)
456574
> (num-right-end-zeroes value)
24999
>

largo_winch
01-12-2011, 10:01
hello!

1) simple python example I've explored:


import math, random (für Standardbibliothek)

import math
print math.sin(math.pi)

from math import *
print sin(pi)

>>> pi = 1234
>>> pi
1234
>>> from math import *
>>> pi
3.1415926535897931

from math import sin as hallo, pi as welt
print hallo(welt)



2) python + GUI:

# File: hello1.py

from Tkinter import *

root = Tk()

w = Label(root, text="Hello, world!")
w.pack()

root.mainloop()

# File: hello2.py

from Tkinter import *

class App:

def __init__(self, master):

frame = Frame(master)
frame.pack()

self.button = Button(frame, text="QUIT", fg="red", command=frame.quit)
self.button.pack(side=LEFT)

self.hi_there = Button(frame, text="Hello", command=self.say_hi)
self.hi_there.pack(side=LEFT)

def say_hi(self):
print "hi there, everyone!"

root = Tk()

app = App(root)

root.mainloop()

after having found some example at websites related to python topics for me python isn't any more complicated to understand. you can for example load (import) modules like thinbasic. one side remember me to java, other side to basic language (imho), but I have had some problems to install python issue for windows here. I will check what's going on.

thanks for interesting feedback. one favour, please stay at topic, if that's possible ;) bye, largo

John Spikowski
04-12-2011, 03:52
one favour, please stay at topic, if that's possible

OT is a major portion of the content posted here. Once in awhile we get lucky and Eros, Petr or Mike chimes in and we find out something about thinBasic.

danbaron
04-12-2011, 06:43
Those videos were released in 1985. Are you sure the subject matter is still relevant?

OT is a major portion of the content posted here. Once in awhile we get lucky and Eros, Petr or Mike chimes in and we find out something about thinBasic.

:offtopic:

The title of this thread is, "learning python?".

----------------------------------------------------------------------

Implicit variable typing, variable assignment, variable incrementation, and printing the value of a variable to a console window, in Python 3:


# code --------------------------------------------------------------

sum=0
sum+=1
print(sum)

# output ------------------------------------------------------------

1

John Spikowski
04-12-2011, 23:32
Allow me to move this forward a bit and show an experimental IUP binding for Python that AIR is working on. (stay tuned for an official announcement)



#!/usr/bin/env python

from iup import *
from dictclient import *

selected_server = ''

about_msg="""This is a Demo
of the IUP GUI Binding
for Python"""

def btnAbout_Clicked(sender):
IupMessage("ABOUT",about_msg)
return IUP_DEFAULT

def btnExit_Clicked(sender):
return IUP_CLOSE

def btnClear_Clicked(sender):
IupSetAttribute(serverList,"1",None)
IupSetAttribute(text,"VALUE",None)
IupSetAttribute(entry,"VALUE",None)
return IUP_DEFAULT

def btnFetch_Clicked(sender):
try:
s = Connection(selected_server)
dbs = s.getdbdescs()
for db in dbs:
IupSetAttribute(serverList, "APPENDITEM", db + " \t\t\t" + dbs[db])
except socket.error:
IupMessage("Connection Error","Unable to Connect")

return IUP_DEFAULT

def btnSearch_Clicked(sender):
result = ''
search_word = str(IupGetAttribute(entry,"VALUE"))
chkAll_State = str(IupGetAttribute(chkAll,"VALUE"))


if search_word:
s = Connection(selected_server)
if chkAll_State == "ON":
retval = s.match('*',"word",search_word)
else:
pass

for item in retval:
result += item.getdefstr()

IupSetAttribute(text,"VALUE",result)

else:
IupMessage("Missing Search Term", "No Search Term Specified")

return IUP_DEFAULT

def serverCombo_Selection(sender, text, item, state):
global selected_server
if state:
selected_server = str(text)
return IUP_DEFAULT


# Initialize IUP
IupOpen(None, None)

# CREATE FORM OBJECTS
btnFetch = IupSetAttributes(IupButton('Fetch', None),'SIZE=50x')
serverCombo = IupSetAttributes(IupList(None),'DROPDOWN=YES, SIZE=120x, EXPAND=HORIZONTAL, VALUE=1')
btnAbout = IupSetAttributes(IupButton('About',None),'SIZE=50x')
btnClear = IupSetAttributes(IupButton('Clear',None),'SIZE=50x')
btnExit = IupSetAttributes(IupButton('Exit',None),'SIZE=50x')
entry = IupSetAttributes(IupText(None),'EXPAND=HORIZONTAL')
btnSearch = IupSetAttributes(IupButton('Search',None), 'SIZE=50x')
chkAll = IupSetAttributes(IupToggle('ALL',None), 'SIZE=20x14, VALUE=ON')
chkUTF = IupSetAttributes(IupToggle('UTF',None), 'SIZE=20x14')
serverList = IupSetAttributes(IupList(None),'EXPAND=YES, VISIBLELINES=1')
text = IupSetAttributes(IupText(None),'MULTILINE=YES, EXPAND=YES, READONLY=YES')
# END FORM OBJECTS

# CREATE CONTAINER OBJECTS
topbox = IupHbox(IupSetAttributes(IupFrame(IupHbox(serverCombo, btnFetch, None)),'TITLE=Servers, EXPAND=YES'),
IupSetAttributes(IupFrame(IupSetAttributes(IupHbox(btnAbout,btnClear,btnExit,None),'GAP=5')), 'TITLE=Controls'),
None)

dictFrame = IupSetAttributes(IupFrame(serverList),'TITLE=Dictionaries')
transFrame = IupSetAttributes(IupFrame(text),'TITLE=Translation')
bottomBox = IupSetAttributes(IupHbox(entry,btnSearch,chkAll,None),'GAP=10x10')
# END CONTAINER OBJECTS

# CREATE CALLBACK REFERENCES
FetchFunc = Icallback(btnFetch_Clicked)
ComboFunc = LIST_CB(serverCombo_Selection)
ClearFunc = Icallback(btnClear_Clicked)
ExitFunc = Icallback(btnExit_Clicked)
SearchFunc = Icallback(btnSearch_Clicked)
AboutFunc = Icallback(btnAbout_Clicked)
# END CALLBACK REFERENCES

# CONNECT CALLBACKS
IupSetCallback(btnExit,"ACTION",ExitFunc)
IupSetCallback(btnFetch, "ACTION", FetchFunc)
IupSetCallback(serverCombo,"ACTION", ComboFunc)
IupSetCallback(btnClear,"ACTION", ClearFunc)
IupSetCallback(btnSearch,"ACTION",SearchFunc)
IupSetCallback(btnAbout,"ACTION",AboutFunc)
# END CONNECT CALLBACKS


# CREATE MAIN WINDOW
win = IupSetAttributes(IupDialog(IupSetAttributes(IupVbox(topbox,dictFrame,transFrame,bottomBox,None),'MARGIN=10x10')),
'TITLE=Thesaurus, SIZE=420x300')
IupShow(win)

# POPULATE COMBOBOX
for server in ('www.dict.org','dict1.us.dict.org','all.dict.org'):
IupSetAttribute(serverCombo,'APPENDITEM',server)

# RUN MAIN LOOP
IupMainLoop()

# SHUTDOWN IUP
IupClose()


I have also been busy with the ScriptBasic version of the IUP binding. (more ... (http://www.scriptbasic.org/forum/index.php/topic,237.0.html))

John Spikowski
06-12-2011, 00:05
Does thinBasic have an extension module for GUI based scripts? Would using something like IUP improve on that module?

thinBasic UI module (http://www.thinbasic.com/public/products/thinBasic/help/html/ui.htm)

I guess IUP isn't something thinBasic users would get excited about. :rolleyes: