Page 19 of 43
Re: Programming, computers, etc. [Serious]
Posted: Thu Sep 27, 2012 5:36 pm
by Anonymously Famous
Internally it does it through tuples (a type of list or array), which can be unpacked to several variables.
Here's something I did in the Python interactive interpreter just now:
Code: Select all
>>> def someFunction(parameter):
#Do some stuff
return 1, 2
>>> a, b = someFunction(5)
>>> a
1
>>> b
2
You can use any list-like data structure.
Code: Select all
>>> def someFunction(parameter):
#Do some stuff
return "ab"
>>> a, b = someFunction(None)
>>> a
'a'
>>> b
'b'
There are also iterators, that return a series of items, one at a time:
Code: Select all
>>> def fibonacci(maxNumber):
a = 0
b = 1
if maxNumber > a: yield a
if maxNumber > b: yield b
while b < maxNumber:
a, b = b, a + b
if b < maxNumber: yield b
>>> for i in fibonacci(15):
print i,
0 1 1 2 3 5 8 13
There's a function that allows you to traverse a folder structure that uses an iterator of multiple return values.
Code: Select all
>>> import os
>>> for currentDirectory, directories, files in os.walk("folderPath"):
for fileName in files:
doStuff(os.path.join(currentDirectory, fileName))
Re: Programming, computers, etc. [Serious]
Posted: Thu Sep 27, 2012 6:59 pm
by atomtengeralattjaro
hey that's pretty cool.
This reminds me of Matlab. i have a course where we learn some basic stuff in Matlab.
Re: Programming, computers, etc. [Serious]
Posted: Thu Sep 27, 2012 9:54 pm
by Anonymously Famous
In Python 3, which is the current version (though most people still use Python 2), you can even designate a "throw away" variable, which is a list of the other values that you don't want to keep.
Code: Select all
>>> a,b,*c = 1,2,3,4,5
>>> c
[3, 4, 5]
Re: Programming, computers, etc. [Serious]
Posted: Thu Sep 27, 2012 10:10 pm
by atomtengeralattjaro
huh?
what are a and b in this case? you marked c with a star, that makes it an array so that 1 and 2 will be in a and b, and any subsequent values will be in c? what makes it "throw away" then?
Re: Programming, computers, etc. [Serious]
Posted: Fri Sep 28, 2012 12:26 am
by Anonymously Famous
I guess "throw away" is the wrong term. More like "the rest."
The star signifies that they should all be packed in an array, and you can have the array either at the beginning or the end. The first (or last) values will go into each variable until they run into the one with the star. Then the last (or first) several will be put into that variable as an array.
I called it "throw away" because in some cases you only want the first several, and you don't care what's in the rest. But you can definitely use it, too.
Code: Select all
>>> add = lambda x,y: x+y
>>> function, first, *theRest = add,1,2,3,4,5,6,7,8,9,10
>>> totals = [function(first, y) for y in theRest]
>>> totals
[3, 4, 5, 6, 7, 8, 9, 10, 11]
Re: Programming, computers, etc. [Serious]
Posted: Fri Sep 28, 2012 2:01 pm
by atomtengeralattjaro
a-ha! that's cool. i can't imagine where would I use such a thing, but i see it's not pointless.
Re: Programming, computers, etc. [Serious]
Posted: Sat Sep 29, 2012 2:21 pm
by john123abc201
Does anybody know how to install a cursor pack with an ini file?
Re: Programming, computers, etc. [Serious]
Posted: Sat Sep 29, 2012 2:53 pm
by atomtengeralattjaro
depends on the OS i guess..
i have no idea about cursor packs, but if you happen to have the individual .cur or .ani files for the different cursors, you can change them one by one in control panel/mouse/pointers.
Re: Programming, computers, etc. [Serious]
Posted: Fri Oct 05, 2012 4:43 pm
by atomtengeralattjaro
boo! double poast because i never ever do that. Thus, traditionally, I deserve to die.

Re: Programming, computers, etc. [Serious]
Posted: Fri Oct 05, 2012 6:22 pm
by MTG09
It is relative and on topic. Therefore, any kind of necroposting or double posing is excused.
Re: Programming, computers, etc. [Serious]
Posted: Sat Oct 06, 2012 1:53 pm
by klinscy
Blasphemy?
Re: Programming, computers, etc. [Serious]
Posted: Sat Oct 06, 2012 1:59 pm
by Anonymously Famous
Not any kind, but on-topic kinds are.
The other day I finished a Python script that helps my department do stuff. That's cool and all, but the really cool part is:
I made it bilingual (kind of). It works with both Python 2 and Python 3! That's tricky, given some of the differences in standard module locations and the fact that strings are represented differently.
Re: Programming, computers, etc. [Serious]
Posted: Sat Oct 06, 2012 2:23 pm
by atomtengeralattjaro
why not just make a python2 version and a python3 version?
Re: Programming, computers, etc. [Serious]
Posted: Sun Oct 07, 2012 2:07 pm
by Anonymously Famous
Because I wanted to see if I could make one version that worked on both.
Re: Programming, computers, etc. [Serious]
Posted: Sun Oct 07, 2012 2:15 pm
by atomtengeralattjaro
And you won!
btw,
here is a contest that I'm probably not going to participate in.
Re: Programming, computers, etc. [Serious]
Posted: Sun Oct 07, 2012 6:27 pm
by Anonymously Famous
Probably not.
Re: Programming, computers, etc. [Serious]
Posted: Wed Oct 10, 2012 5:43 pm
by Anonymously Famous
I'm officially registered for
PyCon. This makes me happy.
Re: Programming, computers, etc. [Serious]
Posted: Wed Oct 10, 2012 6:04 pm
by atomtengeralattjaro
have fun gathering.
this looks intriguing.
Re: Programming, computers, etc. [Serious]
Posted: Wed Oct 10, 2012 10:28 pm
by Anonymously Famous
That it does. I'll have to look into it.
Edit: That's it: I'm going to start learning it. I was going to go for a Lisp language for my next endeavor, but Haxe has me intrigued.
Re: Programming, computers, etc. [Serious]
Posted: Thu Oct 11, 2012 10:22 am
by atomtengeralattjaro
i thought you might like it. i don't think i'll start learning anything else until i've finished the university.