Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8131651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:08:57+00:00 2026-06-06T09:08:57+00:00

I am writing some code that will go through a file, edit it as

  • 0

I am writing some code that will go through a file, edit it as a temp file, and than copy the temp file over the new file so as to make the edit. However when using the move method from shutil I keep getting this error :

IOError: [Errno 22] Invalid Argument

I’ve tried using copy, copy2, and copyfile. Here is a copy of the code :

def writePPS(seekValue,newData):
    PPSFiles = findPPS("/pps")
    for file in PPSFiles:
        #create a temp file
        holder,temp = mkstemp(".pps")
        print holder, temp
        pps = open(file,"r+")
        newpps = open(temp,"w")
        info = pps.readlines()
        #parse through the pps file and find seekvalue, replace with newdata
        for data in info:
            valueBoundry = data.find(":")
            if seekValue == data[0:(valueBoundry)]:
                print "writing new value"
                newValue = data[0:(valueBoundry+1)] + str(newData)
                #write to our temp file
                newpps.write(newValue)
            else: newpps.write(data)
        pps.close()
        close(holder)
        newpps.close()
        #remove original file
        remove(file)
        #move temp file to pps
        copy(temp,"/pps/ohm.pps")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T09:08:58+00:00Added an answer on June 6, 2026 at 9:08 am

    I am not exactly sure why you are getting that error, but to start you could try cleaning up your code a bit and fixing all those import statements. Its hard to see where the functions are coming from and for all you know you could have a namespace collision eventually.

    Lets start here with some actually runnable code:

    import shutil
    import os
    import tempfile
    
    def writePPS(seekValue,newData):
        PPSFiles = findPPS("/pps")
        for file_ in PPSFiles:
            #create a temp file
            newpps = tempfile.NamedTemporaryFile(suffix=".pps")
            print newpps.name
            with open(file_,"r+") as pps:
                #parse through the pps file and find seekvalue, replace with newdata
                for data in pps:
                    valueBoundry = data.find(":")
                    if seekValue == data[0:(valueBoundry)]:
                        print "writing new value"
                        newValue = data[0:(valueBoundry+1)] + str(newData)
                        #write to our temp file
                        newpps.write(newValue)
                    else: 
                        newpps.write(data)
    
                #move temp file to pps
                newpps.flush()
                shutil.copy(newpps.name,"/pps/ohm.pps")
    

    You don’t need to read all your lines into memory. You can just loop over each line. You also don’t need to manage all those open/close file operations. Just use a with context and also a NamedTemporaryFile which will clean itself up when it is garbage collected.

    Important note, that in your example and above, you are overwriting the same destination file each time for every source file. I left it that way for you to address. But if you start here, we can then begin to figure out why you are getting errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am writing some code in vb.net that will be generating a pdf file.
I'm writing some code that will serialize a C# object to JSON, send it
I'm writing some code (just for fun so far) in Python that will store
I'm writing some serialization/deserialization code in Python that will read/write an inheritance hierarchy from
What are the current rules for writing python code that will pass cleanly through
I am currently writing some code that can access a separate workbook through an
I'm writing some logging/auditing code that will be running in production (not just when
I am writing some code generation templates that will work hand-in-hand with a SubSonic
I'm writing some code that will take a screenshot of another application, given its'
I'm writing some optimized C code that basically runs through an array and does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.