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

how to pass a function value to another function...?related to kind of error

P: 3
in this when i am trying to pass the value of new_proj()that is y to the function translate..where test_file=new_proj() its not pass the address to it ...pls tell me the way how to pass it..thanks for the help


Expand|Select|Wrap|Line Numbers
  1. def new_proj():
  2.     x= (r"C:\Documents and Settings\KSR\Desktop\%s")%name_entry.get() 
  3.     if not os.path.exists(x): os.makedirs(x)
  4.     shutil.copy2('C:\Documents and Settings\KSR\Desktop\god.cmd',x)
  5.     y = x+'\god.cmd'
  6.     print x
  7.     return y
  8.  
  9.     def replace_words(text, word_dic):
  10.         rc = re.compile('|'.join(map(re.escape, word_dic)))
  11.         def translate(match):
  12.             return word_dic[match.group(0)]
  13.             return rc.sub(translate, text)
  14.  
  15.             test_file = new_proj()
  16.  
  17.             fin = open(test_file, "r")
  18.             str2 = fin.read()
  19.             fin.close()
  20.  
  21.             word_dic = {
  22.                         'virtex1': 'virtex5',
  23.                         'ff676': 'jhjak'}
  24.  
  25.             str3 = replace_words(str2, word_dic)
  26.  
  27.             fout = open(test_file, "w")
  28.             fout.write(str3)
  29.             fout.close()     
Mar 28 '13 #1
Share this Question
Share on Google+
5 Replies

Rabbit
Expert Mod 10K+
P: 12,441
Your function definitions need to be on the same indentation level. Also, no code is going to run because it consists only of function definitions.
Mar 28 '13 #2

P: 3
sir can be more specific ...lyk by doing the edit where i need to make....coz i am facing the problem from a long tym....i am kind of new to programmng nd confusing me a lot...
Mar 30 '13 #3

Rabbit
Expert Mod 10K+
P: 12,441
Python relies heavily on leading white space. I would review the those rules. But in essence the problem is this:

This is wrong.
Expand|Select|Wrap|Line Numbers
  1. def someFunction():
  2.    do something
  3.  
  4.    def otherFunction():
  5.       do something else
  6.  
This is right.
Expand|Select|Wrap|Line Numbers
  1. def someFunction():
  2.    do something
  3.  
  4. def otherFunction():
  5.    do something else
  6.  
Mar 31 '13 #4

P: 3
its never been the issue but can you tell me how to pass the value of function new_proj....Y to the other function ....the test_file....or with some similar example ....that will be gr8
Apr 2 '13 #5

Rabbit
Expert Mod 10K+
P: 12,441
First you need to fix your white space issues per my original response.
Apr 2 '13 #6

Post your reply

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