1

I am coding a python database relying on txt file's. I have one function that has some parameters. Here is the base code:

def store_new_content(mainfield,filename,f1 = None,f2 = None,f3 = None,*arg):
      file1 = open(f"{filename}.txt","w")
      name1 = f":{f1}"
      name2 = f":{f2}"
      name3 = f":{f3}"
      unlimitedname= f":{arg}"
      file1.write(f"{name}{name1}{name2}{name3}{arg} \n")

seem's normal right? wrong. So I want the result in filename.txt to be f1:f2:f3:f4:f5:f6:f7 and so on and so on. But it comes out as f1:f2:f3(f4,f5,f6,f7).So how do I make it come our correctly, btw f4,f5,f6,f7 are from the *args. if not possible does anyone know how to have unlimited parameters that will come out neatly?

BZKN
  • 1,499
  • 2
  • 10
  • 25

2 Answers2

0

arg is a list of other parameters passed to your function, you can simply join the elements of this array, like any list in python.

>>> def test(*arg):
...     print(':'.join(arg))
... 
>>> test('f1', 'f2', 'f3')
f1:f2:f3
florianvazelle
  • 141
  • 1
  • 7
0

try this

def store_new_content(mainfield,filename,f1 = None,f2 = None,f3 = None,*arg):
    fulllist = [f1,f2,f3, *arg]
    print(':'.join(fulllist))
Ade_1
  • 1,480
  • 1
  • 6
  • 17