Advertisement

07.13.2008 at 10:17PM PDT, ID: 23561733
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.5

Copy text to new files with counter and text insertion - Python

Asked by mgjust in Python Scripting Language

Hello,
Below I copied a text file (.gmd extension). I would like to copy the text with some insertions and save each file as .gmd with the a number included in the name of the .gmd that corresponds to the number being inserted.

First the numbers need to change in these two lines:
....
NAME OF INITIAL LANDUSE IMAGE           :    gr_lc_01b_075_fp
SUITABILITY IMAGE FOR SIMULATION 1      :    c2_mce_075

These should change together: gr_lc_01b_XXX_fp & c2_mce_XXX  (XXX goes from 075 - 407)
....

RGNVAL          REGION NAME    # CELLS      BEGIN        END      BEGIN        END
     1             Region 1     294276     152838     140000      78439      91277

Each of these 5 numbers will be different for each iteration from 074-407. I have them right now in an excel &/or text file.  Please advise how to incorporate this into the script.
.....

NAME OF OUTPUT LANDUSE IMAGE            :    delete_test

I would like the output name to be updated with the number from the iteration (075-407, e.g. output_075)

.....

Thank you kindly,
I really appreciate annotated code so that I might one day now how to do this myself, I have used the code below but I get this error message:

C:\Documents and Settings\u4cncmgj>C:\python24\python C:\temp\temp2\geomod_test.py
Traceback (most recent call last):
  File "C:\temp\temp2\geomod_test.py", line 29, in ?
    cells = open("c:\temp\temp2\spreadsheet.csv")
IOError: [Errno 2] No such file or directory: 'c:\temp\temp2\\spreadsheet.csv'

Should this code work (will it insert one line per .gmd file and go down the list in the .csv? And why do I get this error message?

Cheers,
MJ



text that needs to be copied and or updated starts immediately below:

***************************************************************
* THIS FILE CONTAINS THE VALUES OF THE PARAMETERS REQUIRED    *
* FOR THE GEOMOD MODULE, WHICH AUTOMATICALLY IS GENERATED IN  *
* IDRISI. STRONGLY RECOMMEND REEDITING IN IDRISI IF NECESSARY.*
***************************************************************

TIME TO BEGIN GEOMOD, INCLUSIVE         :    2001
TIME TO END GEOMOD, INCLUSIVE           :    2016
TIME STEP IN TIME UNITS                 :    1

# NEIGHBORS AWAY TO SEARCH,0=NO NIBBLE  :    1
WRITE DEBUG OUTPUT TO LOG FILE,YES=1    :    0
NAME OF STRATA/MASK IMAGE               :    N/A
NAME OF INITIAL LANDUSE IMAGE           :    gr_lc_01b_075_fp
DO ENVIR. IMPACT ANALYSIS? 1=YES, 0=NO  :    0
CMP/READ SUITABILITY SCORES(0=CP,1=RD)  :    1
NUMBER OF RUNS ONCE                     :    1
SUITABILITY IMAGE FOR SIMULATION 1      :    c2_mce_075
DO VALIDATION ANALYSIS? 1=YES, 0=NO     :    0
SINCE NO VALIDATION IMAGE, LANDUSE CHANGE INFO READ FROM FOLLOWS:
                                  LANDUSE STATE 1       LANDUSE STATE 2
RGNVAL          REGION NAME    # CELLS      BEGIN        END      BEGIN        END
     1             Region 1     294276     152838     140000      78439      91277

# OF TIMES OF OUTPUT BESIDE END TIME    :    0
NAME OF OUTPUT LANDUSE IMAGE            :    delete_testStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
data = """\
***************************************************************
* THIS FILE CONTAINS THE VALUES OF THE PARAMETERS REQUIRED    *
* FOR THE GEOMOD MODULE, WHICH AUTOMATICALLY IS GENERATED IN  *
* IDRISI. STRONGLY RECOMMEND REEDITING IN IDRISI IF NECESSARY.*
***************************************************************
 
TIME TO BEGIN GEOMOD, INCLUSIVE         :    2001
TIME TO END GEOMOD, INCLUSIVE           :    2016
TIME STEP IN TIME UNITS                 :    1
 
# NEIGHBORS AWAY TO SEARCH,0=NO NIBBLE  :    1
WRITE DEBUG OUTPUT TO LOG FILE,YES=1    :    0
NAME OF STRATA/MASK IMAGE               :    N/A
NAME OF INITIAL LANDUSE IMAGE           :    gr_lc_01b_%03d_fp
DO ENVIR. IMPACT ANALYSIS? 1=YES, 0=NO  :    0
CMP/READ SUITABILITY SCORES(0=CP,1=RD)  :    1
NUMBER OF RUNS ONCE                     :    1
SUITABILITY IMAGE FOR SIMULATION 1      :    c2_mce_%03d
DO VALIDATION ANALYSIS? 1=YES, 0=NO     :    0
SINCE NO VALIDATION IMAGE, LANDUSE CHANGE INFO READ FROM FOLLOWS:
                                  LANDUSE STATE 1       LANDUSE STATE 2
RGNVAL          REGION NAME    # CELLS      BEGIN        END      BEGIN        END
     1             Region 1    %s        %s     %s      %s      %s
 
# OF TIMES OF OUTPUT BESIDE END TIME    :    0
NAME OF OUTPUT LANDUSE IMAGE            :    %s
"""
cells = open("c:\temp\temp2\spreadsheet.csv")
 
for iter in range(75, 408):
  filename = "output_%03d.gmd" % iter
  out = open(filename, "w")
  cell = cells.readline().split(",")
print >>out, data % (iter, iter, cell[0], cell[1], cell[2], cell[3], cell[4], filename)
Attachments:
 
text file (cant upload spreadsheet.csv) of the numbers to be inserted.
 
[+][-]07.13.2008 at 10:59PM PDT, ID: 21995964

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.14.2008 at 01:12AM PDT, ID: 21996400

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.14.2008 at 01:31AM PDT, ID: 21996470

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.14.2008 at 08:44AM PDT, ID: 21999123

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 10:58AM PDT, ID: 22000383

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.14.2008 at 11:23AM PDT, ID: 22000608

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 11:44AM PDT, ID: 22000787

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.14.2008 at 12:07PM PDT, ID: 22000997

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Python Scripting Language
Sign Up Now!
Solution Provided By: pepr
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.15.2008 at 12:25PM PDT, ID: 22010138

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.17.2008 at 01:21PM PDT, ID: 22029831

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628