Re: [Tutor] Importing XML files.

2019-01-21 Thread mhysnm1964
Peter and Alan,

Peter, Thanks for the information. The library did the trick and I can get 
access to the XML content.

Alan, thanks for the explanation of the tree structure. I was aware of this 
already for HTML and XML. Just didn't understand the terminology used from the 
XML library. The tutorials I have viewed didn't explain this information. I 
will continue investigating. The library provided has addressed my concerns for 
now.


-Original Message-
From: Tutor  On Behalf Of Peter 
Otten
Sent: Tuesday, 22 January 2019 5:22 AM
To: tutor@python.org
Subject: Re: [Tutor] Importing XML files.

mhysnm1...@gmail.com wrote:

> I am trying to import ITunes XML files. I have been doing some reading 
> and I am somewhat confused with some XML terminology.

> What is:
> 
>  
> 
> Tag – I think it is the  in the itunes library file.
> 
> Text = The text between the 
> 
> Attrib  -- don’t know.
> 
>  
> 
> If I am correct in my thinking. If you look up all the tags using the 
> xml module. How do you then isolate all the name text? I do not have 
> any working code at this present time. I have been playing with the 
> xml methods and reading some example tutorials. But I am stumped with 
> the above terminology which is a small road block. Below is an example 
> extract of my xML ITunes to see if this helps. I am doing this in 
> Python 3.7 for Windows 10.
> 
>  
> 
> 
> 
>  "http://www.apple.com/DTDs/PropertyList-1.0.dtd;>
> 
> 

You may be lucky in that you can avoid the hard way outlined by Alan -- 
Python's stdandard library includes a module that handles Apple's plist format. 
I tried your sample, and the module seems to turn it into nested
dicts:

