New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force file_type on read #148

Closed
guysoft opened this Issue Aug 3, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@guysoft

guysoft commented Aug 3, 2018

Hey,
So working with files ending with .txt that are actually .csv files.
This is in fact the standard in Example GTFS Feed which are used by google and governments.

So I need a way to read a file ending in .txt as a .csv.

I see here in the code that there is a use of file_type, but it would not work if there is a file_name already defined. Is this a bug or covering a use-case I don't know?
Can I PR something that uses force_file_type or something like that?

class FileSourceInfo(SourceInfo):
    """Plugin description for a file source"""
    def is_my_business(self, action, **keywords):
        status = SourceInfo.is_my_business(self, action, **keywords)
        if status:
            file_name = keywords.get("file_name", None)
            if file_name:
                if is_string(type(file_name)):
                    file_type = find_file_type_from_file_name(file_name,
                                                              action)
                else:
                    raise IOError("Wrong file name")
            else:
                file_type = keywords.get("file_type")

            status = self.can_i_handle(action, file_type)
        return status
@chfw

This comment has been minimized.

Member

chfw commented Aug 3, 2018

I acknowledge that this is a valid constraint. for physical file, the only way to tell pyexcel about the file format is the file extension.

A change in pyexcel_io may be required to support this feature. You can submit a PR too. We can work on it together.

@chfw chfw added the enhancement label Aug 5, 2018

chfw added a commit that referenced this issue Aug 22, 2018

chfw added a commit to pyexcel/pyexcel-io that referenced this issue Aug 23, 2018

force read a physical file as a different format, which then will s…
…elects a particular reader. for example: force txt file as csv. But forcing xls as xlsx may not give you any benefit, because pyexcel-xls reads both xls and xlsx. related to: pyexcel/pyexcel#148

@chfw chfw referenced this issue Aug 23, 2018

Merged

Release 0.5.9 #52

chfw added a commit that referenced this issue Aug 23, 2018

💚 integration tests with #148. please note that: pyexcel uses file_ty…
…pe togather with file_name. but if you use pyexcel-io, you need to use force_file_type for the same feature

chfw added a commit that referenced this issue Aug 23, 2018

@chfw chfw closed this Aug 30, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment