java to python q's

Blake Winton bwinton at tor.dhs.org
Mon May 15 22:16:59 EDT 2000


In comp.lang.python, you wrote:
>(from the java code below)
>1) whats the differance between public and private and what is the
>equivalent in python?

Public means that anyone can see your variables.  Private means that
only you can see your variables.  There is a middle ground called
"protected", which means that you and your sub-classes can see your
variables.

In Python, everything is public, and you trust people not to look at
things you ask them not to.  Oh, yeah, and if you name something with an
_ at the start, it's a sign that perhaps people shouldn't use it.

>2) how do i declare the variable nvsequence of type NvSequence in python?

nvsequence = new NvSequence()

In Python, variables aren't strongly typed, so the variable nvsequence
can contain anything.  If you want it to only contain NvSequences, then
only assign NvSequences to it.  :)

>3) is this.id = id; the same as self.id = id, in python?

I think so.

>  this.nvSequence = null;
>how do i set this.nvSequence to null in python?
>is it:
> def msg(id,subid,nvSequence=None)?

That would work.

Or just self.nvSequence = null

>5)how/what modules do i use to find the index of the first/second integer in
>a string?

>>> import string

>>> dir( string )
['__builtins__', '__doc__', '__file__', '__name__', '_idmap', '_idmapL',
'_lower', '_re', '_safe_env', '_swapcase', '_upper', 'atof',
'atof_error', 'atoi', 'atoi_error', 'atol', 'atol_error', 'capitalize',
'capwords', 'center', 'count', 'digits', 'expandtabs', 'find',
'hexdigits', 'index', 'index_error', 'join', 'joinfields', 'letters',
'ljust', 'lower', 'lowercase', 'lstrip', 'maketrans', 'octdigits',
'replace', 'rfind', 'rindex', 'rjust', 'rstrip', 'split', 'splitfields',
'strip', 'swapcase', 'translate', 'upper', 'uppercase', 'whitespace',
'zfill']

>>> print string.find.__doc__
find(s, sub [,start [,end]]) -> in

Return the lowest index in s where substring sub is found,
such that sub is contained within s[start,end].  Optional
arguments start and end are interpreted as in slice notation.

Return -1 on failure.

>>> print string.index.__doc__
index(s, sub [,start [,end]]) -> int

        Return the lowest index in s where substring sub is found,
        such that sub is contained within s[start,end].  Optional
        arguments start and end are interpreted as in slice notation.

        Raise ValueError if not found.

Hope this helps,
Blake.
-- 
8:24pm up 24 days, 34 min, 2 users, load average: 1.00, 1.02, 1.00




More information about the Python-list mailing list