Re: [Tutor] Difficulty Understanding Example Code for Blender Script
On Thu, Jul 22, 2010 at 2:47 AM, Marc Tompkins wrote: > On Wed, Jul 21, 2010 at 9:48 PM, Andrew Martin > wrote: >> >> This code was part of a Blender script to build a 3d bar graph, so I don't >> know if understanding Blender is a prereq for understanding this code. The >> function is for the axis labels. >> >> def label(text,position,orientation='z'): >> txt=Text3d.New('label') >> txt.setText(text) >> ob=Scene.GetCurrent().objects.new(txt) >> ob.setLocation(*position) >> if orientation=='x': >> ob.setEuler(-pi/2.0,0,0) >> elif orientation=='z': >> ob.setEuler(0,0,pi/2.0) >> print 'label %s at %s along %s' %(text,position,orientation) >> >> I understand it for the most part except for the orientation part. I >> assume orientation is for the 3d text object, but how is it determined >> whether it is x or z? > > I don't use Blender myself, so this will be a more generic, high-level > answer... >> >> def label(text,position,orientation='z'): > > This definition specifies that label() takes two mandatory parameters - text > and position - and one optional parameter, orientation. What makes > "orientation" optional is the fact that a default value is supplied: > "orientation='z'". In other words, "orientation" is equal to "z" unless you > specify otherwise in your call to label(). Seeing as how blender is 3d graphics, have you tried the 'newbie fidget with it', and typed in w(quaternion),x, or y to see what occurs. Also, have you looked into the hierarchy to see if z, which looks as though it's contained in a string, is an input variable declared elsewhere as an integer, or represents something else in it's usage. Z can mean global, or object orientation in blender from what I see. > > Take a look at this section of the Python docs: > http://docs.python.org/tutorial/controlflow.html#more-on-defining-functions > > Hope that helps... > > > ___ > Tutor maillist - tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] "expected an indented block" (see attached)
Hi all, Attached is a file. When I run the program it is part of, I get an error that says: line 62: IndentationError: expected an indented block. I can see nothing wrong with the indentation, though. This is part of my Battleship game, defining all the different ships and aircraft the user can have, as well as the special weapons methods for each ship. If anyone can spot the problem, it would be great. I know I only indent one space, instead of the normal four, but I use a screen reader and it is a lot easier and faster to do it this way. If a version of Python based on braces instead of indents were released, my world would be so much better! -- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com; http://www.facebook.com/mehgcap craft.py Description: Binary data ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] "expected an indented block" (see attached)
> Attached is a file. When I run the program it is part of, I get an > error that says: > line 62: IndentationError: expected an indented block. This function: def fromString(self, str): #creates a Craft object from the string #end class Craft Is completely empty (the comment lines are discarded). So Python expects any next piece of code to be inside this method (and thus indented). If you want an empty function, use 'pass' instead. (also consider using four spaces for indentation, which I've also found much clearer. Have a read through PEP 8; has a lot of interesting tidbits. And an editor with a good Python mode is very handy, because that would have almost automatically indented the next piece of code, 'class Battleship(Craft)', which would have indicated something went awry before that line). > I can see nothing wrong with the indentation, though. This is part of > my Battleship game, defining all the different ships and aircraft the > user can have, as well as the special weapons methods for each ship. > If anyone can spot the problem, it would be great. I know I only > indent one space, instead of the normal four, but I use a screen > reader and it is a lot easier and faster to do it this way. If a > version of Python based on braces instead of indents were released, my > world would be so much better! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] "expected an indented block" (see attached)
On 7/22/10, Evert Rol wrote: >> Attached is a file. When I run the program it is part of, I get an >> error that says: >> line 62: IndentationError: expected an indented block. > > This function: > > def fromString(self, str): > #creates a Craft object from the string > #end class Craft > > > Is completely empty (the comment lines are discarded). So Python expects any > next piece of code to be inside this method (and thus indented). Oh, I did not realize it threw out comments. That explains it, then! > If you want an empty function, use 'pass' instead. > > (also consider using four spaces for indentation, which I've also found much > clearer. Have a read through PEP 8; has a lot of interesting tidbits. > And an editor with a good Python mode is very handy, because that would have > almost automatically indented the next piece of code, 'class > Battleship(Craft)', which would have indicated something went awry before > that line). The only problem is that I have not found an accessible editor that will do this. > > > >> I can see nothing wrong with the indentation, though. This is part of >> my Battleship game, defining all the different ships and aircraft the >> user can have, as well as the special weapons methods for each ship. >> If anyone can spot the problem, it would be great. I know I only >> indent one space, instead of the normal four, but I use a screen >> reader and it is a lot easier and faster to do it this way. If a >> version of Python based on braces instead of indents were released, my >> world would be so much better! > > -- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com; http://www.facebook.com/mehgcap ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] "expected an indented block" (see attached)
On Thu, Jul 22, 2010 at 3:35 PM, Evert Rol wrote: >> Attached is a file. When I run the program it is part of, I get an >> error that says: >> line 62: IndentationError: expected an indented block. > > This function: > > def fromString(self, str): > #creates a Craft object from the string > #end class Craft > > > Is completely empty (the comment lines are discarded). So Python expects any > next piece of code to be inside this method (and thus indented). > If you want an empty function, use 'pass' instead. > > (also consider using four spaces for indentation, which I've also found much > clearer. Have a read through PEP 8; has a lot of interesting tidbits. Did you read the rest of his post? He's using a screen reader for a reason; he can't *see* the code. visual means of structuring code like whitespace are meaningless to him at best, and annoying at worst. No wonder his code is littered with '#end def' comments. Python's significant indentation is horrible for the blind, at least until we create a more specialized/better screen reader. Alex, Perhaps a better solution is to indent with tabs rather than spaces, though I'm normally opposed to using tabs. Alternatively, run your files through a script that expands every indent space to four spaces before posting here. I've attached a bare-bones script that takes a file and a number as argument, replaces every initial space with that number of spaces, and writes the result to a new file (filename is just the old filename with .new appended). Yes, the script is indented with four spaces, Sorry. I'm sure you could write a script that does the reverse operation so it becomes a little more readable for you. Hugo #! /usr/bin/env python import sys def expand_indent(string, num=4): """replace every initial space in string with num spaces""" if string[0] == ' ': return (' ' * num) + expand_indent(string[1:]) else: return string if __name__ == '__main__': if len(sys.argv) == 3: num = int(sys.argv[2]) else: num = 4 infile = open(sys.argv[1], 'r') outfile = open(sys.argv[1] + '.new', 'w') for line in infile: outfile.write(expand_indent(line, num)) infile.close() outfile.close() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] "expected an indented block" (see attached)
>> (also consider using four spaces for indentation, which I've also found much >> clearer. Have a read through PEP 8; has a lot of interesting tidbits. > > Did you read the rest of his post? He's using a screen reader for a > reason; he can't *see* the code. visual means of structuring code like > whitespace are meaningless to him at best, and annoying at worst. No > wonder his code is littered with '#end def' comments. Python's > significant indentation is horrible for the blind, at least until we > create a more specialized/better screen reader. Sorry, I had obviously missed that. Apologies. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] "expected an indented block" (see attached)
On 7/22/10, Hugo Arts wrote: > On Thu, Jul 22, 2010 at 3:35 PM, Evert Rol wrote: >>> Attached is a file. When I run the program it is part of, I get an >>> error that says: >>> line 62: IndentationError: expected an indented block. >> >> This function: >> >> def fromString(self, str): >> #creates a Craft object from the string >> #end class Craft >> >> >> Is completely empty (the comment lines are discarded). So Python expects >> any next piece of code to be inside this method (and thus indented). >> If you want an empty function, use 'pass' instead. >> >> (also consider using four spaces for indentation, which I've also found >> much clearer. Have a read through PEP 8; has a lot of interesting tidbits. > > Did you read the rest of his post? He's using a screen reader for a > reason; he can't *see* the code. visual means of structuring code like > whitespace are meaningless to him at best, and annoying at worst. No > wonder his code is littered with '#end def' comments. Python's > significant indentation is horrible for the blind, at least until we > create a more specialized/better screen reader. I think a specialized editor is all it would take. Edsharp (http://www.empowermentzone.com/edsetup.exe) has a way of converting braced code into Pythonic indents and colons, but you then have to manage two sets of files, the braced code and the indented code. Perhaps such an editor is a future project for me... > > Alex, Perhaps a better solution is to indent with tabs rather than > spaces, though I'm normally opposed to using tabs. Alternatively, run > your files through a script that expands every indent space to four > spaces before posting here. I've attached a bare-bones script that > takes a file and a number as argument, replaces every initial space > with that number of spaces, and writes the result to a new file > (filename is just the old filename with .new appended). Tabs are worse because, for some very annoying reason, my reader reads both hard returns and tabs as the word "blank". That means that I have no way of knowing when I am reading a tab and when I have gone to a previous line. Spaces are the only viable option. Thanks for the script; if I have to attach code in the future, I will try to remember to run the file(s) through it for easier reading. I can also make your script remove the #end... comments, since I know a lot of people do not like them either. > > Yes, the script is indented with four spaces, Sorry. I'm sure you > could write a script that does the reverse operation so it becomes a > little more readable for you. > > Hugo > -- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com; http://www.facebook.com/mehgcap ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] "x and y" means "if x is false, then x, else y"??
On 07/05/10 22:23, Adam Bark wrote: > > I should add that this is how something like: > > if x != y: > do_something() > > works, if expects a True or False (this isn't always true but works for > comparison operators expressions such as this). > "if" expects an expression that can be converted to True or False by calling its __bool__()/__nonzero__(); in case of missing __bool__/__nonzero__, then the object is considered True. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] "x and y" means "if x is false, then x, else y"??
On 6 July 2010 02:05, Lie Ryan wrote: > On 07/05/10 22:23, Adam Bark wrote: > > > > > I should add that this is how something like: > > > > if x != y: > > do_something() > > > > works, if expects a True or False (this isn't always true but works for > > comparison operators expressions such as this). > > > > "if" expects an expression that can be converted to True or False > by calling its __bool__()/__nonzero__(); in case of missing > __bool__/__nonzero__, then the object is considered True. > > Well put, I couldn't decide how to phrase it without adding confusion but you hit the nail on the head. Cheers, Adam. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] "x and y" means "if x is false, then x, else y"??
Lie Ryan wrote: > On 07/05/10 22:23, Adam Bark wrote: > >> >> I should add that this is how something like: >> >> if x != y: >> do_something() >> >> works, if expects a True or False (this isn't always true but works for >> comparison operators expressions such as this). >> > > "if" expects an expression that can be converted to True or False > by calling its __bool__()/__nonzero__(); in case of missing > __bool__/__nonzero__, then the object is considered True. Don't forget about __len__() >>> class A: ... def __init__(self, n): self.n = n ... def __len__(self): return self.n ... >>> "yes" if A(1) else "no" 'yes' >>> "yes" if A(0) else "no" 'no' Bonus: >>> "yes" if A(-1) else "no" Traceback (most recent call last): File "", line 1, in ValueError: __nonzero__ should return >= 0 Peter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] sound libraries?
Hi all, I am curious. If I wanted a library that would let me play sounds at specific positions in the stereo field, then update that position as the user "moved" so that it would seem to be a fixed reference point, what would I use? For example, say the left/right arrows move you left and right. In the center of your stereo field you hear a sound, say a bell. As you press the arrow keys, the sound moves, or rather, you move but the sound stays the same. Pysonic looks like the perfect answer, but it seems to require python2.3, and I am using 2.6. Are there any other conprehensive sound libraries that would allow for dynamic positioning of sound, doplar effects, volume control, and so on? -- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com; http://www.facebook.com/mehgcap ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] how i can change two lists into one directory
hey i have just started making a app using python and just gt a problem.. i have two list a=["x","z"] b=[1,2] i want to make a directory like this c={"x":1,"z":2} is it possible i mean i tried it using loops and all but i cant append a directory so i m unable to do this... plz tell me if there's any way to get the directory like this Thanks in advance :):) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
This message was blank, I am not sure if that was the idea or not. On 7/22/10, ankur wrote: > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com; http://www.facebook.com/mehgcap ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how i can change two lists into one directory
On 7/22/10, ANKUR AGGARWAL wrote: > hey i have just started making a app using python and just gt a problem.. > > i have two list > a=["x","z"] > b=[1,2] > > i want to make a directory like this It is called a dictionary, actually. > c={"x":1,"z":2} > > is it possible i mean i tried it using loops and all but i cant append a > directory so i m unable to do this... > plz tell me if there's any way to get the directory like this Thanks in > advance :):) idx=0 for i in a: c[i]=b[idx] idx+=1 > -- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com; http://www.facebook.com/mehgcap ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how i can change two lists into one directory
On 7/22/2010 7:51 PM, ANKUR AGGARWAL wrote: hey i have just started making a app using python and just gt a problem.. i have two list a=["x","z"] b=[1,2] i want to make a directory like this Do you mean "dictionary"? c={"x":1,"z":2} is it possible Indeed. There are several ways to do this. Easiest: dict(zip(a,b)) i mean i tried it using loops d = {} for i in range(len(a)): d[a[i] = b[i] and all but i cant append a directory Of course you can't append, since a dictionary is not a sequence. But you can add a key-value pair as the above loop demonstrates. -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how i can change two lists into one directory
On Fri, 23 Jul 2010 09:51:37 am ANKUR AGGARWAL wrote: > hey i have just started making a app using python and just gt a > problem.. > > i have two list > a=["x","z"] > b=[1,2] > > i want to make a directory like this > c={"x":1,"z":2} The word you want is "dictionary" or "dict", not directory. Here's one slow, boring, manual way: a = ["x", "z"] b = [1, 2] c = {} c[a[0]] = b[0] c[a[1]] = b[1] You can turn that into a loop: c = {} for index in range( min(len(a), len(b)) ): c[a[i]] = b[i] Here's the sensible way that makes Python do all the heavy lifting: c = dict(zip(a, b)) -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sound libraries?
You can access openal through either pyglet or pygame I believe, and definitely thru panda3d. That would allow you to have true 3d sound positioning and I believe openal can automatically Doppler too, not sure though. Let us know what you go with or if you have questions. Sent from my iPhone On Jul 22, 2010, at 6:49 PM, Alex Hall wrote: > Hi all, > I am curious. If I wanted a library that would let me play sounds at > specific positions in the stereo field, then update that position as > the user "moved" so that it would seem to be a fixed reference point, > what would I use? For example, say the left/right arrows move you left > and right. In the center of your stereo field you hear a sound, say a > bell. As you press the arrow keys, the sound moves, or rather, you > move but the sound stays the same. Pysonic looks like the perfect > answer, but it seems to require python2.3, and I am using 2.6. Are > there any other conprehensive sound libraries that would allow for > dynamic positioning of sound, doplar effects, volume control, and so > on? > > -- > Have a great day, > Alex (msg sent from GMail website) > mehg...@gmail.com; http://www.facebook.com/mehgcap > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how i can change two lists into one directory
Hey quit spamming the list please. Sent from my iPhone On Jul 22, 2010, at 7:08 PM, Alex Hall wrote: > On 7/22/10, ANKUR AGGARWAL wrote: >> hey i have just started making a app using python and just gt a problem.. >> >> i have two list >> a=["x","z"] >> b=[1,2] >> >> i want to make a directory like this > It is called a dictionary, actually. >> c={"x":1,"z":2} >> >> is it possible i mean i tried it using loops and all but i cant append a >> directory so i m unable to do this... >> plz tell me if there's any way to get the directory like this Thanks in >> advance :):) > idx=0 > for i in a: >c[i]=b[idx] >idx+=1 >> > > > -- > Have a great day, > Alex (msg sent from GMail website) > mehg...@gmail.com; http://www.facebook.com/mehgcap > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sound libraries?
On 7/22/10, Luke Paireepinart wrote: > You can access openal through either pyglet or pygame I believe, and > definitely thru panda3d. That would allow you to have true 3d sound > positioning and I believe openal can automatically Doppler too, not sure > though. Let us know what you go with or if you have questions. Thanks. I have pygame but was less than impressed with its audio features, though it is quite possible that I missed or misread something. I am downloading Panda3d right now; its audio documentation looks quite promising. Looks like doplaring is supported, too. > > Sent from my iPhone > > On Jul 22, 2010, at 6:49 PM, Alex Hall wrote: > >> Hi all, >> I am curious. If I wanted a library that would let me play sounds at >> specific positions in the stereo field, then update that position as >> the user "moved" so that it would seem to be a fixed reference point, >> what would I use? For example, say the left/right arrows move you left >> and right. In the center of your stereo field you hear a sound, say a >> bell. As you press the arrow keys, the sound moves, or rather, you >> move but the sound stays the same. Pysonic looks like the perfect >> answer, but it seems to require python2.3, and I am using 2.6. Are >> there any other conprehensive sound libraries that would allow for >> dynamic positioning of sound, doplar effects, volume control, and so >> on? >> >> -- >> Have a great day, >> Alex (msg sent from GMail website) >> mehg...@gmail.com; http://www.facebook.com/mehgcap >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor > -- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com; http://www.facebook.com/mehgcap ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how i can change two lists into one directory
looks like this guy figured out how to send email in a loop ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor