Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6719147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:03:29+00:00 2026-05-26T09:03:29+00:00

I am not a unicode expert, I read similar posts without any conclusive solution.

  • 0

I am not a unicode expert, I read similar posts without any conclusive solution. I need a snippet to read some files with Greek characters. My files have names like

20.10.2011 Ισοζύγιο Πληρωμών- Αύγουστος 2011.xls

I have a generator function that yields filenames:

# -*- coding:utf-8 -*-
import os
import glob

def filesInDir(directory, mask='*.*'):
    for root, dir, files in os.walk(directory):
        for file in glob.glob(os.path.join(root, mask)):            
            yield file

Calling this:

for file in filesInDir(directory=r'.'):
    with open(file,'r') as f:
        print f

gives

IOError: [Errno 22] invalid mode ('r') or filename: '.\\20.10.2011 ?s?????? ?????\xb5??- ?????st?? 2011.xls'

How do a create a valid file object using these sort of filenames?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:03:30+00:00Added an answer on May 26, 2026 at 9:03 am

    You need to make sure that you call os.walk() with a Unicode string, or it will silently change non-ASCII letters to ASCII (or change them to ? as you’ve observed).

    So do

    for file in filesInDir(directory=u'.'):
        with open(file,'r') as f:
            print f
    

    and

    def filesInDir(directory, mask=u'*.*'):
        for root, dir, files in os.walk(directory):
            for file in glob.glob(os.path.join(root, mask)):            
                yield file
    

    See also this similar question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the correct way to read Unicode files line by line in C++?
Not a really mysql expert =( , I need more pair of eyes to
VARCHAR does not store Unicode characters. NVARCHAR does store Unicode characters. Today's applications should
Unicode has a million icon-like glyphs, but they're not always easy to search by,
How do I convert from unicode to single byte in C#? This does not
I am trying to use Unicode variable names in g++, but it does not
How can I check whether a character is a Unicode character or not with
I'm trying to read and print a file that may or may not contain
I'm working on an application in C# and need to read and write from
Is there a free or open source library to read Excel files (.xls) directly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.