[Tutor] Defining operators for custom types

2010-02-12 Thread Mark Young
I created a custom vector type, inheriting from object, and defined __mul__,
__add__, etc. Unfortunately, the operators only work if I type "vector *
(int/float/number)", in that exact order. My program produces an error if I
instead type "number * vector". This makes sense to me, because I haven't
told the number (int, float, whatever) how to deal with an object of type
vector, (At least, I think that's why it doesn't work.). Is there any way
to allow "number (operator) vector", short of modifying the standard types'
behavior?

Here's an example of the error.
vec1 = vector(5,6,7)
>>> vec1 * 2
(10, 12, 14)
>>> 2 * vec1
Traceback (most recent call last):
  File "", line 1, in 
2 * vec1
TypeError: unsupported operand type(s) for *: 'int' and 'vector'

I'm using python 3.1.
Thanks.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Defining operators for custom types

2010-02-12 Thread Mark Young
Thanks for the help. That's exactly the kind of solution I wanted. I've been
to that page several times already, but just ignored that section
apparently. Thanks alot.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Calling a number's methods

2010-06-22 Thread Mark Young
Why does this work

>>> a = 6
>>> b = 7
>>> answer = a.__sub__(b.__neg__())
>>> answer
13


but this does not?

>>> answer = 6.__sub__(7.__neg__())
SyntaxError: invalid syntax

I searched the internet, and found someone suggest adding spaces after each
number, which indeed works properly.

>>> answer = 6 .__sub__(7 .__neg__())
>>> answer
13

Why does this work? I don't even understand why python recognizes that I'm
trying to access the numbers' __sub__ and __neg__ methods, I would think
that the spaces would cause it to not work, but obviously it works just
fine.

Thanks!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Calling a number's methods

2010-06-23 Thread Mark Young
Hmm, apparently python doesn't care about whitespace in method calls or
attribute access:

class person:
def __init__(self):
self.name ="jim"
def hi(self):
print("hello")

>>> guy = person()
>>> guy.   name
'jim'
>>> guy   .hi()
hello

That at least explains that part of my question. I never knew this, although
it's pretty ugly, so I guess it's fairly useless information. Thanks for the
guess, Alan. That seems reasonable.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Scripting Blender

2010-08-11 Thread Mark Young
2010/8/11 Corey Richardson 

> Yes. It's called the Python API, it comes with Blender ;) bpy and Blender
> are the top modules. There are submodules for everything. The reference is
> here: http://www.blender.org/documentation/249PythonDoc/index.html
>
> HTH,
> ~Corey Richardson
>
> aug dawg wrote:
>
>> Are there any Python modules to script Blender? For example, placing
>> predefined objects into a new Blender project to create a 3D model.
>>
>> Thanks!
>>
>> 
>>
>>
>> ___
>> 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
>


Questions about coding in blender will likely be answered better at
http://blenderartists.org/forum/ .
Also, the previously mentioned docs are outdated, documenting blender 2.4x,
which is supposed to become obsolete sometime soon. Blender 2.5x is pretty
different from 2.4x, so those docs won't help too much.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] this module

2009-08-07 Thread Mark Young
Hi, I was reading a tutorial, and it mentioned the "import this" easter egg.
I was curious, and looked up the contents of the module, and dscovered that
it had attributes c, d, i, and s. I was wondering if anyone had any clue
what these attributes were supposed to mean. I think (this.s) is the zen of
python in some foreign language (dutch maybe?), but I have no clue what the
significance of the others are. Just wondering if anyone knew, (or if they
mean anything at all).

Also, I was wondering, when a user first imports this, how does the module
print the zen of python? I can't figure out how it does it.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] this module

2009-08-08 Thread Mark Young
Thanks everybody, I didn't know modules ran code when you imported them, I
just thought they defined the functions, etc. in them.  Thanks for the info.
I'm going to go look at the module's code now that I know where it's at.

Mark Young
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] What language should I learn after Python?

2009-10-06 Thread Mark Young
I'm now fairly familiar with Python, so I'm thinking about starting to learn
a second programming language. The problem is, I don't know which to learn.
I want a language that will be good for me to learn, but is not so different
from python that I will be totally confused. I tried learning C++ and it was
a massive failure, so I definitely think I'd like to stay closer to a
high-level language. I know that this is a subjective question, but I'd
still like to hear some suggestions if anyone has any.

Also, I wasn't really sure if it was okay to ask this on tutor, if it's the
wrong place, I'm sorry.

Mark Young
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What language should I learn after Python?

2009-10-06 Thread Mark Young
 I have no real need to learn anything for a job, it's just a hobby right
now. I mostly just want "a programming language that has a different
philosophy or approach than
Python".  However, you guys are right, if I just learn a language without a
reason, it will be worthless.

When I tried to learn C++, I just got extremely confused, I didn't even
understand the basic "Hello World" script. I may have given up too quickly;
maybe I should try again, or maybe I'll try C.

I was thinking about Java, and I heard about Lisp, I heard that it would
supposedly make you a better programmer or something. I looked at Lisp, but
I wasn't sure which one to use, Scheme or Common Lisp. I think I heard the
same about Haskell, but I'm not sure if I'm remembering correctly.

Thanks for the suggestions so far. I'm thinking about trying to go back to
C++ or C, to study a a lower level language, or maybe Lisp, just to see
different techniques in a high level language. I guess I have to accept that
things will be different in any language, and if I want to learn different
methods and gain new abilities, I'll just have suck it up and start reading.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What language should I learn after Python?

2009-10-06 Thread Mark Young
Ok, thanks alot everybody. I think I'll start with either Scheme or C, I
haven't decided yet. I was pleasantly surprised by how Scheme looks, it's
much prettier than some other languages I looked at.

Contributing to a project actually sounds like a good idea, I've never done
a project with other people before, so it would definitely be helpful, for
both my Python and for whatever language I pick up. I think I may wait a bit
though, so I can actually help someone instead of slowing them down.

Anyway, thanks everyone for the input, you've helped alot.

Mark Young
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What language should I learn after Python?

2009-10-07 Thread Mark Young
2009/10/7 Serdar Tumgoren 

> And in case you hadn't heard enough suggestions yet, here's something
> I just stumbled into this morning:
>
> Programming Paradigms for Dummies, by Peter Norvig
> http://lambda-the-ultimate.org/node/3465
>
> Here's a portion of the soundbite from the website (where you can
> download the PDF):
>
> "This chapter gives an introduction to all the main programming
> paradigms, their underlying concepts, and the relationships between
> them. We give a broad view to help programmers choose the right
> concepts they need to solve the problems at hand. We give a taxonomy
> of almost 30 useful programming paradigms and how they are related.
> Most of them differ only in one or a few concepts, but this can make a
> world of difference in programming."
>
> Having skimmed a few pages, I'm not sure I'd say this is your average
> "Dummies" book, but it appears to provide a bird's eye view of how
> different languages are geared to solve different kinds of problems.
> Might bring the landscape into sharper relief before you settle on
> that next language.
>
> HTH!
>
> Serdar
>  ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


 It looks interesting, I'm working on reading it.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor