There must be a better way of writing the following code, I would really appreciate your suggestions and coding. I am new with python. Thanks.

A1 = os.path.join(pathname, "x")
A2 = os.path.join(pathname, "x", "y")
A3 = os.path.join(pathname, "x", "y", "z1")
A4 = os.path.join(pathname, "x", "y", "z2")
createPath(A1)
createPath(A2)
createPath(A3)
createPath(A4)

For starters, you can use a loop

import os

for path in [["x"], 
             ["x", "y"], 
             ["x", "y", "z"]]:
    pathname = "pathname"
    for next_path in path:
        pathname = os.path.join(pathname, next_path)
    print pathname
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.