0

I need to open a txt file with python but I don't know how because the data in the txt is not familiar for me. Next the firsts lines. How can I read theses and then use it?

What is this?

[
{
  "complemento": {
    "valorTotal": 24.9
  },
  "dets": [
    {
      "nItem": "1",
      "prod": {
        "indTot": "1",
        "qCom": 1.0,
        "uCom": "UN",
        "vProd": 3.5,
        "vUnCom": 3.5,
        "xProd": "AGUA"
      }
    },
    {
      "nItem": "2",
      "prod": {
        "indTot": "1",
        "qCom": 0.312,
        "uCom": "KG",
        "vProd": 21.4,
        "vUnCom": 68.6,
        "xProd": "BUFFET"
      }
    }
  ],
martineau
  • 119,623
  • 25
  • 170
  • 301

3 Answers3

1

This is a JSON file. Importing it using json.load(path) will give you a Python dict that has the exact same structure you see in your file.

lucasnadalutti
  • 5,818
  • 1
  • 28
  • 48
1

That is a JSON file but it is not complete. Some part is missing. You can use JSON LINT http://jsonlint.com/ to validate a json file. For parsing json in python u can use json library details can be found in this post. https://dzone.com/articles/python-reading-json-file

ImVikash_0_0
  • 174
  • 9
0

You can open a file in python like this:

with open(file_path, 'r') as your_file:
     content = your_file.read()

After this the content of your file will be in the variable content. I would like to answer the rest of your question but I cannot understand it. Srry

Guillaume Jacquenot
  • 11,217
  • 6
  • 43
  • 49
Developer
  • 443
  • 2
  • 11