r/learnpython • • Feb 20 '21

What are you having difficulty learning or are currently struggling to learn?

I'm curious what the community here has difficulty with when it comes to learning Python. Partly because I want to see if the more experienced community here (or myself) can help point you into the right direction. . . but also because I'm trying to come up with video tutorial ideas for future content and would love to hear from Python learners what would be most useful to dedicate our time on.

I'm looking forward to hearing what you guys have to say!

417 Upvotes

324 comments sorted by

View all comments

Show parent comments

2

u/MaraudingAvenger Feb 21 '21

You can use xml.etree.ElementTree to parse and navigate XML. Check out the docs for some good code examples.

Changing what you parse into sqlite syntax is a matter of string formatting -- I highly recommend getting familiar with the string formatting mini-language if you have a chance -- that is everything after the colon in the squirrelly brackets in:

"{name:-^30}".format(name="middle")

I assume you're interacting with your sqlite database using the sqlite3 library (or maybe pandas).

A JSON is almost exactly a python dictionary, written out in a string, the way it looks when you write one out in your code. The json library can parse json strings coming in into python dicts (json.loads), or dump python dicts out into json strings (json.dumps).

Basically combining all of those things should give you the ability to go from huge XML files to sqlite to JSONs! If you want to share more specifics I could maybe help point the way.

As for stardict files, from what I can gather from https://en.wikipedia.org/wiki/DICT, the format looks pretty approachable -- you should probably use a good regex combined with some string cleanup (probably also using regex) to extract definitions from the files.

Hopefully that's enough to get you at least some stuff to Google!

1

u/Yetsubou Feb 22 '21

Thank you for the detailed answer! I am not that good at programming yet so I will have to work myself a bit into the documentations, especially regrex. I found it not that easy to find dictionary manipulation information in general.

More details about what I am planning to do: My main idea at the moment is to convert these https://github.com/spellcheck-ko/korean-dict-nikl three dictionaries to jsons with this format

[{"term": "分隔", "altterm": "", "pronunciation": "fēn gé", "definition": "to divide/to separate/partition", "pos": "", "examples": "", "audio": ""}, {"term": "分离", "altterm": "分離", "pronunciation": "fēn lí", "definition": "to separate", "pos": "", "examples": "", "audio": ""}]

I found a way to transform sqlite databases to correctly formatted jsons, https://github.com/digitalprk/dicrs these for example and they work. Someone helped me with the code and I adapted it for the individual dictionaries, using the sqlite3 library and the json library.

The idea with the stardicts is the same as with the xml dictionaries, making it into a JSON file of the same format to use them in a more practical application.

A future project will be to write my own dictionary where I want to extract sentences from dictionary websites or documents and make an example sentence dictionary out of them, but I do not know how to approach that at the moment.

I would be thankful for any more info, I know I might be asking some basic things.