sobjornstad / AnkiLPCG

Addon for dae/anki for studying lyrics and poetry

Home Page:https://ankilpcg.readthedocs.io/en/latest/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Whitespaces and IOError

fabswt opened this issue · comments

Hello,

Using AnkiLPCG with Python 2.7. I can drag and drop the input file, specify the title and tags, however I would then end up with the following error:

C:\Users\Fabien\Downloads\AnkiLPCG-master\AnkiLPCG-master>lpcg.py
    Lyrics/Poetry Cloze Generator v0.9.0
    Copyright 2013 Soren Bjornstad; see COPYING for details.

    Input File: Drag and drop the input file you wish to use onto this window.
    Title:      This will be used to prompt you for the first line of the text.
    Tags:       This will be fed to Anki as the Tags field of each card.

    For further help, see the README.

Input File: "D:\Dropbox\LANGUAGES\EN American English\English Pronunciation\Mode
ls\Poems\Fire and Ice.txt"
Title: Fire and Ice
Tags (optional): FireAndIce
Traceback (most recent call last):
  File "C:\Users\Fabien\Downloads\AnkiLPCG-master\AnkiLPCG-master\lpcg.py", line
 163, in <module>
    main()
  File "C:\Users\Fabien\Downloads\AnkiLPCG-master\AnkiLPCG-master\lpcg.py", line
 112, in main
    lyrics_file = open(input_file)
IOError: [Errno 22] invalid mode ('r') or filename: '"D:\\Dropbox\\LANGUAGES\\EN
 American English\\English Pronunciation\\Models\\Poems\\Fire and Ice.txt"'

I've fixed it by removing whitespaces from the input file's name and by moving it to a different directory.

I would suggest either automatically adding double-quotes around the path or putting a warning about paths inside of the readme.

I hope it helps somewhat.

By the way, thanks for the script, I've started playing with some poems I want to commit to memory and this is great stuff!

Fabien

The issue, strangely, is actually that there are quotes added, not that there aren't (there are two sets of quotes, which for whatever reason causes open() to look for a path starting with the drive "C. I'll add something to strip quotation marks.

I have pushed version 0.9.2 which fixes this issue for me. Please let me know if it doesn't work for you.

Hello,
Thanks for the feedback.

0.9.2 doesn't work for me, not even with files that do not contain any whitespaces in them:

Input File: C:\Users\Fabien\Desktop\hetedik.txt
Title: The Seventh
Tags (optional): TheSeventh
Traceback (most recent call last):
File "C:\Program Files (x86)\Anki\AnkiLPCG\lpcg.py", line 173, in
main()
File "C:\Program Files (x86)\Anki\AnkiLPCG\lpcg.py", line 122, in main
lyrics_file = open(input_file)
TypeError: coercing to Unicode: need string or buffer, NoneType found

Hope it helps.

Well, perhaps Windows handles it differently than Linux does then. Could you try editing the (0.9.2) file and replacing the quotation_strip function with this?

def quotation_strip(string):
    string = "\"%s\"" % string

What happens then, with both no-spaced and spaced paths?

This situation is irrelevant in 1.0., so whatever it was, it should be okay now. :-)