0

I am trying to create a function that would create a folder based on the values passed as arguments. The function has 2 arguments (one argument that stores the store name and the other argument that has a reference date). Given below is the function.

def sales_fn(name,date):
    path = "/Users/user/'%s'/{}"%(name).format(date)

I keep getting an error

 FileNotFoundError: [Errno 2] No such file or directory: "/Users/user/'store_name'{}"

Could anyone guide me where am I going wrong. Thanks.

2
  • You're confusing the old % string formatting with .format, try to search online for documentation and examples that use .format you'll find plenty! Side-note: a path shouldn't contain quotes Commented Oct 24, 2018 at 18:01
  • A path can contain quotes if he thinks the username might contain spaces. Commented Oct 24, 2018 at 18:09

2 Answers 2

2

It's strange to use multiple types of string formatting like that. % is the old way, so just use .format():

path = "/Users/user/'{}'/{}".format(name, date)
Sign up to request clarification or add additional context in comments.

Comments

1

How about f-strings, they are much more elegant-

path = "/Users/user/'%s'/{}"%(name).format(date)

to -

path = f"/Users/user/{name}/{date}" 

NOTE: They will work only with Python 3.6+

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.