2016-10-02 2 views
0

기본적으로 나는 https://en.wikipedia.org/wiki/List_of_lists_of_lists의 목록을 내 클립 보드에 복사하고 있습니다. 프로그램을 실행하면 각 행의 앞이나 뒤에 글 머리 기호가 추가됩니다. 예를 들어(Python) 클립 보드에서 문자열을 수정하는 것에 대한 도움

: 등

•• Lists of Iranian films •• 

그리고 :

Lists of Iranian films 

가로 변환겠습니까. 이 프로그램은 줄 앞에 글 머리 기호를 추가 할 때 작동하지만, 뒤 따르면 줄 바꿈 문자없이 긴 문자열 하나만 인쇄합니다. 아무도 내가 뭘 잘못하고 있다고 말할 수 있습니까?

List of Israeli films before 1960 
List of Israeli films of the 1960s 
List of Israeli films of the 1970s 
List of Israeli films of the 1980s 

클립 보드 메모장에 붙여 : 내 클립 보드에

#bulletPointAdder.py - Adds Wikipedia bullet points to the start and end 
#of each line of text on the clipboard 

import pyperclip 
text=pyperclip.paste()  #paste a big string of text from clipboard into the 'text' string 


# Separate lines and add stars 
lines = text.split('\n')  #'lines' contains a list of all the individual lines up until '\n' 
          #lines= ['list of iserael films', 'list of italian films' ...] 

for i in range(len(lines)):   #loop through all indexes in the "lines" list 
    lines[i] = '••' + lines[i] + '••' #add bullets before and after each line 

text = '\n'.join(lines)   #put a '\n' in between the list members (joins them) into a single string 
pyperclip.copy(text) 

: 여기

코드의

••List of Israeli films before 1960••••List of Israeli films of the 1960s••••List of Israeli films of the 1970s••••List of Israeli films of the 1980s•• 
+0

무엇이 질문입니까? '텍스트'의 종류는 무엇입니까? 'str' 요소의'list'입니까? – blacksite

+0

죄송합니다. 유형은 클립 보드에 복사 된 문자열입니다. – tadm123

답변

1

이 당신의 코드를 약간 변경 (대신 os.linesep를 사용 '\n') :

DOS/윈도우
  • CR에

    • CR의 LF에을 : 일반적으로3210
      import os 
      import pyperclip 
      text=pyperclip.paste()  
                #paste will paste a big string of text in 'text' string 
      
      # Separate lines and add stars 
      lines = text.split(os.linesep)  #lines contains a list of all the individual lines up cut before newline 
                #lines= ['list of iserael films', 'list of italian films' ...] 
      
      for i in range(len(lines)):   #loop through all indexes in the "lines" list 
          lines[i] = '••' + lines[i] + '••' #add bullets before and after each line 
      
      text = os.linesep.join(lines)   #put a newline in between the list members (joins them) into a single string 
      pyperclip.copy(text) 
      

      는 "새로운 라인"을 포함 할 수 일반적으로 새로운 라인을 신호로 해석됩니다 문자의 집합을 말한다 유닉스에서 오래된 맥

    • LF는 일반적으로 \ 연구로 표현 캐리지 리턴 ASCII 문자 (코드 0x0d로), 현대 맥

    CR되어 포함, 변종입니다. LF는 줄 바꿈 문자 (코드 0x0A)이며 일반적으로 \ n으로 표시됩니다.

    또한

    이 읽기 ​​:

    https://blog.codinghorror.com/the-great-newline-schism/ 난 그냥 당신이 멀티 플랫폼 솔루션을 쓰고 싶었다. 따라서 os.linesep

  • +0

    고마워요 ..이게 효과가 있어요. 내가 뭘 잘못하고 있었는지 말해 줄 수 있니? '\ n'문자로는 작동하지 않는다는 것이 매우 이상합니다. – tadm123

    +0

    나는 다시 .. 고마워. – tadm123

    관련 문제