2

I tried to use Python with command line parser 'kakasi' together. Here is my code:

# -*- coding: utf-8 -*-
import os
text = 'スッキリわかる Java入門 実践編 第2版'
cmd = "echo $text | iconv -f utf8 -t eucjp | kakasi -i euc -w | kakasi -i euc -Ha -Ka -Ja -Ea -ka"
os.system(cmd)
-------------------

The result is empty line as below:

Process finished with exit code 0

Actually, the result should be like this:

sukkiri wakaru Java nyuumon jissenhen dai 2 han

I need a help.
Thanks in advance.

2 Answers 2

4

text is a variable known to the python interpreter only; the shell you execute your command in has no idea what $text is (it will evaluate to an empty string).

you could try this:

cmd = "echo '{}' | iconv ...".format(text)

that way you get your string to the command you want to execute. (can't test if there are other things that do not work...)

(side note: i like the sh module for this kind of thing. it is not in the standard library though).

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. It is helpful.
3

You should need to use String formatting.

SOLUTION :

# -*- coding: utf-8 -*-
import os
text = 'スッキリわかる Java入門 実践編 第2版'
cmd = "echo {} | iconv -f utf8 -t eucjp | kakasi -i euc -w | kakasi -i euc -Ha -Ka -Ja -Ea -ka".format(text)
os.system(cmd)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.