subscript

Python: subscript a module

痞子三分冷 提交于 2019-11-27 08:14:36
问题 I was trying to do something like this: module.py def __getitem__(item): return str(item) + 'Python' test.py import module print module['Monty'] I expected "MontyPython" to be printed. However, this doesn't work: TypeError: 'module' object is not subscriptable Is it possible to create a subscriptable module in pure Python (i.e. without modifying its source code, monkey-patching, etc.)? 回答1: >>> class ModModule(object): def __init__(self, globals): self.__dict__ = globals import sys sys

Ambiguous Use of Subscript in Swift

天大地大妈咪最大 提交于 2019-11-27 03:45:23
问题 I keep getting an error of "ambiguous use of subscript," in my Swift code. I don't know what's causing this error. It just randomly popped up. Here's my code: if let path = NSBundle.mainBundle().pathForResource("MusicQuestions", ofType: "plist") { myQuestionsArray = NSArray(contentsOfFile: path) } var count:Int = 1 let currentQuestionDict = myQuestionsArray!.objectAtIndex(count) if let button1Title = currentQuestionDict["choice1"] as? String { button1.setTitle("\(button1Title)", forState:

How to create vertically aligned superscript and subscript in TextView

旧时模样 提交于 2019-11-27 01:38:12
问题 In the example of image below: How can I make both the superscript and subscript numbers to be aligned to produce a common scientific notation like below in TextView ? If there is a way using Spannable or ReplacementSpan I would like to see a working example. Thank you. 回答1: You might want to try something like this. It's basicall a ReplacementSpan that takes the text it's applied on, separates it into two parts, and draws them on the canvas. The size factor and y translation are somewhat

Python slice first and last element in list

北慕城南 提交于 2019-11-27 00:49:53
问题 Is there a way to slice only the first and last item in a list? For example; If this is my list: >>> some_list ['1', 'B', '3', 'D', '5', 'F'] I want to do this (obviously [0,-1] is not valid syntax): >>> first_item, last_item = some_list[0,-1] >>> print first_item '1' >>> print last_item 'F' Some things I have tried: In [3]: some_list[::-1] Out[3]: ['F', '5', 'D', '3', 'B', '1'] In [4]: some_list[-1:1:-1] Out[4]: ['F', '5', 'D', '3'] In [5]: some_list[0:-1:-1] Out[5]: [] ... 回答1: One way:

How to find the unicode of the subscript alphabet?

回眸只為那壹抹淺笑 提交于 2019-11-27 00:22:14
I've found some letters but i need to find others such as "c", "m", "p", is this even possible? Take a look at the wikipedia article Unicode subscripts and superscripts . It looks like these are spread out across different ranges, and not all characters are available. Consolidated for cut-and-pasting purposes, the Unicode standard defines complete sub- and super-scripts for numbers and common mathematical symbols ( ⁰ ¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹ ⁺ ⁻ ⁼ ⁽ ⁾ ₀ ₁ ₂ ₃ ₄ ₅ ₆ ₇ ₈ ₉ ₊ ₋ ₌ ₍ ₎ ), a full superscript Latin lowercase alphabet except q ( ᵃ ᵇ ᶜ ᵈ ᵉ ᶠ ᵍ ʰ ⁱ ʲ ᵏ ˡ ᵐ ⁿ ᵒ ᵖ ʳ ˢ ᵗ ᵘ ᵛ ʷ ˣ ʸ ᶻ ), a limited

HTML <sup /> tag affecting line height, how to make it consistent?

不问归期 提交于 2019-11-26 23:55:10
问题 If I have a <sup> tag in a multi-line <p> tag, the line with the superscript on it has a larger line spacing above it than the other lines, irregardless of what line-height I put on the <p> . Edit for clarification : I don't mean i have lots of <p> s, each which is on a single line. I have a single <p> with enough content in it to cause wrapping onto multiple lines. Somewhere (anywhere) in the text there may be a <sup> or <sub> . This affects the line height for that line by adding extra

Set superscript and subscript in formatted text in wpf

瘦欲@ 提交于 2019-11-26 22:38:22
How can I set some text as subscript/superscript in FormattedText in WPF? You use Typography.Variants : <TextBlock> <Run>Normal Text</Run> <Run Typography.Variants="Superscript">Superscript Text</Run> <Run Typography.Variants="Subscript">Subscript Text</Run> </TextBlock> You can use something like <TextBlock>5x<Run BaselineAlignment="Superscript">4</Run> + 4</TextBlock> . However, as far as I know, you will have to reduce the font-size yourself. I used a layout transform, because Typography.Variants often doesn't work: <TextBlock Text="MyAmazingProduct"/> <TextBlock Text="TM"> <TextBlock

Char array subscript warning

与世无争的帅哥 提交于 2019-11-26 22:03:33
问题 when I use char array subscript as in this example: int main(){ char pos=0; int array[100]={}; for(pos=0;pos<100;pos++) printf("%i\n", array[pos]); return 0; } I am getting warning that I am using char array subscript: warning: array subscript has type ‘char’ [-Wchar-subscripts] Which is OK, because I have this warning enabled. GCC manual says: -Wchar-subscripts Warn if an array subscript has type "char". This is a common cause of error, as programmers often forget that this type is signed on

Subscripts in plots in R

无人久伴 提交于 2019-11-26 18:26:35
I can't find a way how to write subscripts in the title or the subtitle in R. How can I write v 1,2 with 1,2 as subscripts? Thanks for your help! smu expression is your friend: plot(1,1, main=expression('title'^2)) #superscript plot(1,1, main=expression('title'[2])) #subscript If you are looking to have multiple subscripts in one text then use the star(*) to separate the sections: plot(1:10, xlab=expression('hi'[5]*'there'[6]^8*'you'[2])) See ?expression plot(1:10,main=expression("This is a subscript "[2])) A subscript and referring to a stored value... a <- 10 plot(c(0,1), c(0,1), type = 'n',

Printing subscript in python

瘦欲@ 提交于 2019-11-26 16:18:57
问题 In Python 3.3, is there any way to make a part of text in a string subscript when printed? e.g. H₂ (H and then a subscript 2) 回答1: If all you care about are digits, you can use the str.maketrans() and str.translate() methods: >>> SUB = str.maketrans("0123456789", "₀₁₂₃₄₅₆₇₈₉") >>> SUP = str.maketrans("0123456789", "⁰¹²³⁴⁵⁶⁷⁸⁹") >>> "H2SO4".translate(SUB) 'H₂SO₄' Note that this won't work in Python 2 - see Python 2 maketrans() function doesn't work with Unicode for an explanation of why that's