News:

CAN'T A BROTHER GET A LITTLE PEACE?

Main Menu

Python lessons

Started by Triple Zero, January 26, 2012, 09:02:04 PM

Previous topic - Next topic

Triple Zero

I believe there's several people on PD learning python (Faust, BDS), apparently Google's tutorials are pretty good:

http://blog.hartleybrody.com/2012/01/google-python/
http://sumukh.me/GFM5+ (PDF that's linked on the blog, in case it's down)

Oh and since I know quite a bit about the subject, if you got any questions, post and I'll try to answer them here.
Ex-Soviet Bloc Sexual Attack Swede of Tomorrow™
e-prime disclaimer: let it seem fairly unclear I understand the apparent subjectivity of the above statements. maybe.

INFORMATION SO POWERFUL, YOU ACTUALLY NEED LESS.

minuspace

Thank you for that.  Actually quickest link to execution ever, quite rewarding.  BASIC was hard by comparison.  A friend of mine was talking about "completion" w.r.t. some language/code - is that anything worth trying?

Triple Zero

Not sure what you mean by "completion"? You mean that, when in the editor, writing your code, it'll automatically complete/predict often-used words for you?

Then yes, that's definitely worth getting. Another great thing to have is "syntax highlighting", which gives different colours to different things in your code, variables, keywords, strings, numbers, etc.

If you're on Windows, PyScripter is by far your best option for a code editor. An advanced one like this is actually not just called editor, but IDE (Integrated Development Environment). Apart from syntax highlighting (which is pretty standard in about any editor with more features than Notepad), it can do code-completion, it'll even give you a pop-up drop-down menu with the methods and properties of an object as soon as you press the '.', and when you call a function or method it'll show a tooltip with the parameters when you type the opening '(' so you can easily know what parameters to pass. It also has a built-in interactive Python interpreter that sort of runs together with your code, as well as a shortcut key to paste+execute currently selected block of code in that interpreter, and it has a debugging environment in which you can set breakpoints or manually advance step-by-step through your code running and in the meanwhile you can change stuff via the interpreter or inspect variables and such via another window. And IMO the bestest thing is, if you hold Ctrl (or maybe it was Shift) every variable, class or identifier becomes a hyperlink when you mouse over it and you can click and it'll jump straight to where it's defined in the source code, even in another tab or automatically opening the file if it's not open yet, and it even works with (non-binary) external python modules/libraries such as Django, in which sense it's sometimes more useful to check the source code and function definitions of what you're calling than figuring it out from the module's documentation.

Other more general purpose code-editors are PSPad (windows only) and jEdit (Java-based, cross-platform). They do syntax highlighting for a great many types of files (HTML, XML, Java, C, Python, PHP, you name it. Both have about 100 syntaxes built-in). They can both do code-completion, though it requires a bit fiddling to get it working, plus since they're not Python-specific, they're not as advanced as PyScripter. Be sure to also check jEdit's many plugins (you can just select and install them from the menu).

And even if you're already decided on PyScripter it's still good to have one of these general-purpose editors around, since they're just really powerful for a lot of heavy-duty text-editing needs.

If you're on Linux, I personally like to use gEdit, since it's really lightweight, but can be made to do all sorts of amazing things if you install the right plugins. Hard-core Linux coders seem to generally prefer Vim or Emacs, though. Vim's got a very steep learning curve because it operates rather differently than any text-editor you're probably used to, but there's a load of tutorials out there, especially since for some reason last year it got a surge in popularity. Emacs is easier to use right away, but it's huuuuuuuuge. Both Emacs and Vim can literally do anything.

Also for Linux, I can really recommend IPython. That's a python application designed to replace the default interactive Python interpreter, and it can do all sorts of amazing things. Especially great if you use it with PyLab/Matplotlib for doing calculations and plotting graphs and such--those things combined basically provide you with a free, open source version of MATLAB, except you're coding in Python, not MATLAB scripts, which is nice.

You can probably also get IPython to run on Windows, but I doubt you'd be using it much when you also got PyScripter ... Not running Windows myself, PyScripter, Ableton Live and uTorrent are probably the only three programs I regret not having access to on Linux (there's good torrent clients for Linux of course, but uTorrent is just really good and lightweight) (also yes I know I can use Wine).
Ex-Soviet Bloc Sexual Attack Swede of Tomorrow™
e-prime disclaimer: let it seem fairly unclear I understand the apparent subjectivity of the above statements. maybe.

INFORMATION SO POWERFUL, YOU ACTUALLY NEED LESS.

Bruno

I learned a little Python a couple of years ago, and then got distracted by other things. I'd like to get back into it, but I've still got these other things that I want to do more.

Some day 03.

Some day.
Formerly something else...

minuspace

Yea, I,m not sure what it (completion) means.  Along similar lines to auto-complete, I think he was mentioning that the code was generative to the extent of writing itself on a higher level of complexity than just auto-complete.  Again, something that sounds unreasonable, but maybe it was worth a shot...  Meanwhile, python is super cool, the interactive interpreter mode is awesome, really decisive design feature:  the idea of interacting-processing should be built right into the ground  :fnord:

Yea, I like e-macs but the interface is a little culty, that and once I got stuck in those buffers and was traumatized.  So now I use nano - but I like the idea of hyperlinking variables...  I used to use Borlands compiler in Dos, and color coding the functions made the experience more friendly, maybe I'll get one - for now I'm just grooving on not needing one!

For related audio visual applications I was thinking of using it to code things in "processing" and "node box" down the line.

As for how you can live without ableton.... :eek:

Triple Zero

Quote from: LuciferX on January 28, 2012, 12:31:26 AM
Yea, I,m not sure what it (completion) means.  Along similar lines to auto-complete, I think he was mentioning that the code was generative to the extent of writing itself on a higher level of complexity than just auto-complete.  Again, something that sounds unreasonable, but maybe it was worth a shot...

Are you into generative art, by any chance?

QuoteMeanwhile, python is super cool, the interactive interpreter mode is awesome, really decisive design feature:  the idea of interacting-processing should be built right into the ground  :fnord:

In that case, get IPython right now! It's a replacement for the interactive interpreter and it's simply just better. Better keyboard editing, it remembers all your commands, got colours, it even remembers the *results* of all your commands in a global array of objects.

Additionally the latest IPython has a "QT Console" which is the interactive interpreter in its own GUI window. It's still a command line, just like a terminal, but it can do extra amazing shit. For example with Pylab/Matplotlib it can display your plots inline as graphics. You can of course also define your own objects to have a graphical representation. It's similar to how all Python objects have a __str__ and a __repr__ method for string representation.

QuoteYea, I like e-macs but the interface is a little culty, that and once I got stuck in those buffers and was traumatized.  So now I use nano - but I like the idea of hyperlinking variables...  I used to use Borlands compiler in Dos, and color coding the functions made the experience more friendly, maybe I'll get one - for now I'm just grooving on not needing one!

Hm, my version of Nano also does syntax highlighting btw. You might want to look into that.

Still, if you're on Linux, better to use GEdit (if on Gnome) or Kate (if on KDE*). Unless for some reason you're restricted to a text mode interface? Because in that case, if I had to do that a lot, I'd get real proficient in Vim, real fast. I'm pretty good at it already, but not enough to use it instead of a regular editor.

(*hadn't mentioned Kate yet because I haven't used it in a while, but 5 years back it was really awesome, and as open source goes, it probably only got better)

QuoteFor related audio visual applications I was thinking of using it to code things in "processing" and "node box" down the line.

