Jump to content

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

WillLTT
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 comment
Share on other sites

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 comment
Share on other sites

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 3600 || GPU: RTX 3070|| Memory: 32GB @ 3200 || Cooler: Scythe Big Shuriken || PSU: 650W EVGA GM || Case: NR200P

Link to comment
Share on other sites

Link to post
Share on other sites

9 minutes ago, Slottr said:

Can you post your script?

[file removed by me]

also i tested with Windows store python 3.6.7 and normal windows python 3.8

Link to comment
Share on other sites

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 3600 || GPU: RTX 3070|| Memory: 32GB @ 3200 || Cooler: Scythe Big Shuriken || PSU: 650W EVGA GM || Case: NR200P

Link to comment
Share on other sites

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 comment
Share on other sites

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 3600 || GPU: RTX 3070|| Memory: 32GB @ 3200 || Cooler: Scythe Big Shuriken || PSU: 650W EVGA GM || Case: NR200P

Link to comment
Share on other sites

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

×