简体   繁体   中英

print dollar sign in python

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM