Python - passing string and specific lists, combined into function
NickName:Ilyasofficial Ask DateTime:2017-09-11T22:53:08

Python - passing string and specific lists, combined into function

i want to pass string (dirPath + dirName[x]) to a function

i already tried 3 times to combining string and a specific list (only dirName[x])

it seems that python just rejecting it anyway even if i already convert it to another type.

is anyone know how i pass this string to Function?

layer = 0
dirName = []
#dummy value layer = 4,  dirName = [/a,/b,/c,/d], dirBruteForce(layer,vault)

def dirBruteForce(layer,dirPath):
if layer > 0 :
    #call again to make layered dir
    for x in range(len(dirName)):
        dirBruteForce(layer - 1, dirPath + dirName[x]) ##this line
#call end of the dir
elif layer is 0 :
    for x in range(len(dirName)):
        try:
            os.makedirs(dirPath)
            print(dirPath)
        except Exception as e:
            pass
###

try1:

dirBruteForce(layer - 1, dirPath + dirName[x])
TypeError: can only concatenate list (not "str") to list

try2:

list = [dirPath,str(dirName[x])]
dir = ''.join(list)
dirBruteForce(layer - 1, dir)

error2:

dir = ''.join(list)
TypeError: sequence item 0: expected str instance, list found

try3:

dir = ''.join([dirPath,dirName[x]])
dirBruteForce(layer - 1, dir)

error3:

dir = '-'.join([dirPath,dirName[x]])
TypeError: sequence item 0: expected str instance, list found

Copyright Notice:Content Author:「Ilyasofficial」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/46158628/python-passing-string-and-specific-lists-combined-into-function

More about “Python - passing string and specific lists, combined into function” related questions

Python - passing string and specific lists, combined into function

i want to pass string (dirPath + dirName[x]) to a function i already tried 3 times to combining string and a specific list (only dirName[x]) it seems that python just rejecting it anyway even if i

Show Detail

Passing variable length parameters to a function in python

This question, though specific in nature, can be abstracted to a general question about Python. Imagine there is a function that takes in a few parameters. This list of parameters is of variable ...

Show Detail

python passing parameter to a function

I am not clear about the concept of passing lists as arguments to functions in python. I've tried researching on this myself , didn't find adequate resources. I want to implement a helper function

Show Detail

Passing Partial Lists into Python Function

I'm writing a Python program to read in a text file and pull out some information. There are three items I'm trying to find, one real number, and two lists. The script stores the lines of the text

Show Detail

Replace string in specific index in list of lists python

How can i replace a string in list of lists in python but i want to apply the changes only to the specific index and not affecting the other index, here some example: mylist = [["test_one", "test_...

Show Detail

How can I delete a specific element of a list in a combined list of lists?

I am trying to find a way to check a list which contains several other lists for a specific element and delete it. So basically I have 2 lists (a and b) which are combined in another list (c) a=...

Show Detail

How to print an item with least combined rank in two lists

I have just started with Python and trying to solve this problem. Given the two lists, I have to print the item with the least combined rank in the two lists. Here is my approach so far, but it see...

Show Detail

Passing a dictionary of lists to the zip function in python

I have a dictionary that groups lists in the form list_hostname and its size can vary depending on the number of hosts. I would like to zip those lists together along with another list list_times...

Show Detail

alternative for passing references around in python

I'm relatively new to python and oop, and i have a question around the design of my code for a hobby project. I created a lot of variables in my main program. These variables are lists of objects ...

Show Detail

Python: Combined lists iteration

I've got two lists: synonymes = ['verb1', 'verb2', 'verb3'] phrases = ['blabla verb blabla', 'blibli verb blibli', 'verb bloblo bloblo'] and I would like to combin

Show Detail