标签云

微信群

扫码加入我们

WeChat QR Code

I've been trying to read some things from a file and when I give the open() command the whole address it gives me no problems:address = 'Languages/Menu/en.txt'file = open(address, 'r')Even adding a string and a variable works:address = 'Languages/Menu/'pi = 'en.txt'address += pifile = open(address, 'r')But when I try to add one string and a variable from a class it doesn't work:address = 'Languages/Menu/'address += options.languageprint addressfile = open(address, 'r')IOError: [Errno 2] No such file or directory: 'Languages/Menu/en.txt\r'But the address printed is correct: Languages/Menu/en.txtSomeone knows why this is happening? In windows works perfectly.Thank you


actually, address.strip() will take care of every nonprinting and whitespace character in one go

2019年04月19日56分53秒

Thanks, fixed that

2019年04月19日56分53秒

Thank you. I used:address += options.languageaddress = address.strip('\r').strip('\n)in a function that I had for reading files. That's the function that creates the options.language variable in the class, apart from others.Now it works perfectly and it still keeps the whitespaces. :D

2019年04月19日56分53秒