Note that there are some explanatory texts on larger screens.

plurals
  1. PO.split(",") separating every character of a string
    text
    copied!<p>At some point of the program I ask it to take the user's text input and separate the text according to it's commas, and then I <code>",".join</code> it again in a txt file. The idea is to have a list with all the comma separated information.</p> <p>The problem is that, apparently, when I <code>",".join</code> it, it separates every single character with commas, so if I've got the string <code>info1,info2</code> it separates, getting <code>info1 | info2</code>, but then, when joining it back again it ends like <code>i,n,f,o,1,,,i,n,f,o,2,</code> which is highly unconfortable, since it get's the text back from the txt file to show it to the user later in the program. Can anyone help me with that?</p> <pre><code> categories = open('c:/digitalLibrary/' + connectedUser + '/category.txt', 'a') categories.write(BookCategory + '\n') categories.close() categories = open('c:/digitalLibrary/' + connectedUser + '/category.txt', 'r') categoryList = categories.readlines() categories.close() for category in BookCategory.split(','): for readCategory in lastReadCategoriesList: if readCategory.split(',')[0] == category.strip(): count = int(readCategory.split(',')[1]) count += 1 i = lastReadCategoriesList.index(readCategory) lastReadCategoriesList[i] = category.strip() + "," + str(count).strip() isThere = True if not isThere: lastReadCategoriesList.append(category.strip() + ",1") isThere = False lastReadCategories = open('c:/digitalLibrary/' + connectedUser + '/lastReadCategories.txt', 'w') for category in lastReadCategoriesList: if category.split(',')[0] != "" and category != "": lastReadCategories.write(category + '\n') lastReadCategories.close() global finalList finalList.append({"Title":BookTitle + '\n', "Author":AuthorName + '\n', "Borrowed":IsBorrowed + '\n', "Read":readList[len(readList)-1], "BeingRead":readingList[len(readingList)-1], "Category":BookCategory + '\n', "Collection":BookCollection + '\n', "Comments":BookComments + '\n'}) finalList = sorted(finalList, key=itemgetter('Title')) for i in range(len(finalList)): categoryList[i] = finalList[i]["Category"] toAppend = (str(i + 1) + ".").ljust(7) + finalList[i]['Title'].strip() s.append(toAppend) categories = open('c:/digitalLibrary/' + connectedUser + '/category.txt', 'w') for i in range(len(categoryList)): categories.write(",".join(categoryList[i])) categories.close() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload