# How to convert code from Java code to Python format T.T

**URL:** <https://forum.inductiveautomation.com/t/how-to-convert-code-from-java-code-to-python-format-t-t/42858>\
**Category:** Ignition\
**Tags:** python\
**Created:** [February 2, 2021, 1:20am UTC](https://forum.inductiveautomation.com/t/how-to-convert-code-from-java-code-to-python-format-t-t/42858 "2021-02-02T01:20:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kjy0124kr](https://avatars.discourse-cdn.com/v4/letter/k/f07891/32.png) [@kjy0124kr](https://forum.inductiveautomation.com/u/kjy0124kr)\
**Post date:** [February 2, 2021, 1:20am UTC](https://forum.inductiveautomation.com/t/how-to-convert-code-from-java-code-to-python-format-t-t/42858/1 "2021-02-02T01:20:21Z")

</div>

The code below is the Java source code. I would like to see the code that converted this source code to Python format. (Due to lack of Python knowledge…)  
Example) Data structure, instance creation Please help

```
        BufferedReader reader = new BufferedReader(new FileReader(file));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String s = "";
        Stack<Character> stack = new Stack<>();
        boolean flag = false;
        List<Jsoncolumn> result = new ArrayList<>();
        Answer answer = null;
        Questions questions = null;
        Jsoncolumn o = null;
        String lang="";
        boolean kycs=false;
        while ((s = reader.readLine()) != null) {
            for (char c : s.toCharArray()) {
                if (c == '{' || c == '[') stack.push(c);
                else if (c == ']' && stack.peek() == '[') stack.pop();
                else if (c == '}' && stack.peek() == '{') stack.pop();
            }
            if (stack.size()==1&&s.contains("level") && s.contains("NumberInt")) {
                flag = true;
                o = new Jsoncolumn();
                o.level = Integer.parseInt(s.replaceAll("[^0-9]", ""));
                System.out.println(o.level);
            }
            if(stack.size()==2){
                if (s.contains("kyc")&&!s.contains("s")) {
                    kycs=false;
                }
                if (s.contains("kycs")) {
                    kycs=true;
                }
            }
            if (flag&&!kycs) {
                if (stack.size() == 3) {
                    if ((s.contains("en") || s.contains("ko") || s.contains("ru"))&&!s.contains("languageType")) {
                        if(questions==null)questions=new Questions();
                        lang=s.split(":")[0].replaceAll("[\"']","").trim();
                        questions.lang = lang;
                    }
                }
                if (stack.size() == 5) {
                    if (s.contains("q_id")) {
                        if (questions == null) questions = new Questions();
                        questions.lang = lang;
                        questions.qId = Integer.parseInt(s.replaceAll("[^0-9]", ""));
                    }
                    if (s.contains("type")) {
                        if (questions == null) questions = new Questions();
                        questions.lang = lang;
                        String s2 = s.split(":")[1].replaceAll("[\",']", "").trim();
                        if(s2.toCharArray()[s2.length()-1]==',')s2 =s2.substring(0,s2.length()-1);
                        questions.type = s2;
                    }
                    if (s.contains("question")) {
                        if (questions == null) questions = new Questions();
                        String s2 = s.split(":")[1].replaceAll("[\"']", "").trim();
                        if(s2.toCharArray()[s2.length()-1]==',')s2=s2.substring(0,s2.length()-1);
                        questions.content = s2;
                    }
                }
                if (stack.size() == 7) {
                    if (answer == null) answer = new Answer();
                    if (s.contains("a_id")) answer.a_id = Integer.parseInt(s.replaceAll("[^0-9]", ""));
                    if (s.contains("answer")){
                        String s2 = s.split(":")[1].replaceAll("[\"']", "").trim();
                        if(s2.indexOf(s2.length())==',')s2 =s2.substring(0,s2.length()-2);
                        answer.answer = s2;
                    }
                }
                if (stack.size() == 6) {
                    if (answer != null) {
                        if (questions != null)
                            questions.answerList.add(answer);
                        answer = null;
                    }
                }
                if (stack.size() == 4) {
                    if (questions != null) o.questions.add(questions);
                    questions = null;
                }
            }
            if(stack.isEmpty()){
                if(o!=null)result.add(o);
                o=null;
            }
        }
```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 2, 2021, 1:45am UTC](https://forum.inductiveautomation.com/t/how-to-convert-code-from-java-code-to-python-format-t-t/42858/2 "2021-02-02T01:45:51Z")

</div>

You already asked this in another topic, yesterday. It is rather rude to repost just because you didn't get the answer written out completely for you.

> [@How to convert Java class to Python T.T](http://forum.inductiveautomation.com/t/how-to-convert-java-class-to-python-t-t/42800):
>
> Can someone tell me how to convert this java classes to python: Java: Help T.T File file = new File("/Users/gim-yuwan/Documents/project/RealResearch-API-BackEnd-Beta/src/main/resources/static/test.json"); BufferedReader reader = new BufferedReader(new FileReader(file)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); String s = ""; Stack\<Character\> stack = new Stack\<\>(); boolean flag = false; …
