ÆÄÀ̽ã ÆÄÀÏ Àбâ Áú¹®

   Á¶È¸ 5717   Ãßõ 0    

 파이썬으로 스크립트를 짜보고 있는 초보인데요,

nvt_00 부터 nvt_90 까지의 폴더들 안에 포함된, pr_nvt_00.mdp ~ 90번까지의 파일들을

반복문 for를 이용해서 수정하려고, 아래와 같이 파일을 읽게 하려고 했는데

        open_file = open("nvt_%02d/pr_nvt_%02d.mdp" % (temp_set.index(temp_option), temp_set.index(temp_option)), "r")

빨간색 부분을 추가 하니까 안되네요ㅠ. 어떤 방법이 있는지 여쭈어봅니다.

ªÀº±Û Àϼö·Ï ½ÅÁßÇÏ°Ô.
±èÁ¦¿¬ 2017-01
¤¾¤¨ ........ÆÄÀ̽ã ªÀº ¼Ò½º°¡ ÀåÁ¡À̱ä ÇÏÁö¸¸.. Á¦°¡ Ãʺ¸¶ó ±×·±Áö ¹«½¼ ÄÚµåÀÎÁö °¨µµ ¾È¿À³×¿ä.. ¤¾¤§¤§ .
½±°Ô ¹Ýº¹¹®À¸·Î µ¹·Á¼­ Çϼ¼¿ä...
     
³×ÀÌÃÄ 2017-01
¹Ýº¹¹®À¸·Î ´ÙÇߴµ¥¿ä...¸·È÷´Â ºÎºÐ¸¸ Àû¾îºÃ½À´Ï´Ù.

 open_file = open("pr_nvt.mdp", "r") ÀÌ·±½ÄÀ¸·Î ÆÄÀÏ À̸§À» ÁöÁ¤ÇÏ¸é µÇ´Âµ¥... ¿©·¯°³¸¦ ó¸®ÇØ º¸·Á°í À§¿¡ ó·³ ÇÏ´Ï±î ¾ÈµÇ³×¿ä ¤Ð
±èÁ¦¿¬ 2017-01
¾Æ ÀÌÁ¦º¸´Ï %02¿¡ °ª ³Ö¾îÁÖ´Â ¼Ò½º±º¿ä -_-;;

http://stackoverflow.com/questions/3484348/dynamic-filenames

ÂüÁ¶Çغ¸¼¼¿ä ´Ù¾çÇÑ ¹æ¹ýÀÌ Àֳ׿ä... Àú·± ¹æ¹ýÀÌ ½¬¿ì½Ã¸é ¸Ç À§¿¡..

for x in range(22): #Remember that the range function returns integers up to 22-1
    exec "f%02d = open('file%02d.txt', 'w')" % (x, x)

¿ä°í ¾²½Ã¸é µÉ°Í °°³×¿ä .. ¾ÈÂÊÀÌ ¾Æ´Ñ ¹Ù±ùÂÊ¿¡´Ù ³Ö´Â°Å³×¿ä..
     
³×ÀÌÃÄ 2017-01
¾Æ °¨»çÇÕ´Ï´Ù~ ´äº¯ÇØÁֽŠ°ÍÀ» Âü°í·Î °øºÎÇغ¸°Ú½À´Ï´Ù.

Ãʺ¸¶ó¼­ ¸çÄ¥µ¿¾È °Ü¿ì°Ü¿ì Á¶±Ý¾¿ ÇÏ°í ÀÖ½À´Ï´Ù ¤¾¤¾
ÀÌ°ÇÈñ 2017-01
³×ÀÌÃÄ´Ô ¿¹Àü ±Û¿¡µµ µ¡±Û ´Þ¾Æµå¸° ±â¾ïÀÌ Àֳ׿ä~
ÀÏ´Ü ÆÄÀ̽ãÀ¸·Î ÆÄÀÏÀ» ÀÐÀ¸·Á¸é os ¸ðµâ »ç¿ë¹ý °£·«ÇÏ°Ô ¾Ë¾ÆµÎ¼Å¾ß ÇÕ´Ï´Ù. ¸¹À̵µ ÇÊ¿ä¾ø°í ÀÚÁÖ¾²´Â°Í¸¸...

À̹ø ±Û¿¡¼­´Â ¹®ÀÚ¿­ Æ÷¸ÅÆÃÀ» À߸ø ÇϽŠ°Í °°½À´Ï´Ù. Æ÷¸ÅÆÃÀÌ ¹«¾ùÀÎÁö´Â ¾Æ½ÃÁÒ?

Áö±Ý ¹®¸ÆÀÌ ÀÌÇØ°¡ ¾È°¡´Âµ¥ ´õ ÀÚ¼¼È÷ Àû¾îÁÖ½Ç ¼ö ÀÖ³ª¿ä?
Àú±â¿¡ temp_set.index³ª temp_optionÀÌ À§¿¡¼­ defÇϽŰǰ¡...
     
³×ÀÌÃÄ 2017-01
³×³× °¨»çÇÕ´Ï´Ù. ¤¾¤¾
Á¦°¡ ÀÛ¼ºÇØ ³õÀºµ¥ ±îÁö ÀÔ´Ï´Ù.

import os
import shutil


