Error message in python

aprofile

Commendable
May 11, 2016
2
0
1,510
0
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
89

aprofile

Commendable
May 11, 2016
2
0
1,510
0


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
 

Ralston18

Dignified
Moderator
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 [] ?
 
Thread starter Similar threads Forum Replies Date
B Apps General Discussion 1
R Apps General Discussion 1
J Apps General Discussion 4
J Apps General Discussion 1
S Apps General Discussion 5
N Apps General Discussion 1
M Apps General Discussion 1
O Apps General Discussion 10
S Apps General Discussion 2
D Apps General Discussion 4
N Apps General Discussion 1
N Apps General Discussion 2
Z Apps General Discussion 10
K Apps General Discussion 1
T Apps General Discussion 1
T Apps General Discussion 4
A Apps General Discussion 6
SHADOWSTRIKE1 Apps General Discussion 3
L Apps General Discussion 1
G Apps General Discussion 19

ASK THE COMMUNITY