473,383 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

No Thoughts about Everything

I wonder about the huge traffic in the question how many tuples are
dispensible. I find that a question of only ternary or quarterny order -
use it or use it not (free after Shakespears "to be or not to be). Well,
I had my part on that.

But introducing students to python as a first programming language lists
and tuples are astoninglishy always constant points of confusion as well
as the other points of the citatet list. I will not repeat it now, but
the class-questions are more interesting for me and fundamental for the
choice of python.

A point of vital interest for me are the classes and the handling of
class variables. I have read a lot of discussion threads in the mean
time and the PEP 318 as well. One point of critic will become obsolet
with the possible future change described in PEP 318. (Use of Java-like
modifiers is simpler.)

I find the syntax and handling of classes and class variables (or static
variables) in python not an absolute success. Fist that is a result of
comparing my personal experience with Java in the first place. Second it
is an experience of introductory teaching python. The learning curve is
astoninglishly steep, but it will flatten arriving at classes and
objects in python. Compared with Java I found it just opposit.

Beside, I find the concept of modifiers in Java very attractive. (May be
that concept is not absolutely clean OO - but it is very simple to apply
in real world programming.) Some arguments I found in the discussions
make me arguing that some concepts connected to that modifiers are
absolutely misunderstood. For instance "information hiding" with the use
of the modifier "private" for instance variables and/or methods
basically means that no direct access from the clients is allowed. There
is no doubt, that that concept rescues bugs and improves program
modification. In the discussions very often "information hiding" is only
interpreted as "hidden code". Even compiled Java code can easily be
recovered - start a internet search for appropriate tools. In an
interpreted language like python I see no problem at all. (Guido will
never allow hiding.......)

Let me give you an instance for the use of the Java modifiers static and
final. (There are three "visibility" and seven other modifiers in Java)
That problem is not a constructed and log searched example, but an every
day application in teaching for instance natural or engineering science,
while using Java. I kindly ask for help to transfer that simple, single
line intelligent to python in the best possible way:

static final double c=2.99792458e8;

That is the speed of light in vacuum in scientific (exponential)
notation. I use it in a class as a class variable. That means it will be
shared as a single copy of a variable among all of the objects
instantiated from that class. That is the meaning of the modifier
"static". With final I make it to a constant, that cannot changed by any
code. (double is self speaking, it is not necessary in python - as
anyone knows.) I dont like to use c as global variable. A possible
waywith the following code recipes?

1. modifier final
For instance recipe 5.15 Defining Constants (Alex Martelli) out of the
python cookbook (OReilly, ISBN 0-596-00167-3) shows, how to define
constants. About 10 lines, instead of one modifier - I have not found
another way.
2. modifier static
There is recipe 5.6 i(Alex Martelli, Carel Fellinger) in the cited book
shows how to implement static Methods to make variables static. Three
more lines for a simple modifier.

With some time and by trial and error may be I find the solution. But
there are many Geeks reading python.org. I think for them it is only a
fingersnip to transfer that to the python way? So, here again my Question:
How can I create such a "class constant" (static final / recipe 5.15 and
5.6 in one) in python as short as possible?
(I hope you recognize, why teaching python to beginners becomes tedious
in python arriving at that point?)

Thanks in advance
Bernhard


Jul 18 '05 #1
5 1624

"b-blochl" <bb******@compuserve.de> wrote in message
news:ma*************************************@pytho n.org...
I wonder about the huge traffic in the question how many tuples are
dispensible. I find that a question of only ternary or quarterny order -
use it or use it not (free after Shakespears "to be or not to be). Well,
I had my part on that.

But introducing students to python as a first programming language lists
and tuples are astoninglishy always constant points of confusion as well
as the other points of the citatet list. I will not repeat it now, but
the class-questions are more interesting for me and fundamental for the
choice of python.
Tuples can be difficult if they're not explained properly, and
I don't find a lot of good material around that really brings
out the salient points.

For me at least, the basic thing about tuples is that they're a
quick way of bundling a bunch of objects together when you
don't want to go to the trouble of creating a special purpose
object to hold them.

I think that the use of implicit tuple creation on the return statement
and sequence unpacking make this point quite well.

I find that classifying them as sequences is essentially confusing,
and also stating that they're immutable is, while true, also confusing.

Thanks in advance
Bernhard

Jul 18 '05 #2
b-blochl wrote:
static final double c=2.99792458e8;

That is the speed of light in vacuum in scientific (exponential)
notation. I use it in a class as a class variable. That means it will be
shared as a single copy of a variable among all of the objects
instantiated from that class. That is the meaning of the modifier
"static". With final I make it to a constant, that cannot changed by any
code. (double is self speaking, it is not necessary in python - as
anyone knows.) I dont like to use c as global variable. So, here again my Question:
How can I create such a "class constant" (static final / recipe 5.15 and
5.6 in one) in python as short as possible?

This will create c as an unmodifiable attribute:

c = property(lambda self: 2.99792458e8)
Does that do what you want?

Jul 18 '05 #3
> This will create c as an unmodifiable attribute:

c = property(lambda self: 2.99792458e8)
Does that do what you want?

class foo: .... c = property(lambda self: 2.99792458e8)
.... v = foo()
v.c 299792458.0 v.c += 1
v.c 299792459.0 foo().c 299792458.0


It doesn't quite work.

- Josiah
Jul 18 '05 #4
Josiah Carlson wrote:
This will create c as an unmodifiable attribute:

c = property(lambda self: 2.99792458e8)
Does that do what you want?


>>> class foo: ... c = property(lambda self: 2.99792458e8)
... >>> v = foo()
>>> v.c 299792458.0 >>> v.c += 1
>>> v.c 299792459.0 >>> foo().c 299792458.0 >>>
It doesn't quite work.


I suppose I should have mentioned that you have to use a new-style class:
class foo(object): .... c = property(lambda self: 2.99792458e8)
.... v = foo()
v.c 299792458.0 v.c += 1

Traceback (most recent call last):
File "<input>", line 1, in ?
AttributeError: can't set attribute
I don't think the behavior of property() is even officially defined for
old-style classes.

Jul 18 '05 #5
> I don't think the behavior of property() is even officially defined for
old-style classes.


Very good point. I think I'm going to need to play with properties next
weekend.

- Josiah
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

39
by: Marco Aschwanden | last post by:
Hi I don't have to talk about the beauty of Python and its clear and readable syntax... but there are a few things that striked me while learning Python. I have collected those thoughts. I am...
1
by: Steve | last post by:
I'm still a database newbie so I would like to solicit thoughts about the smartest way to do something in sqlserver. My company has a web application that we customize for each client. We can...
1
by: jmar | last post by:
I posted on this topic a while back and received some good responses. However, I have better insight into what I'm looking to do so I am tapping the wealth of experience here again hoping to find a...
0
by: Suganya | last post by:
"Change your language and you change your thoughts." Learn English and free download Grammar & dictionary. Just click the website and share ur thoughts….enter in the search column “What do u...
0
by: Suganya | last post by:
"Change your language and you change your thoughts." Learn English and free download Grammar & dictionary. Just click the website and share ur thoughts….enter in the search column “What do u...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.