Python Forum
How do I pick the right python in Linux env?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I pick the right python in Linux env?
#4
Thanks for weighing in.

Here is the code

#!/usr/bin/python
def Process_XML(infile, inxpath, xpathdln):
    """
       Process XML Xpath
    """   
    import xml.etree.ElementTree as ET
    from lxml import etree

    tree = etree.parse(infile)
    root = tree.getroot()
    print(root)
    for dln in tree.xpath(xpathdln):    
        # Iterate over attributes of datafield
            print(dln.tag + ' = ' + dln.text)
            for df in tree.xpath(inxpath):    
        # Iterate over attributes of datafield
                    print(df.tag + ' = ' + df.text)
                    for attrib_name in df.attrib:
                                    print( '@' + attrib_name + '=' + df.attrib[attrib_name])

        # subfield is a child of datafield, and iterate
                                    subfields = df.getchildren()
                                    for subfield in subfields:
                                                 print (subfield.tag + ' = ' + subfield.text)
    return;                
                
infile1 = '<CountryData.xml>  # Given below
inxpath1 = '//Country'
xpathdln = '/data'
Process_XML(infile1, inxpath1, xpathdln) 
The above code is tested in windows Python 3.8.1, but Linux has Python 2

INPUT Data
==============

<?xml version="1.0" encoding="UTF-8"?>
<data>
<country name="Liechtenstein">
<rank>1</rank>
<year>2008</year>
<gdppc>141100</gdppc>
<neighbor name="Austria" direction="E"/>
<neighbor name="Switzerland" direction="W"/>
</country>
<country name="Singapore">
<rank>4</rank>
<year>2011</year>
<gdppc>59900</gdppc>
<neighbor name="Malaysia" direction="N"/>
</country>
<country name="Panama">
<rank>68</rank>
<year>2012</year>
<gdppc>13600</gdppc>
<neighbor name="Costa Rica" direction="W"/>
<neighbor name="Colombia" direction="E"/>
</country>
</data>

The python code ==> xmltest.py
It is sitting in the home directory with u+x permission

If I use ./xmltest.py throw file not found

Running this in window make output, but Linux is not making output.

I ran with python -v xmltest.py.

I did not see any errors there as well.

Thanks for your guidance.
Reply


Messages In This Thread
RE: How do I pick the right python in Linux env? - by MDRI - Jun-25-2020, 01:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Is possible to run the python command to call python script on linux? cuten222 6 826 Jan-30-2024, 09:05 PM
Last Post: DeaD_EyE
  How to use a variable in linux command in python code? ilknurg 2 1,636 Mar-14-2022, 07:21 AM
Last Post: ndc85430
  Python syntax in Linux St0rmcr0w 2 54,746 Jul-29-2021, 01:40 PM
Last Post: snippsat
  Login to NordVPN on Linux with python script AGreenPig 2 6,059 Feb-09-2021, 10:44 AM
Last Post: AGreenPig
  how to run linux command with multi pipes by python !! evilcode1 2 6,443 Jan-25-2021, 11:19 AM
Last Post: DeaD_EyE
  where to get portable Python for Linux (Fedora)? python001 5 6,397 Nov-01-2020, 05:23 PM
Last Post: Larz60+
  Python in Linux environment on RPI kendias 22 11,288 Sep-05-2020, 03:04 AM
Last Post: K_Research
  control a linux program with python Fifoux082 9 4,167 May-08-2020, 04:24 PM
Last Post: Fifoux082
  Python version on Linux whois1230 5 3,595 Apr-10-2020, 07:12 PM
Last Post: buran
  how to get PID's of linux commands executed through python modules? Manikandan_PS 4 3,092 Mar-12-2020, 07:16 AM
Last Post: Manikandan_PS

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020