Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 吉他标签到uke标签程序帮助_Python_File - Fatal编程技术网

Python 吉他标签到uke标签程序帮助

Python 吉他标签到uke标签程序帮助,python,file,Python,File,所以我做了这个程序,它用一个吉他标签,获取fret编号,然后通过一个字典运行它,这个字典获取音符,然后在uke音符字典中搜索它 但我的问题是,如果我在txt文件中有一个选项卡,例如: |-----11----------11----------11------11--13--11----------11----------11----------11------11--13--11---------------| |-------13----------13----------13-------

所以我做了这个程序,它用一个吉他标签,获取fret编号,然后通过一个字典运行它,这个字典获取音符,然后在uke音符字典中搜索它

但我的问题是,如果我在txt文件中有一个选项卡,例如:

|-----11----------11----------11------11--13--11----------11----------11----------11------11--13--11---------------|
|-------13----------13----------13--------------------------13----------13----------13-----------------------------|
|--13-----13---13-----13---12-----12---------------12-13------13---13-----13---12-----12--------------------------|
|------------------------------------------------------------------------------------------------------------------|
|------------------------------------------------------------------------------------------------------------------|
|------------------------------------------------------------------------------------------------------------------|
所以我想要的是打开txt文件,在每一个与行相连的数字前面放一个字母。所以第一行上的每个数字都会说“e”,第二行说“B”,第三行说“G”

把它整理好,这样最终的结果会是:G13 e11 B13 G13等。。。
有什么想法吗?

对于解析,请编写一个函数,该函数包含一行制表符和一个注释,并根据位置生成FRET:

import re

def parse_line(line, note):
    fret_pattern = re.compile(r'\d+')
    for match in fret_pattern.finditer(line):
        yield (match.start(), ''.join((note, match.group(0))))
对于第一行--11--,这将产生
(6,“e11”)
。元组可用于以后对所有字符串上的所有注释进行排序

现在只需
open()
文件,读入前6行并给它们正确的名称:

import itertools

notes = ['e', 'B', 'G', 'D', 'A', 'E']
with open('tab.txt') as fp:
    # Read-in 6 lines
    lines = itertools.islice(fp, 0, 6)

    # Holds all the notes.
    frets = []

    # Process the lines, append all notes to frets.
    for note, line in itertools.izip(notes, lines):
       frets.extend(parse_line(line, note))

    # Sort the frets by position.
    frets.sort()

    # Drop the positions.
    frets = [fret for pos, fret in frets]

这应该是你想要的。但是很晚了

tablines  = '''|------11----------11----------11------11--13--11----------11----------11----------11------11--13--11--------------|
|-------13----------13----------13--------------------------13----------13----------13-----------------------------|
|--13-----13---13-----13---12-----12---------------12-13------13---13-----13---12-----12---------------------------|
|-----------------7------------------------------------------------------------------------------------------------|
|------9----------7------------------------------------------------------------------------------------------------|
|-----------------7------------------------------------------------------------------------------------------------|'''

# this will rotate them sideways, so you can compare them.
tabs = zip(*[list(l) for l in tablines.split("\n")][::-1])

ot = []
tl = len(tabs)
i = 1;
strings = 'eadgbe'
while i + 1 < tl:
    chord = []
    for j in range(6):
       # Because we need to care very strictly about order, we need to look 
       # through each point on the set of lines individually.
       dt = tabs[i][j] + tabs[i+1][j]
       if dt.isdigit():
           # both are digits, that means this is a chord.
           chord.append(strings[j] + dt)
       elif tabs[i-1][j] == '-' and tabs[i][j].isdigit():
           chord.append(strings[j] + tabs[i][j])
    if chord: # a chord has been found
       # tuples used because there the distinct possibility of two chords at once
       ot.append(tuple(chord))
    i+=1

print ot
tablines='''.----11----11----11----13----11----11----11----11----11----11----13----11--------------|
|-------13----------13----------13--------------------------13----------13----------13-----------------------------|
|--13-----13---13-----13---12-----12---------------12-13------13---13-----13---12-----12---------------------------|
|-----------------7------------------------------------------------------------------------------------------------|
|------9----------7------------------------------------------------------------------------------------------------|
|-----------------7------------------------------------------------------------------------------------------------|'''
#这将使它们侧向旋转,以便进行比较。
tabs=zip(*[列表(l)表示表格中的l。拆分(“\n”)][::-1])
ot=[]
tl=长度(制表符)
i=1;
字符串='eadgbe'
而i+1
结果是:

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,('b13',),('g13',),('g12',),('e11',),('b13',),('g12',),('e11',),('e13',),('e11',),('e11',)]


对我来说,仅仅两个音符就毁了它,但还是要谢谢你way@P“是的,我累了。我现在修好了。