Jump to content

[Python3] random.choce(list) Does not work in *.py file

Go to solution Solved by Slottr,
5 minutes ago, WillLTT said:

Oh lol I see 

 

your python file is called random. You imported the script you’re writing on. You’re not using the module, you’re using your current py file 

rchoice = random.choices(list1)

does not work when its in the PY, it spits:

Traceback (most recent call last):
  File "random.py", line 1, in <module>
    import random
  File "C:\Users\Willi\random.py", line 17, in <module>
    rchoice = random.choices(list1)
AttributeError: module 'random' has no attribute 'choices'

 

But when running the SAME with copy&paste into the shell:

No issues. Runs perfectly.

 

WHY?

Link to post
Share on other sites

Did you import random?

Community Standards || Tech News Posting Guidelines

---======================================================================---

CPU: R5 9600X || GPU: RX 9070 XT|| Memory: 32GB || Cooler: Peerless Assassin || PSU: RM850e|| Case: Lian Li A3

Link to post
Share on other sites

5 minutes ago, Slottr said:

Did you import random?

Yes. i apprichiated the reply :)

 

i launched python without any manual imports pasted the code in and it works.

 

However launching the via the py shows the error above.

Link to post
Share on other sites

Just now, WillLTT said:

Yes.

i launched python without any manual imports pasted the code in and it works.

 

However launching the via the py shows the error above.

Can you post your script?

Community Standards || Tech News Posting Guidelines

---======================================================================---

CPU: R5 9600X || GPU: RX 9070 XT|| Memory: 32GB || Cooler: Peerless Assassin || PSU: RM850e|| Case: Lian Li A3

Link to post
Share on other sites

5 minutes ago, WillLTT said:

Oh lol I see 

 

your python file is called random. You imported the script you’re writing on. You’re not using the module, you’re using your current py file 

Community Standards || Tech News Posting Guidelines

---======================================================================---

CPU: R5 9600X || GPU: RX 9070 XT|| Memory: 32GB || Cooler: Peerless Assassin || PSU: RM850e|| Case: Lian Li A3

Link to post
Share on other sites

Just now, Slottr said:

Oh lol I see 

 

your python file is called random. You imported the script you’re writing on. You’re not using the module, you’re using your current py file 

ahahahh

 

i feel so dumb

Link to post
Share on other sites

2 minutes ago, WillLTT said:

ahahahh

 

i feel so dumb

It gets the best of us sometimes

Community Standards || Tech News Posting Guidelines

---======================================================================---

CPU: R5 9600X || GPU: RX 9070 XT|| Memory: 32GB || Cooler: Peerless Assassin || PSU: RM850e|| Case: Lian Li A3

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×