Strange Problem
Dave Angel
davea at ieee.org
Tue Dec 22 17:14:46 EST 2009
Victor Subervi wrote:
> Hi;
> I have the following code:
>
> print 'printTheForm: ', descrProds, '<br />'
> for value in descrProds:
> print 'value: ', value, '<br />'
>
> which prints this:
>
> 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]
>
> You'll notice that the first print statement prints out several tuples that
> don't get printed out in the last statement (they're truncated). Why?
> TIA,
> beno
>
>
As Emile points out, you're clearly doing some other processing between
that print and the place you're capturing the output. Presumably this
is a CGI script or equivalent. So several other layers of code are
manipulating that stream before you see it.
Have you added another print immediately after the loop, so you can tell
that it ended, and that subsequent output is separated from it? My
first guess was that you have some character in there that's special to
html, such as "<", but I don't see such. In general, you might need to
escape your data (using & escape sequences), rather than just printing
it directly to the CGI stream.
Another clue for this type of problem is to look at the "page source" in
your browser, rather than trust its rendering. Sometimes the rendering
gets messed up, especially if the html is not strictly legal.
In Firefox, use "View -> Page Source" to see the source to the page,
which should come pretty close to the output of your print statements.
My preference would be to run the script outside of the web-server
environment, either on a local copy, or by shelling into your server.
DaveA
More information about the Python-list
mailing list