#🔒 so basically i want it so that the list in alphabetical order how would i adjust my code
224 messages · Page 1 of 1 (latest)
@alpine shell
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
@trail pawn @brittle crow
is the friendBtnList what you want to sort?
look at this
def processPath():
global path
if os.path.exists(path):
#print("path exists")
if os.path.isdir(path):
print("It is directory")
count = 0 #keeps a track of how many image files are dealt with:
for file in os.listdir(path):
print(file)
(head, tail)= os.path.splitext(file)
print(f"head... {head}) and tail ...{tail}")
if tail.lower() not in [".png", ".jpg"]:
continue
print(file)
count = count + 1
print(f"number of image files processed: {count}")
displayImg(file,count)
print(friendBtnList.sort())# changed this
or sorted(firendBtnList)
so this is how i add it to my code?
idk you can try it
nvm linux is giving up on me 🙏 discord im sorry but youre gonna have to get ended
huh
u need photo
@alpine shell do that and let me know
ok
.sort() i added
add sorted(friendBtnList)
a?
can u send photo here too 😄 just two
ok let me do sorted first
how would i do it
becuase friendBtnList is in ()
already
ye add another
nd print is there
print(sorted(friendBtnList))
ohok so another line of code
no
or same
def processPath():
global path
if os.path.exists(path):
#print("path exists")
if os.path.isdir(path):
print("It is directory")
count = 0 #keeps a track of how many image files are dealt with:
for file in os.listdir(path):
print(file)
(head, tail)= os.path.splitext(file)
print(f"head... {head}) and tail ...{tail}")
if tail.lower() not in [".png", ".jpg"]:
continue
print(file)
count = count + 1
print(f"number of image files processed: {count}")
displayImg(file,count)
print(sorted(friendBtnList))# changed this
doesnt work
ye send photo here ;v
Wat photo
Wait why is my thing messed up now
Like now when I press the friends it doesn’t show now
Like u see how it’s small nd only one
There should be 4
so you want photos in alphabetical orders?
Yh
ohh
But also like why is it messed up now
can you send us two photos from images/ folder
where did you get those guys inisde there?
Wdym
i want those photos not the app photos
path = 'images/' # folder that has all the images
This it
@wet flame how do I get my thing back to this
yh but its not working
Yh but look now it does this
Before it didn’t do that it should the friends
Do Yk wat happened
did u copy the code from https://paste.pythondiscord.com/PWGA
and pasted all of that there?
Yes
and saved it
Yes
so how did that change and didnt go back as old
Idk
you doin smth wrong?
Let me try fix it
lol sorry
Ok wait
So
I’ll fix that
So basically
I want it
To be
Like alphabetically in order
So for example
U see here
How it goes jimmy
..
I want it to be Adam first
Nd so on
@wet flame u get it?
Ok ty
Wdym
and everytime i add new stuff in my folder they first get order in the folder
by windows
I have Mac
A quick search says that the order returned by os.listdir is OS/filesystem dependant. If you want a certai order, use sorted or the sort method of lists to sort the files first.
Huh
So I change list.dir to os.dir
No. list.dir was a typo I made in the original comment.
https://stackoverflow.com/questions/4813061/non-alphanumeric-list-order-from-os-listdir
Ok I’ll try let me fix my code first
@alpine shell
Yh
can you try add a files.sort() at
def processPath():
global path
if os.path.exists(path):
#print("path exists")
if os.path.isdir(path):
print("It is directory")
count = 0 #keeps a track of how many image files are dealt with:
files.sort() #<<< HERE
for file in os.listdir(path):
print(file)
(head, tail)= os.path.splitext(file)
print(f"head... {head}) and tail ...{tail}")
if tail.lower() not in [".png", ".jpg"]:
continue
print(file)
count = count + 1
print(f"number of image files processed: {count}")
displayImg(file,count)
print(friendBtnList)
else:
print("Path exists but no folders")
else:
print("No such path")
pass```
under count = 0
Ok first lemme fix my code from before
This is what the posts suggests to do.
Give me 5 mins
So yes. Just call sort or sorted.
The list of files.
And also, there's no need for the pass at the end there. Not sure who put that in.
Mac must make that guarantee or something . The docs for listdir say:
The list is in arbitrary order.
oh okay
first i thought he wanted tjhe list when he prints to be sorted lol
took a long long time to fix this "simple" issue
😂
under it or aboce doesnt matter
what was the problem :D?
No now it doesn’t even show anything
It was only showing 1 picture
files = os.listdir(path)
files.sort()```
I have to add that
lemme send the code
def processPath():
global path
if os.path.exists(path):
#print("path exists")
if os.path.isdir(path):
print("It is directory")
files = os.listdir(path) # <<<
files.sort() # <<
count = 0 #keeps a track of how many image files are dealt with:
for file in files: # <<<
print(file)
(head, tail)= os.path.splitext(file)
print(f"head... {head}) and tail ...{tail}")
if tail.lower() not in [".png", ".jpg"]:
continue
print(file)
count = count + 1
print(f"number of image files processed: {count}")
displayImg(file,count)
print(friendBtnList)
else:
print("Path exists but no folders")
else:
print("No such path")
pass```
ye
Then files.sort next line
Anything else
you add files not os.listdir(path)
you maybe could do os.listdir(path).sort() 😄 ? idk
but try first if it works
The loop? Is where
in processPath
for file in os.listdir(path): you change os.listdir(path) to files
So just .files
Ok
maybe works
really
Yh look
Ok forget that
Do Yk
Say
I want it so that the friends of the friend
Is like going down
Not across
So like for the friends of Adam
I want his friends to be going down in a row
Do Yk how I would do that
@wet flame
His friends are Alex Ali raj rima
But it goes to like the bottom in a row rather than going down his name
so if you click ADAM all should align below adam like a column
can you click adam first?
But it doesn’t work like that
and show pic
Yh
Ok
Here u go boss
So I want it going down next to his name
Not across everyone else
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.