Creating a Script

More
16 Feb 2013 01:35 #30131 by BigJohnT
Replied by BigJohnT on topic Creating a Script
Here is the python file. Place it in the directory with a copy of your files you want to convert and make sure you set permissions to execute.
#! /usr/bin/env python
# Usage: ./todd.py filenametoconvert.ngc
# Output: converted_filenametoconvert.ngc

import sys

def main(argv):

  openfile = open(argv[0], 'r')
  file_in = openfile.readlines()
  openfile.close()

  file_out = []
  for line in file_in:
    # print line
    if line.find('Z') != -1:
      words = line.rstrip('\n')
      words = words.split(' ')
      newword = ''
      for i in words:
        if i[0] == 'Z':
          newword = 'W'+ i[1:]
      if len(newword) > 0:
        words.append(newword)
        newline = ' '.join(words)
        file_out.append(newline)
    else:
      file_out.append(line)
  newfile = open('converted_'+argv[0], 'w')
  for item in file_out:
    newfile.write("%s\n" % item)
  newfile.close()

if __name__ == "__main__":
   main(sys.argv[1:])

Enjoy
John

Please Log in or Create an account to join the conversation.

More
18 Feb 2013 22:31 #30280 by BigJohnT
Replied by BigJohnT on topic Creating a Script
Todd,

Did this work out for you?

John

Please Log in or Create an account to join the conversation.

  • Todd Zuercher
  • Todd Zuercher's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
18 Feb 2013 23:51 #30286 by Todd Zuercher
Replied by Todd Zuercher on topic Creating a Script
I have not had time to test it yet.

Please Log in or Create an account to join the conversation.

  • Todd Zuercher
  • Todd Zuercher's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
19 Feb 2013 02:01 #30291 by Todd Zuercher
Replied by Todd Zuercher on topic Creating a Script
Ok, where do I save the file? When I try to use it it a window pops ups and sais that the file can not be found.

Please Log in or Create an account to join the conversation.

More
19 Feb 2013 02:12 - 20 Mar 2013 17:27 #30292 by BigJohnT
Replied by BigJohnT on topic Creating a Script
Save the python file to any directory. Copy a ngc file you wish to convert to the same directory.

Open up a terminal and change directory to the one that contains the two files.
Type in dot slash the python file name and the file name to convert.

For example
cd convert_directory
./todd.py filename.ngc

John
Attachments:
Last edit: 20 Mar 2013 17:27 by BigJohnT.

Please Log in or Create an account to join the conversation.

  • Todd Zuercher
  • Todd Zuercher's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
20 Mar 2013 03:33 #31617 by Todd Zuercher
Replied by Todd Zuercher on topic Creating a Script
I can not open the file todd.py.txt

Please Log in or Create an account to join the conversation.

More
20 Mar 2013 03:38 #31618 by PCW
Replied by PCW on topic Creating a Script
You probably have to remove the .txt from the filename

Please Log in or Create an account to join the conversation.

  • Todd Zuercher
  • Todd Zuercher's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
20 Mar 2013 04:20 #31622 by Todd Zuercher
Replied by Todd Zuercher on topic Creating a Script
I can't down load it from the web site. It gives an internal server error when clicked on.

Please Log in or Create an account to join the conversation.

More
20 Mar 2013 07:05 #31626 by PCW
Replied by PCW on topic Creating a Script
The forum seems to have misplaced a lot of old attachments, but
the complete text of the program is in a previous post so you
should be able to just copy and paste it into an editor (gedit for example)

Please Log in or Create an account to join the conversation.

  • Todd Zuercher
  • Todd Zuercher's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
20 Mar 2013 08:48 #31630 by Todd Zuercher
Replied by Todd Zuercher on topic Creating a Script
I've not had any luck getting it to work, and I was hoping that there were some revisions in the last attachment that might clue me in to what I'm doing wrong.

Please Log in or Create an account to join the conversation.

Time to create page: 0.110 seconds
Powered by Kunena Forum