-1

Why do the line "old_langpacks.append(act_item)" get skipped? When I use just the for loop, without the if, then it works.

    if act_file == "Languages.csv":
        temp_list = open(act_file,"r")
        for act_item in temp_list:
            old_langpacks.append(act_item)
    else:
        pass

2 Answers2

2

The reason it is not working is because your if condition is evaluating to false.

In addition to what Mark Byers suggested one thought came to mind:

Is it possible that act_file is a file object, opposed to a string which represents the name of the file?

How is act_file created?

If you obtain it via something similar to:

act_file = open("Languages.csv")

then you will not be able to check its name the way you have written, because act_file is indeed a file object.

If act_file is a file object, the correct way to write your if statement would be:

if act_file.name == "Languages.csv":
Tom Neyland
  • 6,860
  • 2
  • 36
  • 52
0

Probably the condition in your if is resulting in False even though you think it should be true.

That might be due to case sensitivity - if you are on Windows, the file names will work with any casing, but the string comparison in your if won't compare true, if the case of any letter in the act_file variable differs from the way they are in the Languages.csv string.

To work around this I'd suggest you change the if line to:

if act_file.lower() == "languages.csv":
Brian Deragon
  • 2,929
  • 24
  • 44
jsbueno
  • 99,910
  • 10
  • 151
  • 209