尝试打印Unicode代码点表

时间:2018-08-06 00:22:49

标签: javascript unicode

我正在尝试制作一个unicode代码点表,该表将打印代码点直到import os, time, sys from bokeh.layouts import widgetbox from bokeh.models.widgets import RadioButtonGroup, Button, TextInput from bokeh.models.widgets.inputs import MultiSelect from bokeh.models.widgets import AutocompleteInput from bokeh.models.callbacks import CustomJS from bokeh.io import output_notebook, show from bokeh.models import ColumnDataSource from bokeh.models.widgets.markups import Div from bokeh.resources import INLINE output_notebook(resources=INLINE) ipies=[str(i.strip('.ipynb')) for i in os.listdir() if i.endswith('.ipynb')] minutes=0 hours=0 days=0 months=0 daysmonth=0 days=0 minute_options=[str(i) for i in range(1,60)] minute_options.append("*") minute_callback = CustomJS(args=dict(a=minute_options), code=""" var options=a; console.log(options[parseInt(cb_obj.active)]); var ind=options[parseInt(cb_obj.active)]; IPython.notebook.kernel.execute('minutes='+ind+''); """) minute_rbg = RadioButtonGroup( labels=minute_options, callback=minute_callback, active=len(minute_options)-1) min_title=Div(text="Which minute on the hour, * for every minute") hour_options=[str(i) for i in range(24)] hour_options.append("*") hour_callback = CustomJS(args=dict(a=hour_options), code=""" var options=a; console.log(options[parseInt(cb_obj.active)]); var ind=options[parseInt(cb_obj.active)]; IPython.notebook.kernel.execute('hours='+ind+''); """) hour_rbg = RadioButtonGroup( labels=hour_options,callback=hour_callback,active=len(hour_options)-1) hour_title=Div(text="Which hour in a day, * for every hour") day_month_options=[str(i) for i in range(1,32)] day_month_options.append("*") day_month_callback = CustomJS(args=dict(a=day_month_options), code=""" var options=a; console.log(options[parseInt(cb_obj.active)]); var ind=options[parseInt(cb_obj.active)]; IPython.notebook.kernel.execute('daysmonth='+ind+''); """) day_month_rbg = RadioButtonGroup( labels=day_month_options,callback=day_month_callback,active=len(day_month_options)-1) day_month_title=Div(text="Which day in a month, * for every day of the month") month_options=[str(i) for i in range(1,13)] month_options.append("*") month_callback = CustomJS(args=dict(a=month_options), code=""" var options=a; console.log(options[parseInt(cb_obj.active)]); var ind=options[parseInt(cb_obj.active)]; IPython.notebook.kernel.execute('months='+ind+''); """) month_rbg = RadioButtonGroup( labels=month_options, callback=month_callback,active=len(month_options)-1) month_title=Div(text="Which month in a year, * for every month") day_week_options=[str(i) for i in range(7)] day_week_options.append("*") day_week_callback = CustomJS(args=dict(a=day_week_options), code=""" var options=a; console.log(options[parseInt(cb_obj.active)]); var ind=options[parseInt(cb_obj.active)]; IPython.notebook.kernel.execute('days='+ind+''); """) day_week_rbg = RadioButtonGroup( labels=day_week_options, callback=day_week_callback, active=len(day_week_options)-1) days_week_title=Div(text="Which day in a week, * for every day of the week") import pandas as pd ipies_pd = pd.DataFrame({"a":ipies}) #Selection source: IPIES CDS cds = ColumnDataSource(data=ipies_pd) #Selection source: autocompleteinput & multiselect widgets selection_callback = CustomJS(args=dict(source=cds), code=""" // THIS CALLBACK ONLY BRINGS BACK SELECTIONS IF THEY ARE INTEGERS var cbobj = cb_obj.value; IPython.notebook.kernel.execute("auto_c_value = "\"+ cbobj + "\"); """) ms = MultiSelect(title="power", callback=selection_callback, options=ipies) auto_c=AutocompleteInput(completions=ipies, height=100, callback=selection_callback) button_callback = CustomJS(code=""" var cur_index = IPython.notebook.get_selected_index()+1; var end_index=IPython.notebook.ncells(); IPython.notebook.execute_cell_range(IPython.notebook.get_selected_index()+1, IPython.notebook.ncells()); """) button = Button(label="button~!", button_type="primary", callback=button_callback) w_box = widgetbox(min_title, minute_rbg, hour_title, hour_rbg, day_month_title, day_month_rbg, month_title, month_rbg,days_week_title, day_week_rbg, button, ms, auto_c, width=800, sizing_mode='scale_both') show(w_box)

我将数字更改为十六进制,然后将其与Unicode转义序列连接起来。

当我尝试用U+300连接十六进制数时,出现错误'\u'

这里是 the code

如何解决该错误?

2 个答案:

答案 0 :(得分:1)

代替此:

print(num + ' => ' + '\u' + num);

使用此:

print(num + ' => ' + '\\u' + num);

或更简洁地说,

print(num + ' => \\u' + num);

您需要转义\本身,以将其包括在字符串文字中。

答案 1 :(得分:1)

将打印语句更改为print(num + ' => ' + String.fromCharCode("0x" + num));