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

  • Home
  • SEARCH
  • 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 8010501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:45:14+00:00 2026-06-04T18:45:14+00:00

newbie python programmer here. I have written a script and want to modify the

  • 0

newbie python programmer here. I have written a script and want to modify the start so that it runs through files in a folder, so I don’t have to change input and output file extensions each time.

The folder of input files contains chromosome files such as ‘chr1’, ‘chr2’, ‘chrx’ etc.
I want to output to a different folder and pathway and use the input files as the basis for the outputfile, while also adding an extension such as ‘windowstatistics’. For example then the input file ‘chr1’ would be output in a different folder as ‘chr1windowstatistics’.

I have been trying to solve this for a couple of days without getting a working solution.

Currently I have:

import os
import glob

path = '/man/genotyping/Conservation/splitbychrom/'
for infile in glob.glob( os.path.join(path, 'Chr*') ):


    inputfile = open(infile, 'r') 
    output = os.rename(inputfile + ".out", 'w')

Does anyone know how to get this working, I don’t mind if the way it is done is quite different, I just want to be able to run the script once and it iterates through the files.

Please let me know if I need to reformulate the question for clarity. Thanks in advance for all your help. It is really appreciated.

  • 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-04T18:45:16+00:00Added an answer on June 4, 2026 at 6:45 pm

    Just write down what you want – which is unclear to me.

    1. Do you want to rename? Then tell os.rename() what you want to rename and to what. In your case, you want to rename the orognal file to a new name which is certainly not w. So do os.rename(infile, newfilename).

    2. Do you want to process and put the output data somewhere else? Then open the file for writing, and with the correct file name: do output = open(infile + ".out", 'w').

    Especially don’t confuse filenames with file objects and how the functions work in particular.

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

Sidebar

Related Questions

A clueless Python newbie needs help. I muddled through creating a simple script that
Python newbie here. I'm writing a script that can dump some output to either
I am complete newbie in Python and have to modify existing Python script. The
python newbie here. I'm writing the code to control an experiment that has multiple
I'm a newbie programmer trying to jump in to Python by building a script
I'm a newbie to python and the app engine. I have this code that
I have another newbie Python question. I have the following piece of code that
Newbie Python question. I have a class that inherits from several classes, and some
Python newbie here: I'm writing a market simulation in Python using Pysage, and want
I'm a Python newbie. I have a series of objects that need to be

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.