temp_set = (300.00, 301.66, 303.33, 305.01, 306.69, 308.38, 310.08, 311.79, 313.51, 315.24, 316.97,
318.71, 320.46, 322.22, 323.97, 325.75, 327.53, 329.32, 331.12, 332.93, 334.74, 336.57, 338.40, 340.24, 342.09,
343.95, 345.82, 347.69, 349.58, 351.47, 353.37, 355.28, 357.20, 359.13, 361.04, 362.98, 364.94, 366.90, 368.88,
370.86, 372.85, 374.85, 376.86, 378.88, 380.91, 382.94, 384.99, 387.05, 389.12, 391.19, 393.28, 395.38, 397.48,
399.60, 401.73, 403.86, 406.01, 408.15, 410.31, 412.49, 414.68, 416.87, 419.08, 421.30, 423.53, 425.76, 428.01,
430.27, 432.54, 434.82, 437.11, 439.41, 441.72, 444.05, 446.38, 448.73, 451.08, 453.45, 455.82, 458.21, 460.61,
463.02, 465.45, 467.88, 470.33, 472.78, 475.25, 477.73, 480.22, 482.73, 485.24, 487.77, 490.30, 492.85, 495.42,
497.99, 500.57)



def make_folder():
    for folder in temp_set:
        os.mkdir("nvt_%02d" % temp_set.index(folder))
    print("%02d folders have been created!" % temp_set.index(folder))


def copy_files():
    for mdp_file in temp_set:
        shutil.copy("pr_nvt.mdp", "nvt_%02d/pr_nvt_%02d.mdp" % (temp_set.index(mdp_file), temp_set.index(mdp_file)))
    print("%02d files have been copied to the folders!" % temp_set.index(mdp_file))


def edit_contents():
    for temp_option in temp_set:
        open_file = open("nvt_%02d/pr_nvt_%02d.mdp" % (temp_set.index(temp_option), temp_set.index(temp_option)), "r")
        read_file = open_file.read()
        edit_file = read_file.replace("300.00", "%.2f" % temp_option)
        re_open_file = open("nvt_%02d/pr_nvt_%02d.mdp" % (temp_set.index(temp_option), temp_set.index(temp_option), "w")
        save_file = re_open_file.write(edit_file)




if __name__ == "__main__":
    make_folder()
    copy_files()
    edit_contents()
     
³×ÀÌÃÄ 2017-01
Æú´õ¸¸µå´Â°Å¶û ÆÄÀÏ º¹»çÇØ ³Ö±â´Â ¼º°øÇߴµ¥,
³»¿ë¼öÁ¤Çϴµ¥¼­ ¸·ÇôÀÖ½À´Ï´Ù.

µû·Î ÆÄÀÏ ¼öÁ¤Çϴ°Ÿ¸ ¸¸µé¾î¼­ Å×½ºÆ® ÇÒ¶§,  open_file = open("pr_nvt.mdp", "r") ÀÌ·¸°Ô ÆÄÀÏ ÇÑ°³¸¸ ÁöÁ¤ÇÒ ¶§´Â µÇ¾ù´Âµ¥
¿©·¯°³¸¦ ó¸®ÇÏ·Á°í ¹Ù²Ù´Ï±î ¸·Çû½À´Ï´Ù.
°¨»çÇÕ´Ï´Ù.
          
±èÁ¦¿¬ 2017-01
r·Î Çߴµ¥ ¼öÁ¤ÀÌ °¡´ÉÇß´Ù´Â ¸»¾¸À̼¼¿ä? ÀÌ»óÇѵ¥¿ä ..rÀÌ read only ¾Æ´Ñ°¡¿ä ..
¾Æ .. ¾²°íº¸´Ï .. Àú·±½ÄÀ¸·Î ÇÑ°³¸¸ ÁöÁ¤Çß´Ù´Â ¸»¾¸À̽ñº¿ä rÀº ÀÇ¹Ì ¾ø°í¿ä ..
               
³×ÀÌÃÄ 2017-01
w·Î ¿©´Ï±î ³»¿ëÀÌ ´Ù Áö¿öÁ®¼­¿ä..
 r·Î ¸ÕÀú ÀоîµéÀÎ ´ÙÀ½¿¡ º¯°æÇÏ°í, ±×´ÙÀ½ w·Î ¿©´Ï±î Àüü ³»¿ëÀÌ À¯Áö µÇ¸é¼­ ÇÊ¿äÇÑ ºÎºÐ¸¸ ¹Ù²¸¼­ ÀúÀåÀÌ µÇ±æ·¡
ÀÌ·¸°Ô Çسù½À´Ï´Ù.  Ãʺ¸¶ó¼­ Àß ¸ð¸£°Ù¾î¿ä ¤Ð ¤¾¤¾


QnA
Á¦¸ñPage 2189/5691
2015-12   1552632   ¹é¸Þ°¡
2014-05   5017233   Á¤ÀºÁØ1
2006-01   5718   ¿ìÁ¦Çõ
2006-02   5718   ¿ì¸íÈÆ
2018-07   5718   Àü¼³¼ÓÀǹ̡¦
2005-10   5718   ¹®Áö¼º
2005-05   5718   ÃÖ½ÂÇö
2011-09   5718   GoodWolf
2008-07   5718   ¹æÈ¿¹®
2008-12   5718   ÀÌ»óµ·
2014-04   5718   ȲÀ¯½Ä
2017-01   5718   ³×ÀÌÃÄ
2007-10   5718   ÀÓ½ÃÇö
2008-07   5718   ±èÅ°æ(ÀÎõ)
2022-03   5718   °ø¹é±â
2005-08   5718   ÀÌÀç¼·
2005-10   5718   ³ëÇϼ®
2011-10   5718   À̺´ÇÑ
2006-04   5718   ±è´ö±â
2005-07   5718   À̽¹Î
2013-01   5718   HEUo±è¿ë¹Î
2008-01   5718   Á¶¿µ¼ö