Writing "pythonish" code
skyofdreams
skyofdreams at gmail.com
Fri Feb 2 06:48:33 EST 2007
"Mizipzor" <mizipzor at gmail.com>
??????:mailman.3452.1170415251.32031.python-list at python.org...
> Hi, this is my first mail to the list (and any list for that matter)
> so any pointers on errors from my part would be appreciated. Im more
> used to forums.
>
> To start off, Ive read some python documents and done some small apps
> so I think I can say I know it semi-well, and I know c++ very well.
> But I want learn python even better, since I know that a company I aim
> to be employed by make heavy use of python, knowing python myself
> would give me an extra edge.
>
> The problem isnt in pythons syntax, its in the architecture/design,
> the concept of writing "pythonish code" if you like. One thing is that
> in c++ im used to have private members in classes and no member is
> altered except through the public functions of the class. In python
> everything is, as far as I know, public. Im confused by this, should I
> still have members in the python class that I simply dont edit
> directly and let the class do its internal stuff? Or should I see the
> python classes like c++ structs with functions?
>
> I guess the ultimate is somewhere in between but I would like a nudge
> or two to get there.
>
as far as i know, the class attributes haven't privilege identifier.
I think If in C++ i need friend relationship between 2 classes, then in
python, i'll access the attribute directly.
in other cases, i treat it as class, suspose it's private attribute , just
like classes in C++.
>
> To me, the main.py code above looks very ugly. So, assuming Im never
> gonna have more than one instance of the foo class, can I write
> something like this:
>
> foo.py
> =========
>
> def bar(self):
> print "bar"
>
> =========
main.py
============
from foo import foo
foo().bar()
try this, it's ok, "from foo import foo" the first "foo" is module-name,
the latter foo is class name.
the formal package import tutortial link is
http://docs.python.org/tut/node8.html#SECTION008400000000000000000
> Thats much more cleaner if you ask me, and kinda a good way to make
> sure that you dont have more than one "instance" of the foo class
> (which no longer is a class at all). But is it "pythonish"?
>
> Gonna stop now, this mail got a little longer than i first thought.
> Any input will be greatly appreciated. :)
HTH
-skyofdreams
More information about the Python-list
mailing list