Emulating C++ coding style

Ivan Van Laningham ivanlan at callware.com
Thu Apr 22 17:58:00 EDT 1999


Hi Thooney and all the other Pythonistas out there--

Thooney Millennier wrote:
> 
> Hello Everyone!
> 
> I usually use C++ ,so I want to make programs like
> I do using C++.
> I don't figure out how to implement the followings
> by Python.
> If you know any solutions,Please Help!
> 
> 1. #define statements
>   e.g. #define __PYTHON_INCLUDED__
>        #define PYPROC(ARG) printf("%s",ARG)
> 

__PYTHON_INCLUDED__ = 1

(Although that's probably not what you really mean to do.)

def PYPROC(arg):
	print arg

> 2. stream class
>   e.g. cout << "hello python."<<endl;
> 

print "hello python"

--or--

sys.stdout.write("hello python")


> 3. const variables
>   e.g. const int NOCHAGE=1;
> 

Can't be done.  Any sufficiently determined Pythonista can change
anything she wants to.

But, you can do this to keep your edges inside a specific file--

_NOCHANGE = 1

Any variable beginning with an underscore has module-specific scope.

> 4. access to class's members using "::"
>   e.g. some_class::static_value
>   e.g. some_class::static_func(x)
> 

print some_class.static_value
t = some_class.static_func(x)

See, there's no real concept of a ``static'' member, or of ``private''
members in Python classes.  All methods and members of all classes are
public.  That's a good thing.

> Thanks for reading.
> 
> Thooney Millennier.

You should investigate the tutorial at http://www.python.org

It's really very good, and with your C++ experience you will have no
trouble at all.

<arigato-to-another-newbie>-ly y'rs,
Ivan
----------------------------------------------
Ivan Van Laningham
Callware Technologies, Inc.
ivanlan at callware.com
http://www.pauahtun.org
See also: 
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps:  Cu Chi, Class of '70
----------------------------------------------




More information about the Python-list mailing list