简体   繁体   中英

Going from Jupyter Notebook to Command Prompt - pass arguments

I've been learning python coding using jupyter notebooks and now I need to call this program from command prompt.

import sys
import codecs
import re

incoming_file =  open ('file_with_bad_character.xml', 'r')
outgoing_file = open ('cleaned_up_file.xml', 'a')

cc = [u'\u0015', u'\u0009']
def remove_control_characters(s):
    return re.sub ("|".join(cc), '', line)

for line in incoming_file.readlines():
    outgoing_file.write(remove_control_characters(line))
outgoing_file.close()

The purpose of this code is the read a file (incoming_file) and write a file out removing the two special control characters. I don't want the file name to change and I want to be able to call this code form command prompt passing it one arguments, the file name.

Can someone please suggest if this is the right approach and help me transition this from jupyter notebook to a python script I can call from command prompt?

一种选择是运行命令将文件转换为 .py,但最简单的方法是执行命令:ipython [file_name.ipynb]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM