By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,985 Members | 1,574 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,985 IT Pros & Developers. It's quick & easy.

question about [0] in os module

P: 12
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 ?

Expand|Select|Wrap|Line Numbers
  1. import os
  2. import string
  3.  
  4. def replace(file, search_for, replace_with):
  5.     # replace strings in a text file
  6.  
  7.     back = os.path.splitext(file)[0] + ".bak"
  8.     temp = os.path.splitext(file)[0] + ".tmp"
  9.  
  10.     try:
  11.         # remove old temp file, if any
  12.         os.remove(temp)
  13.     except os.error:
  14.         pass
  15.  
  16.     fi = open(file)
  17.     fo = open(temp, "w")
  18.  
May 20 '11 #1
Share this Question
Share on Google+
1 Reply


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

Post your reply

Sign in to post your reply or Sign up for a free account.