#🔒 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)

rotund dragonBOT
#

@alpine shell

Python help channel opened

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.

alpine shell
#

@trail pawn @brittle crow

wet flame
#

is the friendBtnList what you want to sort?

trail pawn
#

look at this

alpine shell
#

yh

#

i want it sorted alphabetically

wet flame
#
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)

alpine shell
#

so this is how i add it to my code?

wet flame
#

idk you can try it

trail pawn
#

nvm linux is giving up on me 🙏 discord im sorry but youre gonna have to get ended

alpine shell
#

huh

wet flame
#

@alpine shell do that and let me know

alpine shell
#

ok

wet flame
#

.sort() i added

alpine shell
#

no

#

doesnt work

wet flame
#

add sorted(friendBtnList)

alpine shell
#

a?

wet flame
#

can u send photo here too 😄 just two

alpine shell
#

ok let me do sorted first

#

how would i do it

#

becuase friendBtnList is in ()

#

already

wet flame
#

ye add another

alpine shell
#

nd print is there

wet flame
#

print(sorted(friendBtnList))

alpine shell
#

ohok so another line of code

wet flame
#

no

alpine shell
#

or same

wet flame
#
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 
alpine shell
#

doesnt work

wet flame
#

ye send photo here ;v

alpine shell
#

Ok

wet flame
#

no the photo you added to images folder

#

just two ye

alpine shell
#

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

wet flame
#

so you want photos in alphabetical orders?

alpine shell
#

Yh

wet flame
#

ohh

alpine shell
#

But also like why is it messed up now

wet flame
#

can you send us two photos from images/ folder

alpine shell
#

Before it was like this

#

I want it back like that

#

Nd alphabetically

wet flame
#

where did you get those guys inisde there?

alpine shell
#

Wdym

wet flame
#

i want those photos not the app photos

alpine shell
#

Ok

wet flame
#

path = 'images/' # folder that has all the images

alpine shell
#

This it

wet flame
#

send me two of them send jim.png and adam.png here

#

not screenshots

#

the photo itself

alpine shell
#

Here

alpine shell
wet flame
#

just put old code of urs

#

this was ur old

alpine shell
#

yh but its not working

wet flame
#

wdym

#

its ur old code

#

that u send

alpine shell
#

Yh but look now it does this

#

Before it didn’t do that it should the friends

#

Do Yk wat happened

wet flame
#

and pasted all of that there?

alpine shell
#

Yes

wet flame
#

and saved it

alpine shell
#

Yes

wet flame
#

so how did that change and didnt go back as old

alpine shell
#

Idk

wet flame
#

you doin smth wrong?

alpine shell
#

Let me try fix it

wet flame
#

but your code doesnt work for me

#

givese me so many erros

alpine shell
#

Idk

#

Ffs

#

What happened

wet flame
#

lol sorry

alpine shell
#

Ok wait

#

So

#

I’ll fix that

#

So basically

#

I want it

#

To be

#

Like alphabetically in order

#

So for example

alpine shell
#

How it goes jimmy

#

..

#

I want it to be Adam first

#

Nd so on

#

@wet flame u get it?

wet flame
#

yes lemme try

#

fix the erros i get

alpine shell
#

Ok ty

wet flame
#

everytime i run it i get alphabetical order

alpine shell
#

How comes I don’t

#

@wet flame

#

Is there anyway u can fix my one

wet flame
#

maybe my folders are sorted asc

#

and urs arnt

alpine shell
#

Wdym

wet flame
#

and everytime i add new stuff in my folder they first get order in the folder

#

by windows

alpine shell
#

I have Mac

wet flame
marble hound
#

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.

alpine shell
#

Huh

marble hound
#

*os.listdir

#

Not list.dir.

alpine shell
#

So I change list.dir to os.dir

marble hound
alpine shell
#

Ok I’ll try let me fix my code first

wet flame
#

@alpine shell

alpine shell
#

Yh

wet flame
#

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

alpine shell
#

Ok first lemme fix my code from before

marble hound
#

This is what the posts suggests to do.

alpine shell
#

Give me 5 mins

marble hound
#

So yes. Just call sort or sorted.

wet flame
#

ye sort the file

#

not the list

#

🤔

marble hound
#

The list of files.

#

And also, there's no need for the pass at the end there. Not sure who put that in.

wet flame
#

lol

#

i get everytime ordered

#

how 😮

marble hound
#

Mac must make that guarantee or something . The docs for listdir say:

The list is in arbitrary order.

wet flame
#

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

alpine shell
#

Ok

#

I got it back to how it was before

wet flame
#

😂

alpine shell
#

Now let me do wat u said

#

Wait so after count = 0 I add it

wet flame
#

under it or aboce doesnt matter

wet flame
alpine shell
#

No now it doesn’t even show anything

alpine shell
wet flame
#
 files = os.listdir(path)
 files.sort()```
alpine shell
#

I have to add that

wet flame
#

yes

#

wait

alpine shell
#

It’s two separate lines right

#

Ok

wet flame
#

then in the whole loop

#

you add while file in files it was for

#

not os.lstdir

alpine shell
#

I’m confused so I add more

#

To where

wet flame
#

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```
alpine shell
#

Ok I try

#

So it’s files = os.listdir(path)

#

One line

wet flame
#

ye

alpine shell
#

Then files.sort next line

wet flame
#

yes

#

then in the for loop

alpine shell
#

Anything else

wet flame
#

you add files not os.listdir(path)

#

you maybe could do os.listdir(path).sort() 😄 ? idk

#

but try first if it works

alpine shell
#

The loop? Is where

wet flame
#

for file in os.listdir(path): you change os.listdir(path) to files

alpine shell
#

So just .files

wet flame
#

no just files

#

for file in files

alpine shell
#

Ok

wet flame
#

maybe works

alpine shell
#

Nope

#

Still not alphabetical

wet flame
#

really

alpine shell
#

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

wet flame
#

so if you click ADAM all should align below adam like a column

alpine shell
#

Yh

#

That’s how I want it

wet flame
#

can you click adam first?

alpine shell
#

But it doesn’t work like that

wet flame
#

and show pic

alpine shell
#

Yh

#

Ok

#

Here u go boss

#

So I want it going down next to his name

#

Not across everyone else

wet flame
#

i cant make it work like urs

#

can u send code again

alpine shell
#

Ok

#

!close

rotund dragonBOT
#
Python help channel closed

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.