about python ..

i am new to python…
can anyone please tell me what does…

class World(DirectObject):

directobject means…

and while you define
def init(self):
what is the role of self here …
Thanx in advance…

Hi, and welcome to the forums!

This is a very basic Python question, and when using Panda3D you are expected to already know Python. I advise you to learn Python before attempting Panda3D.
Check this page for a list of tutorials:
wiki.python.org/moin/BeginnersGu … rogrammers

I am newbie here.I want to develop a game using ASP.NET.I just want to know whether it is possible to develop game in Panda3D by using coding of ASP.NET.Hope to get some help from here.Any feedback is appreciated.

Hi, and welcome to the forums! :slight_smile:

Er, isn’t ASP.NET a language for creating websites? I don’t think that would work.
Technically, if you find a way to generate .NET wrappers for Panda3D, and compile ASP.NET code into a standalone application, it could work. But it’s a ridiculous idea and I wouldn’t see the point of it.

Oh, and on a sidenote: please create a new thread instead if you want to ask a question unrelated to the thread you’re posting in.


Thanx a ton for your kind replay… that is really a great help for me…

thanx i found it…
i am very very happy…
i post this so that any one who later have this doubt may benifit from this

5.3. Defining Classes

* 5.3.1. Initializing and Coding Classes
* 5.3.2. Knowing When to Use self and __init__

Python is fully object-oriented: you can define your own classes, inherit from your own or built-in classes, and instantiate the classes you’ve defined.

Defining a class in Python is simple. As with functions, there is no separate interface definition. Just define the class and start coding. A Python class starts with the reserved word class, followed by the class name. Technically, that’s all that’s required, since a class doesn’t need to inherit from any other class.
Example 5.3. The Simplest Python Class

class Loaf: 1
pass 2 3

1 The name of this class is Loaf, and it doesn’t inherit from any other class. Class names are usually capitalized, EachWordLikeThis, but this is only a convention, not a requirement.
2 This class doesn’t define any methods or attributes, but syntactically, there needs to be something in the definition, so you use pass. This is a Python reserved word that just means “move along, nothing to see here”. It’s a statement that does nothing, and it’s a good placeholder when you’re stubbing out functions or classes.
3 You probably guessed this, but everything in a class is indented, just like the code within a function, if statement, for loop, and so forth. The first thing not indented is not in the class.
The pass statement in Python is like an empty set of braces ({}) in Java or C.

Of course, realistically, most classes will be inherited from other classes, and they will define their own class methods and attributes. But as you’ve just seen, there is nothing that a class absolutely must have, other than a name. In particular, C++ programmers may find it odd that Python classes don’t have explicit constructors and destructors. Python classes do have something similar to a constructor: the init method.
Example 5.4. Defining the FileInfo Class

from UserDict import UserDict

class FileInfo(UserDict): 1

1 In Python, the ancestor of a class is simply listed in parentheses immediately after the class name. So the FileInfo class is inherited from the UserDict class (which was imported from the UserDict module). UserDict is a class that acts like a dictionary, allowing you to essentially subclass the dictionary datatype and add your own behavior. (There are similar classes UserList and UserString which allow you to subclass lists and strings.) There is a bit of black magic behind this, which you will demystify later in this chapter when you explore the UserDict class in more depth.
In Python, the ancestor of a class is simply listed in parentheses immediately after the class name. There is no special keyword like extends in Java.

Python supports multiple inheritance. In the parentheses following the class name, you can list as many ancestor classes as you like, separated by commas.
5.3.1. Initializing and Coding Classes

This example shows the initialization of the FileInfo class using the init method.
Example 5.5. Initializing the FileInfo Class

class FileInfo(UserDict):
“store file metadata” 1
def init(self, filename=None): 2 3 4

1 Classes can (and should) have doc strings too, just like modules and functions.
2 init is called immediately after an instance of the class is created. It would be tempting but incorrect to call this the constructor of the class. It’s tempting, because it looks like a constructor (by convention, init is the first method defined for the class), acts like one (it’s the first piece of code executed in a newly created instance of the class), and even sounds like one (“init” certainly suggests a constructor-ish nature). Incorrect, because the object has already been constructed by the time init is called, and you already have a valid reference to the new instance of the class. But init is the closest thing you’re going to get to a constructor in Python, and it fills much the same role.
3 The first argument of every class method, including init, is always a reference to the current instance of the class. By convention, this argument is always named self. In the init method, self refers to the newly created object; in other class methods, it refers to the instance whose method was called. Although you need to specify self explicitly when defining the method, you do not specify it when calling the method; Python will add it for you automatically.
4 init methods can take any number of arguments, and just like functions, the arguments can be defined with default values, making them optional to the caller. In this case, filename has a default value of None, which is the Python null value.
By convention, the first argument of any Python class method (the reference to the current instance) is called self. This argument fills the role of the reserved word this in C++ or Java, but self is not a reserved word in Python, merely a naming convention. Nonetheless, please don’t call it anything but self; this is a very strong convention.
Example 5.6. Coding the FileInfo Class

class FileInfo(UserDict):
“store file metadata”
def init(self, filename=None):
UserDict.init(self) 1
self[“name”] = filename 2

1 Some pseudo-object-oriented languages like Powerbuilder have a concept of “extending” constructors and other events, where the ancestor’s method is called automatically before the descendant’s method is executed. Python does not do this; you must always explicitly call the appropriate method in the ancestor class.
2 I told you that this class acts like a dictionary, and here is the first sign of it. You’re assigning the argument filename as the value of this object’s name key.
3 Note that the init method never returns a value.
5.3.2. Knowing When to Use self and init

When defining your class methods, you must explicitly list self as the first argument for each method, including init. When you call a method of an ancestor class from within your class, you must include the self argument. But when you call your class method from outside, you do not specify anything for the self argument; you skip it entirely, and Python automatically adds the instance reference for you. I am aware that this is confusing at first; it’s not really inconsistent, but it may appear inconsistent because it relies on a distinction (between bound and unbound methods) that you don’t know about yet.

Whew. I realize that’s a lot to absorb, but you’ll get the hang of it. All Python classes work the same way, so once you learn one, you’ve learned them all. If you forget everything else, remember this one thing, because I promise it will trip you up:
init methods are optional, but when you define one, you must remember to explicitly call the ancestor’s init method (if it defines one). This is more generally true: whenever a descendant wants to extend the behavior of the ancestor, the descendant method must explicitly call the ancestor method at the proper time, with the proper arguments.

diveintopython.org/object_orient … asses.html