Error message in python

aprofile

Commendable
May 11, 2016
2
0
1,510
hi I am trying this code but cannot get it to work properly. It comes up with invalid syntax. Please can someone suggest something.
Thanks in advance

def USB():
import os
letters = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
letternumber = 0
while letternumber < 26:
letter = letters[letternumber]
filepath = (letter':\\Python')
true = os.path.exists(filepath)
if true == True:
os.mkdir(letter':\\Python\Folder')
letter = 30
elif true == False:
letternumber = letternumber + 1


USB()
 

turkey3_scratch

Estimable
Herald
Jul 15, 2014
571
0
5,210

aprofile

Commendable
May 11, 2016
2
0
1,510


Thanks for the reply. I completely forgot about this. I have changed the code slightly as I noticed another issue with it and this is it now however it is still producing an error.

def USB():
import os
letters = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
letternumber = 0
done = False
while done == False:
letter = letters[letternumber]
filepath = (letter,':\\Python')
true = os.path.exists(filepath)
if true == True:
os.mkdir(letter,':\\Python\Folder')
done = True
elif true == False:
letternumber = letternumber + 1


USB()

Traceback (most recent call last):
File "F:\USB.py", line 17, in <module>
USB()
File "F:\USB.py", line 9, in USB
true = os.path.exists(filepath)
File "C:\Python34\lib\genericpath.py", line 19, in exists
os.stat(path)
TypeError: argument should be string, bytes or integer, not tuple
 
Error indicates something is believed to be a tuple and not a list.

I found this "definition".

"A tuple is a sequence of immutable Python objects. Tuples are sequences, just like lists. The differences between tuples and lists are, the tuples cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets."

To summarize:

Tuples ---> parentheses

Lists ----> square brackets

Possible mistype/misuse of () or [] ?