Tag Archives: from-import

A python namespace conflict, about the from import mechanism

 

from os import *
#import os

def foo():
    a = listdir("trainingDigits")
    b = open("trainingDigits/0_0.txt")

This code, if only enabled

from os import *

It will then be in

b = open(“trainingDigits/0_0.txt”)

This location reports

TypeError: Required argument ‘flags’ (pos 2) not found

If you enable only

import os

Name error: name ‘listdir’ is not defined will be reported at a = listdir (“training digits”)

The solution is

import os

def foo():
    a = os.listdir("trainingDigits")
    b = open("trainingDigits/0_0.txt")