Processing is cool (it's a framework/language for algorithmic art--for those reading along). Haven't heard of node box.

QuoteAs for how you can live without ableton.... :eek:

I KNOW, RIGHT>?!!

srsly if you know any decent open source linux audio editor that can zoom and pan like Ableton, cut-n-paste clips like Ableton, design effect envelopes like Ableton, and stretch/straighten tempo in tracks like Ableton ... ID BE REALLY REALLY HAPPY
Ex-Soviet Bloc Sexual Attack Swede of Tomorrow™
e-prime disclaimer: let it seem fairly unclear I understand the apparent subjectivity of the above statements. maybe.

INFORMATION SO POWERFUL, YOU ACTUALLY NEED LESS.

minuspace

Quote from: Triple Zero on January 28, 2012, 12:53:10 AM

srsly if you know any decent open source linux audio editor that can zoom and pan like Ableton, cut-n-paste clips like Ableton, design effect envelopes like Ableton, and stretch/straighten tempo in tracks like Ableton ...

Open source....  Grrr......  At a loss...  In a pinch, beta test the linux version of bitwig studio for Linux immediately before it releases in march - bigwig dot com peeps defected from ableton and maybe we can convince them the only morally correct thing to do is release the stolen code as open source (just more subtle) oh and it runs 64 bit, whatever that matters - hope that works at least as a palliative....

minuspace


Bu🤠ns

Posting in the thread for updates.

Trip I'm still working through the Google classes and combine it with a book on python 3.0 (i figure why not mix versions?).

The other night in #discord, ZGT informed me that MIT also offers python classes which can be found here ( i  think this is the link anyway):
http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-189-a-gentle-introduction-to-programming-using-python-january-iap-2011/

Bu🤠ns

also, just checked out the 'regular expressions' google lesson incorporating the 're' module along with re.search() and re.findall()....

OMFG...what i could DO with this...

PeregrineBF

Quote from: Bu☆ns on January 28, 2012, 05:57:13 AM
also, just checked out the 'regular expressions' google lesson incorporating the 're' module along with re.search() and re.findall()....

OMFG...what i could DO with this...

Some people, upon being confronted with a problem, think "I'll use regular expressions!" Now they have two problems.

Triple Zero

Quote from: Bu☆ns on January 28, 2012, 05:57:13 AM
also, just checked out the 'regular expressions' google lesson incorporating the 're' module along with re.search() and re.findall()....

OMFG...what i could DO with this...

don't forget re.sub

and YES, regexes are the fucking tits.
Ex-Soviet Bloc Sexual Attack Swede of Tomorrow™
e-prime disclaimer: let it seem fairly unclear I understand the apparent subjectivity of the above statements. maybe.

INFORMATION SO POWERFUL, YOU ACTUALLY NEED LESS.

Bu🤠ns

Alright so my main issue here is that I need to be able to create a standalone .exe file for my peers when I finally do  create something worthwhile.  I've installed a distutils extension, called py2exe, on all three of my python versions: 2.6, 2.7 and 3.0.

Doesn't work and I'm not exactly sure why. 

Do any of you know of an alternative way to be able to call these python scripts on a machine that might not have python installed? 

I have the portable versions of python also, but that really kicks the MB high on what might be a simple script.  At that point I might as well just bust my way through using VBS or Powershell.  If I end up having to use the portable python, how much of it can i strip away to reduce the overall file size? I assume I can remove unused modules...anything else?

Triple Zero

Sorry, no idea about that. I never made stand-alone executables with Python. On Linux it's usually just there, or a package away.

I suggest to keep googling? Did you try searching on StackOverflow.com? They got good explanations of loads of stuff. Or you can post the question yourself.
Ex-Soviet Bloc Sexual Attack Swede of Tomorrow™
e-prime disclaimer: let it seem fairly unclear I understand the apparent subjectivity of the above statements. maybe.

INFORMATION SO POWERFUL, YOU ACTUALLY NEED LESS.

Golden Applesauce

Last time I checked (which was a while ago), py2exe didn't support all of Python.

When you say "it doesn't work" do you mean that you got an .exe that didn't do what the .py did, or that it failed to produce an .exe at all?
If the latter, looking for the error message py2exe gave you on StackOverflow (or just the general internet) is a good place to start.

If you're going with portable python, you can also strip out any .py file that has a corresponding .pyc file.  (I think, haven't tried it personally.  If that doesn't work, you almost certainly do it the other way around and remove the .pyc's.)  You could also consider just installing python on your friends computers; if they're non-technical, they probably already have tons of random software lying around taking up space, and if they are somewhat technical, they need Python.

Another option:
See if your program works with http://www.skulpt.org/ .  If it does, you can just have your friends run python through their web browsers.
Q: How regularly do you hire 8th graders?
A: We have hired a number of FORMER 8th graders.