Question

I am generating mysql table schemas using information from another mysql table. Below is the python code that prints for an 'enum' mysql data type.

print '\t`%s` %s(\'%s\') COLLATE utf8_unicode_ci NOT NULL,' % (mysql_field_name, mysql_data_type, '\',\''.join(mysql_field_values.split(',')))

I need an enum field with % and $ as the values. I cannot seem to print the dollar sign in my output.

This is what prints:

`promotion_type` enum('','%') COLLATE utf8_unicode_ci NOT NULL,

This is what I want it to print:

`promotion_type` enum('$','%') COLLATE utf8_unicode_ci NOT NULL,

What do I have to change to make the dollar sign print?

Was it helpful?

Solution

mysql_field_name = "promotion_type"
mysql_data_type = "enum"
mysql_field_values = "$,%"
print '\t`%s` %s(\'%s\') COLLATE utf8_unicode_ci NOT NULL,' % (mysql_field_name, mysql_data_type, '\',\''.join(mysql_field_values.split(',')))

`promotion_type` enum('$','%') COLLATE utf8_unicode_ci NOT NULL,

Check your variables to see if they are ok, because the print works without any problem.

My Python version:

Python 2.7.5 (default, Aug 25 2013, 00:04:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top