Navigation Menu

Skip to content
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

csv #71543

Closed
fabianb mannequin opened this issue Jun 20, 2016 · 3 comments
Closed

csv #71543

fabianb mannequin opened this issue Jun 20, 2016 · 3 comments

Comments

@fabianb
Copy link
Mannequin

fabianb mannequin commented Jun 20, 2016

BPO 27356
Nosy @vstinner, @ezio-melotti, @berkerpeksag, @Vgr255
Files
  • MesspunkteAusKurven.py: three lines of python code
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2016-06-20.15:28:06.064>
    created_at = <Date 2016-06-20.15:24:24.545>
    labels = ['invalid', 'expert-unicode']
    title = 'csv'
    updated_at = <Date 2016-06-20.15:33:11.140>
    user = 'https://bugs.python.org/fabianb'

    bugs.python.org fields:

    activity = <Date 2016-06-20.15:33:11.140>
    actor = 'abarry'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-06-20.15:28:06.064>
    closer = 'berker.peksag'
    components = ['Unicode']
    creation = <Date 2016-06-20.15:24:24.545>
    creator = 'fabian_b'
    dependencies = []
    files = ['43490']
    hgrepos = []
    issue_num = 27356
    keywords = []
    message_count = 3.0
    messages = ['268904', '268905', '268906']
    nosy_count = 6.0
    nosy_names = ['bethard', 'vstinner', 'ezio.melotti', 'berker.peksag', 'abarry', 'fabian_b']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue27356'
    versions = []

    @fabianb
    Copy link
    Mannequin Author

    fabianb mannequin commented Jun 20, 2016

    Hi,

    I am running Canopy on Windows 7 64 bit.
    When I run the attached file, I get the following error:

    ----> 5 with open('C:\Users\Anwender\Desktop\Test\blub.txt') as csvfile:
    6 dialekt = csv.Sniffer().sniff(csvfile.read(1024))

    IOError: [Errno 22] invalid mode ('r') or filename: 'C:\\Users\\Anwender\\Desktop\\Test\x08lub.txt'

    As you see, Python complains about the file name after it changes the file name for no reason.

    The thing is, when I use a capital letter after every back slash it is fine, but I needed quite some time to figure that out. So it is very annoying for everyone encountering the problem for the first time.
    Also numbers at the beginning of a file name seem not to work either.

    Thank you for developing Python!

    @fabianb fabianb mannequin added the topic-unicode label Jun 20, 2016
    @berkerpeksag
    Copy link
    Member

    Thanks for the report. \t is a tab character. You can use

    'C:\\Users\\Anwender\\Desktop\\Test\\blub.txt'
    

    or

    r'C:\Users\Anwender\Desktop\Test\blub.txt'
    

    or

    'C:/Users/Anwender/Desktop/Test/blub.txt'
    

    @Vgr255
    Copy link
    Mannequin

    Vgr255 mannequin commented Jun 20, 2016

    (Berker beat me to it, but posting anyway since it is more detailed)

    Backslashes are escape characters, and "\b" is treated as "\x08". Invalid combinations (e.g. "\A", "\D"...) automatically escape the backslash, but you shouldn't rely on this behaviour - as you can see, it can break in various ways.

    To fix your issue, you can either:

    • Add a single 'r' before the beginning of your string, i.e. r"C:\Users\Anwender\Desktop\Test\blub.txt" - the 'r' prefix tells Python to automatically escape all backslashes it sees (unless it's at the end of the string, in that case you need to escape it yourself).

    • Escape each backslash in your string, i.e. "C:\\Users\\Anwender\\Desktop\\Test\\blub.txt" - the extra backslash tells Python "treat this as a literal backslash, don't use it to escape anything"

    • Since this is Windows, you can use forward slashes, i.e. "C:/Users/Anwnder/Desktop/Test/blub.txt", it will work all the same for Python.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant