반응형
출력에서 개행을 수행하는 방법
\n
실제로 출력에서 어떻게 작동합니까? 현재는 단지 하나의 긴 블록으로 모든 것을 씁니다. 도움을 주셔서 감사합니다
Dir.chdir 'C:/Users/name/Music'
music = Dir['C:/Users/name/Music/*.{mp3, MP3}']
puts 'what would you like to call the playlist?'
@new = ''
playlist_name = gets.chomp + '.m3u'
music.each do |z|
@new += z + '\n'
end
File.open playlist_name, 'w' do |f|
f.write @new
end
"\n"
대신 사용'\n'
File.open 블록에서이 작업을 모두 수행 할 수 있습니다.
Dir.chdir 'C:/Users/name/Music'
music = Dir['C:/Users/name/Music/*.{mp3, MP3}']
puts 'what would you like to call the playlist?'
playlist_name = gets.chomp + '.m3u'
File.open playlist_name, 'w' do |f|
music.each do |z|
f.puts z
end
end
실제로는 블록이 필요하지 않습니다.
Dir.chdir 'C:/Users/name/Music'
music = Dir['C:/Users/name/Music/*.{mp3, MP3}']
puts 'what would you like to call the playlist?'
playlist_name = gets.chomp + '.m3u'
File.open(playlist_name, 'w').puts(music)
나는 내 경험을 공유하고 싶습니다 \n
내가 통지 나니 "\ n"시스 - 작동
puts "\n\n" // to provide 2 new lines
하지만
p "\n\n"
또한두고 '\n\n'
합니까하지 작동합니다.
희망은 당신을 위해 일할 것입니다!
참고 URL : https://stackoverflow.com/questions/2060253/how-to-do-a-newline-in-output
반응형
'programing tip' 카테고리의 다른 글
다양한 언어로 코드의 구문 강조를 수행하는 LaTeX 패키지 (0) | 2020.06.03 |
---|---|
장고 휴식 프레임 워크, 동일한 ModelViewSet에서 다른 직렬 변환기 사용 (0) | 2020.06.03 |
Node.js UnhandledPromiseRejectionWarning에서 처리되지 않은 약속을 찾는 방법은 무엇입니까? (0) | 2020.06.03 |
jQuery는 요소 내에서 마우스 위치를 얻는다 (0) | 2020.06.03 |
파이썬 스레딩에서 join () 사용은 무엇입니까 (0) | 2020.06.03 |