c#“$”运算符在窗口7中不起作用

时间:2017-05-27 12:05:10

标签: c# visual-studio-2013

我有一个代码来附加我的键值

import re
import xml.etree.ElementTree as ET

def word_ngrams(frogged_xmlfile, unigrams=True, bigrams=True, trigrams=True):
    vector = {}
    tree = ET.parse(frogged_xmlfile) #enter the xml tree
    root = tree.getroot()
    tokens = []
    words = []
    regex = re.compile(r'[^0-9] |[^(\.|\,|\?|\:|\;|\!)]')
        for node in root.iter('w'):
        for w in node.findall('t'):
            tokens.append(w.text)
    for word in tokens:
        if regex.search(word):
            words.append(word)
    if (unigrams):
        for n in [1]: #unigrams
            grams = ngrams(words, n)
            fdist = FreqDist(grams)
            total = sum(c for g,c in fdist.items())
        for gram, count in fdist.items():
            vector['w'+str(n)+'+'+' '.join(gram)] = count/total

    if (bigrams):
        for n in [2]: #bigrams
            grams = ngrams(tokens, n)
            fdist = FreqDist(grams)
            total = sum(c for g,c in fdist.items())
        for gram, count in fdist.items():
            vector['w'+str(n)+'+'+' '.join(gram)] = count/total

    if (trigrams):
        for n in [3]: #trigrams
            grams = ngrams(tokens, n)
            fdist = FreqDist(grams)
            total = sum(c for g,c in fdist.items())
        for gram, count in fdist.items():
            vector['w'+str(n)+'+'+' '.join(gram)] = count/total
    return vector
print(word_ngrams('romanfragment_frogged.xml', unigrams = True, bigrams = False, trigrams = False))

这段代码在窗口10中使用框架4.5.2和vs2017,但我将此代码复制到具有相同框架工作的窗口7,但不同的VS,即2013年,它返回错误

  

意外字符'$'

我不知道是什么问题,是VS版本问题吗?在VS2013中重现此代码的最佳方法是什么?

1 个答案:

答案 0 :(得分:5)

添加字符串插值功能的C#6于2015年发布。编辑器支持未针对旧版本进行后端移植。这与.NET Framework或操作系统版本无关。

使用字符串连接可以实现相同的功能:

strData += "&" + d.Key + "=" + d.Value;