Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 is something missing?
#1
Output:
File "/usr/lib/python3.6/tempfile.py", line 184, in <module> from random import Random as _Random ImportError: cannot import name 'Random'
is this a bad import or is something missing?

no... it's the danger of a new command script having the same name as a module.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote
#2
I just tried it on my system and it works fine:
>>> from random import Random as _Random
>>>
Quote
#3
create a file named random.py in your home directory and foo.py with that statement in it and try running foo.py and see what happens.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote
#4
does the file have a class named ramdom, and does that class have a method named Random?
if not, there's your reason for the fail.
Quote
#5
Your code is correct and it should work. The reason it is not working is, in the same folder, where you are running your r.py you also have file (your previous program) with the name: random.py, see this from your error print out:

File "/home/aakash/python_yt/random.py", line 5, in <module>
So what it is happening is, python ALWAYS first look into your folder for modules and it finds your random.py, and the real inbuild random function with the same name can't be called since your 'module' has always priority. Rename your previous file into something else and your current code will work as it should ;-)
Quote
#6
As I stated, you can override if your file contains a random class, (best if it inherits the original class),
and must contain methods for those you want to override.
Quote
#7
it didn't have Random in it at all. it was just a command script that prints out some random hex. it got a new name. if figured out the issue before i posted. that's why i included that 2nd line in my post. i guess it was too subtle of an answer.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)