Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python read file - pass variable name [duplicate]

Very simple question for Python 2:

I am calling specific library/function passing filename with readonly flag:

myfunction(r'/tmp/file.txt')

I wanted to replace it with variable:

filename = '/tmp/file.txt'
myfunction(r????)

How can I call that function?

like image 716
user2913139 Avatar asked Jun 20 '26 13:06

user2913139


1 Answers

That is not readonly flag. That means raw string. You use it when you don't want escape sequences inside string to be interpreted (like \n, \t etc.) See https://docs.python.org/2.0/ref/strings.html

For your string, you don't need it since it does not contain any escape sequence. Just omit the leading r.

like image 63
sureshvv Avatar answered Jun 23 '26 01:06

sureshvv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!