>>> import plistlib, pprint
>>> with open("sample.xml", "rb") as f:
... data = plistlib.load(f)
... 
>>> pprint.pprint(data, width=70)
{'Application Version': '12.8.0.150',
 'Date': datetime.datetime(2019, 1, 14, 3, 56, 30),
 'Features': 5,
 'Library Persistent ID': 'F2D33B339F0788F0',  'Major Version': 1,  'Minor 
Version': 1,  'Music Folder': 'file:///Volumes/Itunes/iTunes/iTunes%20Media/',
 'Show Content Ratings': True,
 'Tracks': {'6493': {'Album': 'In Her Sights (Unabridged)',
 'Album Artist': 'Robin Perini',
 'Artist': 'Robin Perini',
 'Artwork Count': 1,
 'Bit Rate': 64,
 'Comments': "Jasmine 'Jazz' Parker, "
 'Jefferson County SWAT’s only '
 'female sniper, can thread the '
 'eye of a needle with a bullet. '
 'But she carries with her a '
 'secret from her past', [snip]
>>> data["Date"].isoformat()
'2019-01-14T03:56:30'
>>> list(data["Tracks"].values())[0]["Artist"]
'Robin Perini'

Looks good, except for the mojibake -- but that was already in your email.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Importing XML files.

2019-01-21 Thread Peter Otten
mhysnm1...@gmail.com wrote:

> I am trying to import ITunes XML files. I have been doing some reading and
> I am somewhat confused with some XML terminology.

> What is:
> 
>  
> 
> Tag – I think it is the  in the itunes library file.
> 
> Text = The text between the 
> 
> Attrib  -- don’t know.
> 
>  
> 
> If I am correct in my thinking. If you look up all the tags using the xml
> module. How do you then isolate all the name text? I do not have any
> working code at this present time. I have been playing with the xml
> methods and reading some example tutorials. But I am stumped with the
> above terminology which is a small road block. Below is an example extract
> of my xML ITunes to see if this helps. I am doing this in Python 3.7 for
> Windows 10.
> 
>  
> 
> 
> 
>  "http://www.apple.com/DTDs/PropertyList-1.0.dtd;>
> 
> 

You may be lucky in that you can avoid the hard way outlined by Alan -- 
Python's stdandard library includes a module that handles Apple's plist 
format. I tried your sample, and the module seems to turn it into nested 
dicts:

>>> import plistlib, pprint
>>> with open("sample.xml", "rb") as f:
... data = plistlib.load(f)
... 
>>> pprint.pprint(data, width=70)
{'Application Version': '12.8.0.150',
 'Date': datetime.datetime(2019, 1, 14, 3, 56, 30),
 'Features': 5,
 'Library Persistent ID': 'F2D33B339F0788F0',
 'Major Version': 1,
 'Minor Version': 1,
 'Music Folder': 'file:///Volumes/Itunes/iTunes/iTunes%20Media/',
 'Show Content Ratings': True,
 'Tracks': {'6493': {'Album': 'In Her Sights (Unabridged)',
 'Album Artist': 'Robin Perini',
 'Artist': 'Robin Perini',
 'Artwork Count': 1,
 'Bit Rate': 64,
 'Comments': "Jasmine 'Jazz' Parker, "
 'Jefferson County SWAT’s only '
 'female sniper, can thread the '
 'eye of a needle with a bullet. '
 'But she carries with her a '
 'secret from her past',
[snip]
>>> data["Date"].isoformat()
'2019-01-14T03:56:30'
>>> list(data["Tracks"].values())[0]["Artist"]
'Robin Perini'

Looks good, except for the mojibake -- but that was already in your email.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Importing XML files.

2019-01-21 Thread Alan Gauld via Tutor
On 21/01/2019 03:17, mhysnm1...@gmail.com wrote:

> confused with some XML terminology.
> 
> What is:
> Tag – I think it is the  in the itunes library file.
> 
> Text = The text between the 
> 
> Attrib  -- don’t know.
You really need to find a tutorial on XML
(And maybe even start with one on HTML?) To parse out
the information from an XML file, even using a parser
like etree, requires that you understand the structure
of the file. And that includes really understanding
the terminology.

In very simple terms an XML file (or more
correctly a "document") is a tree structure.
It starts with a parent node then that has
child nodes. Each child may have children
of its own ad infinitum. Each node is
identified by a pair of tags which are simply
names between angle brackets -  for example
There is a start and closing tag, the closing
one having a '/' at the start. Between the tags
is the text (which may include more tags for
child nodes).

tags can also include attributes which are names
inside the opening tags brackets, often with an
assigned value.

The rules governing what constitutes a valid tag
or attribute and which tags can be nested within
which others are all defined in a definition file,
often called a schema or DTD  file. There is a
standard header that tells the reader where to
find the schema.

You might also see comments which are just notes
to explain whats going on and contain no actual
data...

Here is a meaningless pseudocode example:




   
   
  Some text here
   
   
  Child2 text here
  Text here on same line
  More child2 text
  
   Text for subchild
  
  Finishing off child2 text...
   
   
  More text here, could be lorts of it over many lines
   
   
   


For more than that google XML tutorial...

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Importing XML files.

2019-01-21 Thread mhysnm1964
All,

 

I am trying to import ITunes XML files. I have been doing some reading and I am 
somewhat confused with some XML terminology.

 

What is:

 

Tag – I think it is the  in the itunes library file.

Text = The text between the 

Attrib  -- don’t know.

 

If I am correct in my thinking. If you look up all the tags using the xml 
module. How do you then isolate all the name text? I do not have any working 
code at this present time. I have been playing with the xml methods and reading 
some example tutorials. But I am stumped with the above terminology which is a 
small road block. Below is an example extract of my xML ITunes to see if this 
helps. I am doing this in Python 3.7 for Windows 10. 

 



http://www.apple.com/DTDs/PropertyList-1.0.dtd;>





  Major Version1

  Minor Version1

  Date2019-01-14T03:56:30Z

  Application Version12.8.0.150

  Features5

  Show Content Ratings

  Music 
Folderfile:///Volumes/Itunes/iTunes/iTunes%20Media/

  Library Persistent IDF2D33B339F0788F0

  Tracks

  

   6493

   

 Track 
ID6493

 NameIn Her Sights: 
A Montgomery Justice Novel, Book 1 (Unabridged)

 ArtistRobin 
Perini

 Album ArtistRobin 
Perini

 AlbumIn Her Sights 
(Unabridged)

 
GenreAudiobook

 KindAudible 
file

 
Size206806038

 Total 
Time25574318

 Year2012

 Date 
Modified2015-12-12T23:48:18Z

 Date 
Added2015-12-12T23:48:20Z

 Bit 
Rate64

 Sample 
Rate22050

 CommentsJasmine 
'Jazz' Parker, Jefferson County SWAT’s only female sniper, can thread the eye 
of a needle with a bullet. But she carries with her a secret from her 
past

 
Normalization790

 Artwork 
Count1

 Persistent 
ID2C4CC3C31A2B95B5

 Track 
TypeFile

 Protected

   
Locationfile:///Volumes/Itunes/iTunes/iTunes%20Media/Audiobooks/Robin%20Perini/In%20Her%20Sights_%20A%20Montgomery%20Justice%20Novel,%20Book%201%20(Unabridged).aax

 File Folder 
Count4

 Library Folder 
Count1

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Function not using updated variable?

2019-01-21 Thread Alan Gauld via Tutor
On 21/01/2019 00:14, Ello Solcraft wrote:
> # currLocation doesn't use the updated variable.
> 
> for x in inputList:
> 
> currCalc.append(x)
> currCalc2 = ''.join(currCalc)
> currLocation = mapLocation(mapInput(currCalc2))#mapInput(currCalc2))

You haven't hgiven us any information that would help us diagnose the
problem. All we can say from this is that you are passing the correct
variable to mapInput().

But what does mapUInput() do? Show us that code too.

And what does mapLocation do with the return value from mapInput()?
We need to see that code too.


> ... Hoewer it does work if I input a string
> without the currLocation variable.

That probably makes sense to you but makes no sense to us.
How can it "work" if you remove the variable that you
are saying doesn't work?

Maybe you need to explain what you are trying to achieve?

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor