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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vishwasreddy
    New Member
    • Mar 2013
    • 3

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

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


    Code:
    def new_proj():
        x= (r"C:\Documents and Settings\KSR\Desktop\%s")%name_entry.get() 
        if not os.path.exists(x): os.makedirs(x)
        shutil.copy2('C:\Documents and Settings\KSR\Desktop\god.cmd',x)
        y = x+'\god.cmd'
        print x
        return y
    
        def replace_words(text, word_dic):
            rc = re.compile('|'.join(map(re.escape, word_dic)))
            def translate(match):
                return word_dic[match.group(0)]
                return rc.sub(translate, text)
    
                test_file = new_proj()
               
                fin = open(test_file, "r")
                str2 = fin.read()
                fin.close()
     
                word_dic = {
                            'virtex1': 'virtex5',
                            'ff676': 'jhjak'}
    
                str3 = replace_words(str2, word_dic)
    
                fout = open(test_file, "w")
                fout.write(str3)
                fout.close()
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    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.

    Comment

    • vishwasreddy
      New Member
      • Mar 2013
      • 3

      #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...

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Python relies heavily on leading white space. I would review the those rules. But in essence the problem is this:

        This is wrong.
        Code:
        def someFunction():
           do something
        
           def otherFunction():
              do something else
        This is right.
        Code:
        def someFunction():
           do something
        
        def otherFunction():
           do something else

        Comment

        • vishwasreddy
          New Member
          • Mar 2013
          • 3

          #5
          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

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            First you need to fix your white space issues per my original response.

            Comment

            Working...