On vrijdag 26 januari 2018 22:25:55 CET eil...@themaii.org wrote:
> well, you certainly got me correct! I'm fairly new to python - didn't do
> much coding to learn. Trial by fire, sort of. and the original person who
> put this together is now gone from the company and won't answer any
> outstanding questions. Plus, I *think* he got most of the code from 3rd
> party sources. I could be wrong on that. I was raised on Perl and PL/I (as
> ancient as the latter may seem)

I meant to follow this up, didn't have the opportunity till now.

I strongly suggest to get the python basics down. Your Perl hash is your python 
dict, array 
is a list (tuple for "read only" lists) and you have you basic scalars with 
str, bool, int and 
float. And you have objects. In fact, /everything/, including scalars, class 
definitions, 
methods and functions are objects.

Standard comparison is "==". The "is" comparison is stricter and only used for 
boolean 
values and the special value None (also handy to know is that functions / 
methods that do 
not return anything actually return None).

One can think of "is" comparison as "equal to and of the same type":

>>> empty = ''
>>> empty is None
False
>>> empty is False
False
>>> empty is True
False
>>> bool(empty)
False
>>> bool(empty) is False
True
>>> bool(None)
False

If you want a quick intro to Python, I highly suggest Python Tips[1].

project layout[2] and in your case, getting a handle on views[3] and 
querysets[4].

> 
> On Friday, January 26, 2018 at 3:12:19 PM UTC-5, Melvyn Sopacua wrote:
> > There are a bunch of issues with this code:
> > 
> > 1) Spell Physical correctly:
> > >   2 - Phyiscal
> > >   
> > >             if form.data['handicapped'] is 'Physical' or 'Mental':
> > >     handicapped = forms.ChoiceField(choices=[(x, x) for x in ('-------',
> > > 
> > > 'Mental', 'Physcal')], required=False)
> > 
> > Comparison of non boolean or None values using "is" instead of "==":
> > >             if form.data['handicapped'] is 'Physical' or 'Mental':
> > Use of or as if natural language in RHS of comparisons (should be a == x
> > or a
> > 
> > == y, not a == x or y):
> > >             if form.data['handicapped'] is 'Physical' or 'Mental':
> > 
> > >             if form['handicapped'].data == 1 or 2:
> > So this reads as if someone with very little knowledge of Python is
> > modifying
> > a 3rd party app, written by someone with a decent amount of Django
> > experience.
> > 
> > Finally, when accessing form data from a valid form, we access
> > form.cleaned_data and generally use a local variable to reference the
> > dict:
> > 
> > if form.is_valid():
> >     data = form.cleaned_data
> >     # do stuff with data


-- 
Melvyn Sopacua

--------
[1] http://book.pythontips.com/en/latest/index.html
[2] https://docs.djangoproject.com/en/2.0/intro/tutorial01/#creating-a-project
[3] https://docs.djangoproject.com/en/2.0/topics/class-based-views/
[4] https://docs.djangoproject.com/en/2.0/topics/db/queries/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1695553.VomjpEPLdD%40fritzbook.
For more options, visit https://groups.google.com/d/optout.

Reply via email to