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 7771309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:37:10+00:00 2026-06-01T16:37:10+00:00

def ConvertFile(): FileNameIn = ‘Hexdata.dat’ HexFile = open(FileNameIn, ‘r’) for Line in HexFile: print

  • 0
def ConvertFile():
  FileNameIn = 'Hexdata.dat'
  HexFile = open(FileNameIn, 'r')
  for Line in HexFile:
    print (Line)
    print (Binary(Line))
  HexFile.close()

So far I have that, which, when the program is run, converts the Hexidecimal number in the file to binary. This is in a file called Hexdata.dat

What I want to do is then save the binary output into a file called Binarydata.dat

How would I approach this in code? Be aware I’m new with Python and haven’t covered this properly. I’ve tried different bits of code but they’ve all been unsuccessful, as really, they’re all guesses.

I’m not asking you to solve the problem for me, but more asking how I would save the output of a program into a new text file.

  • 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-01T16:37:11+00:00Added an answer on June 1, 2026 at 4:37 pm

    You’re already most of the way there. You already know how to open a file for reading:

    HexFile = open(FileNameIn, 'r')
    

    The 'r' there means “open for reading”. If you look at the documentation for the open function, you will see that replacing the r with a w will open a file for writing:

    OutputFile = open(FileNameOut, 'w')
    

    And then you can send output to it like this:

    print >>OutputFile, "Something to print"
    

    Or use the write method on the file object:

    OutputFile.write("Something to print\n")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

def foo(**args): for k, v in args.items(): print type(k), type(v) for k, v in
def myFunc(arg1, arg2): print This is a test with + arg1 + and +
def sortProfiles(p): return sorted(p, key=itemgetter('first_name')) I have a list with dictionaries. This function allows
def display_home(request): from datetime import * now=datetime.today() print 'Month is %s'%now.month events=Event.objects.filter(e_date__year=datetime.today().year).filter(e_date__month=datetime.today().month,e_status=1).values('e_name','e_date') return render_to_response("SecureVirtualElection/home.html",{'events':
def myFunc( str ): print str=, str if str == None: print str is
def applejuice(q): print THE FUNCTION NAME! It should result in applejuice as a string.
def main(): x=2 def cool(): y=4 nonlocal x print (x) It is showing an
def exec_command(self, command, bufsize=-1): #print Executing Command: +command chan = self._transport.open_session() chan.exec_command(command) stdin =
def login debugger LOGIN::authenticate(params) end When it hits the line with debugger, I type
def create_thumbnail(f, width=200, height=100): im = Image.open(f) im.thumbnail((width, height), Image.ANTIALIAS) thumbnail_file = StringIO() im.save(thumbnail_file,

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.