A
A
A9FM2021-08-15 23:04:21
Python
A9FM, 2021-08-15 23:04:21

How to edit the conf.py file?

and so, I have a script, but it needs a lot of sessions, each number is different

when I write a number, the script must save it to a variable, after that it starts editing the code of one of the files,

but it’s bad luck how to edit this file

for example, write the number 2, then the file should be

from pyrogram import Client as session
global sess

sess = {
1: session('1'),
2: session('2'),
}

and if we write 5, then the code becomes

from pyrogram import Client as session
global sess

sess = {
1: session('1'),
2: session('2'),
3: session('3'),
4: session('4'),
5: session('5'),
}

how to automate these changes, and is it possible to implement it at all?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Q
qwertiss, 2021-08-16
@qwertiss

Just make a shape for start and end

def func_edit_string(lenght):
  form1 = '''from pyrogram import Client as session
global sess

sess = {
'''
  form_inject = ''

  for num in range(1,lenght+1):
    form_inject += str(num)+": session('"+str(num)+"'),\n"

  return form1+form_inject+"}"

a = func_edit_string(5)
print(a)


from pyrogram import Client as session
global sess
sess = {
1: session('1'),
2: session('2'),
3: session('3'),
4: session('4'),
5: session ('5'),
}

But this way you will get just a line
. If you want the list to increase, then use update
sess = {
1: "shrimp",
2: "shrimp",
}

sess.update({3: "shark"})

print(sess)

{1: 'shrimp', 2: 'shrimp', 3: 'shark'}

ARRAYS AND DICTIONARIES ARE DIFFERENT THINGS!
For arrays, use append!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question