From: MRAB on
Victor Subervi wrote:
> I've isolated the problem in the print-out at the bottom of this post.
> It occurs when these values are passed:
>
> ['LastDatePrice', 'date', '10', 'yyyy/mm/dd', None],
>
> Since this is the first datetime that is passed, it would appear to be
> associated with such values, which are processed thus:
>
> elif typeName == 'datetime':

Where does the value of typeName come from?

> print "<input type='text' width='%s' maxlength='%s' name='%s'
> value='%s' /> " \
> "<i>This field takes a datetime up to %s alphanumeric characters
> inclusive.</i>" \
> % (shortNum, str(typeNum), colName, theVal, str(typeNum))
>
> colName == 'LastDatePrice'
> typeNum = 10
>
> elif 10 < int(typeNum) < 20:

If typeNum is 10 then 10 < int(typeNum) < 20 is False.

> shortNum = '10'
>
> Therefore...
> shortNum = '10'
>
> if whatDo == 'insert':
> theVal = defaultVal
> val = defaultVal
>
What's the difference between theVal and val? The names don't help me!
:-)

> Since whatDo == 'insert'...
> and
> val = 'yyyy/mm/dd'
> therefore
> theVal = None
>
> Now, this value of None doesn't cause any problems with the other values
> printed out. This is the code:
>
> print 'printTheForm: ', descrProds, '<br />'
> for value in descrProds:
> print 'value: ', value, '<br />'
>
> that produces this print-out:
>
> printTheForm: [['ID', 'tinyint', '5', '0', None], ['SKU', 'varchar',
> '40', '', None], ['Category', 'varchar', '40', '', None], ['Name',
> 'varchar', '50', '', None], ['Title', 'varchar', '100', '', None],
> ['Description', 'mediumtext', '100', '', None], ['Price', 'float', '8',
> '0.0', None], ['SortFactor', 'int', '4', '0', None], ['Availability',
> 'tinyint', '1', '0', '1'], ['OutOfStock', 'tinyint', '1', '0', '0'],
> ['ShipFlatFee', 'float', '5', '0.0', '0.00'], ['ShipPercentPrice',
> 'tinyint', '2', '0', '0'], ['ShipPercentWeight', 'tinyint', '2', '0',
> '0'], ['Associations', 'varchar', '40', '', None], ['TempPrice',
> 'tinyint', '1', '0', None], ['LastDatePrice', 'date', '10',
> 'yyyy/mm/dd', None], ['Weight', 'float', '7', '0.0', None], ['Metal',
> 'enum', ['14k gold', '18k gold', 'white gold', 'silver', 'tungsten',
> 'titanium'], '', None], ['PercentMetal', 'tinyint', '2', '0', None],
> ['colorsShadesNumbersShort', 'set', [''], '', None]]
> value: ['ID', 'tinyint', '5', '0', None]
> value: ['SKU', 'varchar', '40', '', None]
> value: ['Category', 'varchar', '40', '', None]
> value: ['Name', 'varchar', '50', '', None]
> value: ['Title', 'varchar', '100', '', None]
> value: ['Description', 'mediumtext', '100', '', None]
> value: ['Price', 'float', '8', '0.0', None]
> value: ['SortFactor', 'int', '4', '0', None]
> value: ['Availability', 'tinyint', '1', '0', '1']
> value: ['OutOfStock', 'tinyint', '1', '0', '0']
> value: ['ShipFlatFee', 'float', '5', '0.0', '0.00']
> value: ['ShipPercentPrice', 'tinyint', '2', '0', '0']
> value: ['ShipPercentWeight', 'tinyint', '2', '0', '0']
> value: ['Associations', 'varchar', '40', '', None]
> value: ['TempPrice', 'tinyint', '1', '0', None]
> value: ['LastDatePrice', 'date', '10', 'yyyy/mm/dd', None]
>
> If in fact the problem has to do with the None value, how can I easily
> substitute a different value? I tried:
>
> if theVal == None:

The Pythonic way is to use "is" when comparing with singletons like
None.

> theVal = ''
>
> but that didn't capture it.
>
What do you mean by "didn't capture it"?
From: Carsten Haese on
Victor Subervi wrote:
> [...]
> If in fact the problem has to do with the None value, how can I easily
> substitute a different value? I tried:
>
> if theVal == None:
> theVal = ''
>
> but that didn't capture it.

That indicates one of two things:
* Your problem is not caused by the None value.
* Your problem is caused by code that is executed before the above
substitution.

Unfortunately, nobody is going to be able to offer any concrete advice,
since you're not posting the actual code you're running. My guess is
that something in your code for handling a datetime field is raising an
exception that is caught and silenced with an "except: pass" somewhere
outside your loop.

The only way we can help you is if you help us help you by posting your
actual code instead of incoherent snippets. You have been asked many
times before to post your actual code. One has to wonder what causes
your persistent inability or unwillingness to honor this request.

--
Carsten Haese
http://informixdb.sourceforge.net

From: Emile van Sebille on
On 12/23/2009 10:21 AM Victor Subervi said...
<snip>
> printed out. This is the code:
>
> print 'printTheForm: ', descrProds, '<br />'
> for value in descrProds:
> print 'value: ', value, '<br />'

Why not try this in a fashion more likely to succeed...

import cgi
for value in descrProds:
print 'value: %s <br />' % cgi.escape(value)

That should at least push everything through whatever is causing the
problem so you can see what values actually are...

Emile

From: uticdmarceau2007 on
Victor Subervi wrote:
> On Wed, Dec 23, 2009 at 2:21 PM, Victor Subervi <victorsubervi(a)gmail.com>wrote:
>
>> I've isolated the problem in the print-out at the bottom of this post. It
>> occurs when these values are passed:
>>
>> ['LastDatePrice', 'date', '10', 'yyyy/mm/dd', None],
>>
>> Since this is the first datetime that is passed, it would appear to be
>> associated with such values, which are processed thus:
>>
>> elif typeName == 'datetime':
>> print "<input type='text' width='%s' maxlength='%s' name='%s'
>> value='%s' /> " \
>> "<i>This field takes a datetime up to %s alphanumeric characters
>> inclusive.</i>" \
>> % (shortNum, str(typeNum), colName, theVal, str(typeNum))
>>
>> colName == 'LastDatePrice'
>> typeNum = 10
>>
>> elif 10 < int(typeNum) < 20:
>> shortNum = '10'
>>
>> Therefore...
>> shortNum = '10'
>>
>> if whatDo == 'insert':
>> theVal = defaultVal
>> val = defaultVal
>>
>> Since whatDo == 'insert'...
>> and
>> val = 'yyyy/mm/dd'
>> therefore
>> theVal = None
>>
>> Now, this value of None doesn't cause any problems with the other values
>> printed out. This is the code:
>>
>> print 'printTheForm: ', descrProds, '<br />'
>> for value in descrProds:
>> print 'value: ', value, '<br />'
>>
>> that produces this print-out:
>>
>> printTheForm: [['ID', 'tinyint', '5', '0', None], ['SKU', 'varchar', '40',
>> '', None], ['Category', 'varchar', '40', '', None], ['Name', 'varchar',
>> '50', '', None], ['Title', 'varchar', '100', '', None], ['Description',
>> 'mediumtext', '100', '', None], ['Price', 'float', '8', '0.0', None],
>> ['SortFactor', 'int', '4', '0', None], ['Availability', 'tinyint', '1', '0',
>> '1'], ['OutOfStock', 'tinyint', '1', '0', '0'], ['ShipFlatFee', 'float',
>> '5', '0.0', '0.00'], ['ShipPercentPrice', 'tinyint', '2', '0', '0'],
>> ['ShipPercentWeight', 'tinyint', '2', '0', '0'], ['Associations', 'varchar',
>> '40', '', None], ['TempPrice', 'tinyint', '1', '0', None], ['LastDatePrice',
>> 'date', '10', 'yyyy/mm/dd', None], ['Weight', 'float', '7', '0.0', None],
>> ['Metal', 'enum', ['14k gold', '18k gold', 'white gold', 'silver',
>> 'tungsten', 'titanium'], '', None], ['PercentMetal', 'tinyint', '2', '0',
>> None], ['colorsShadesNumbersShort', 'set', [''], '', None]]
>> value: ['ID', 'tinyint', '5', '0', None]
>> value: ['SKU', 'varchar', '40', '', None]
>> value: ['Category', 'varchar', '40', '', None]
>> value: ['Name', 'varchar', '50', '', None]
>> value: ['Title', 'varchar', '100', '', None]
>> value: ['Description', 'mediumtext', '100', '', None]
>> value: ['Price', 'float', '8', '0.0', None]
>> value: ['SortFactor', 'int', '4', '0', None]
>> value: ['Availability', 'tinyint', '1', '0', '1']
>> value: ['OutOfStock', 'tinyint', '1', '0', '0']
>> value: ['ShipFlatFee', 'float', '5', '0.0', '0.00']
>> value: ['ShipPercentPrice', 'tinyint', '2', '0', '0']
>> value: ['ShipPercentWeight', 'tinyint', '2', '0', '0']
>> value: ['Associations', 'varchar', '40', '', None]
>> value: ['TempPrice', 'tinyint', '1', '0', None]
>> value: ['LastDatePrice', 'date', '10', 'yyyy/mm/dd', None]
>>
>> If in fact the problem has to do with the None value, how can I easily
>> substitute a different value? I tried:
>>
>> if theVal == None:
>> theVal = ''
Taken from: http://boodebr.org/main/python/tourist/none-empty-nothing:

