question about [0] in os module

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PyGIS
    New Member
    • Feb 2011
    • 12

    question about [0] in os module

    Hi friends:

    i'm beginner in python . i have a question . what does [0] mean in the below code and when should i use [0] in codes ?

    Code:
    import os
    import string
    
    def replace(file, search_for, replace_with):
        # replace strings in a text file
    
        back = os.path.splitext(file)[B][0][/B] + ".bak"
        temp = os.path.splitext(file)[B][0][/B] + ".tmp"
    
        try:
            # remove old temp file, if any
            os.remove(temp)
        except os.error:
            pass
    
        fi = open(file)
        fo = open(temp, "w")
  • Mc1brew
    New Member
    • Feb 2010
    • 4

    #2
    Not knowing Python... My guess would be SplitText returns an array, and [0] indicates that it should return the first element (indexing from 0)...

    Comment

    Working...