列表在python中为空白 [英] list is coming as blank in python

查看:136
本文介绍了列表在python中为空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用配置文件中的目录路径和 prefirx_pattern。
我在vdir2和vprefix2变量中获得了正确的结果,但列表local_file_list仍然为空。

I am trying to use "directory path" and "prefirx_pattern" from config file. I get correct results in vdir2 and vprefix2 variable but list local_file_list is still empty.

result
  vdir2 is"/home/ab_meta/abfiles/"
  vprefix2 is "rp_pck."
  []

代码

def get_files(self):
     try:
        print "vdir2 is" + os.environ['dir_path']
        print "vprefix2 is "+ os.environ['prefix_pattern']
        local_file_list = filter(os.path.isfile, glob.glob(os.environ['dir_path'] + os.environ['prefix_pattern'] +  "*"))
        print local_file_list
        local_file_list.sort(key=lambda s: os.path.getmtime(os.path.join(os.environ['dir_path'], s)))
     except Exception, e:
         print e
         self.m_logger.error("Exception: Process threw an exception " + str(e))
         log.sendlog("error",50)
         sys.exit(1)
     return local_file_list

我尝试了下面给出的另一种方法,但是

I have tried another way as given below but again list is coming as empty.

第二个选项:

def get_config(self):
    try:
        v_dir_path = os.environ['dir_path']
        v_mail_prefix = os.environ['mail_prefix']
        self.m_dir_path = v_dir_path
        self.m_prefix_pattern = v_prefix_pattern
        self.m_mail_prefix = v_mail_prefix

     except KeyError, key:
           self.m_logger.error("ERROR: Unable to retrieve the key " + str(key))
     except Exception, e:
         print e
         self.m_logger.error("Error: job_prefix Unable to get variables " + str(e))
         sys.exit(1)

def get_files(self):
     try:
        local_file_list = filter(os.path.isfile, glob.glob(self.m_dir_path + self.m_prefix_pattern +  "*"))
        local_file_list.sort(key=lambda s: os.path.getmtime(os.path.join(os.environ['dir_path'], s)))
     except Exception, e:
         print e

感谢
Sandy

Thanks Sandy

推荐答案

在此程序之外,无论您在何处设置环境变量,则您未正确设置它们。您的环境变量中包含引号字符。

Outside of this program, wherever you set the environment variables, you are setting them incorrectly. Your environment variables have quote characters in them.

将环境变量设置为具有路径数据,但不带引号。

Set your environment varaibles to have the path data, but no quotes.

这篇关于列表在python中为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