tags = parse_file(filename)
if tags is None:
print "** ERROR **"
elif len(tags) == 0:
print "Empty file"
else:
print "OK!"


>>
>> but that didn't capture it.
>>
>
> Update:
> It's a date value (not datetime). I updated the database to default to the
> value "2000-01-01" but that didn't help (gave the same print-out as above).
>
>
>> TIA,
>> beno
>>
>


From: MRAB on
Victor Subervi wrote:
> On Wed, Dec 23, 2009 at 3:03 PM, MRAB <python(a)mrabarnett.plus.com
> <mailto:python(a)mrabarnett.plus.com>> wrote:
>
> Victor Subervi wrote:
>
> I've isolated the problem in the print-out at the bottom of this
> post. It occurs when these values are passed:
>
> ['LastDatePrice', 'date', '10', 'yyyy/mm/dd', None],
>
> Since this is the first datetime that is passed, it would appear
> to be associated with such values, which are processed thus:
>
> elif typeName == 'datetime':
>
> Where does the value of typeName come from?
>
> It is the descriptor of the MySQL type.
>
> print "<input type='text' width='%s' maxlength='%s'
> name='%s' value='%s' /> " \
> "<i>This field takes a datetime up to %s alphanumeric
> characters inclusive.</i>" \
> % (shortNum, str(typeNum), colName, theVal, str(typeNum))
>
> colName == 'LastDatePrice'
> typeNum = 10
>
> elif 10 < int(typeNum) < 20:
>
> If typeNum is 10 then 10 < int(typeNum) < 20 is False.
>
> Thank you for catching that! However, the code is followed by an else
> clause.
>
> shortNum = '10'
>
> Therefore...
> shortNum = '10'
>
> if whatDo == 'insert':
> theVal = defaultVal
> val = defaultVal
>
> What's the difference between theVal and val? The names don't help me!
> :-)
>
> if whatDo == 'insert':
> theVal = defaultVal
> val = defaultVal
> else:
> theVal = val
>
> Since whatDo == 'insert'...
> and
> val = 'yyyy/mm/dd'
> therefore
> theVal = None
>
[snip]
>
> If in fact the problem has to do with the None value, how can I
> easily substitute a different value? I tried:
>
> if theVal == None:
>
> The Pythonic way is to use "is" when comparing with singletons like
>
> None.
>
>
> Can you please explain by example?
>
Singleton: there is only ever one of certain objects and using "is" lets
you check for identity. For example, consider identical twins; they look
the same, but are not the same person. In programming terms you could
imagine the following scenario:

>>> print first_twin == second_twin
True
>>> print first_twin is second_twin
False

In Python by far the most common singleton is None; you should use "is"
(or "is not") when checking whether (or not) an object is actually None.
There might also be a few cases where a certain implementation of Python
might use singletons for reasons of efficiency, but they are just
optimisations in that implementation and shouldn't be relied on. The
rule is: if you're not checking for identity (and, as I said, by far the
most common use is with None), check for equality.

>
> theVal = ''
>
> but that didn't capture it.
>
> What do you mean by "didn't capture it"?
>
> The output was identical to what I originally posted.

I recommend that you write messages and values to a log file along the
path in the code you think it's following and then see whether it's
doing what you think it is and with the values you think it should have.