如何使用python将字符串更改为','列表切换?

时间:2016-02-06 01:08:13

标签: python

我有一个像这样的字符串

string_ = 'hello world, world, hello, stackoverflow, me, not, me'

如何将其更改为这样的列表?

['hello world', 'world', 'hello', 'stackoverflow', 'me', 'not', 'me']

我试过

alist = list(string_)

但是当我格式化alist时 它显示

['h', 'e', 'l', ... ]

1 个答案:

答案 0 :(得分:2)

这应该可以解决问题:

$uploader = new Uploader();
    $data = $uploader->upload($_FILES['files'], array(
        'limit' => 8, //Maximum Limit of files. {null, Number}
        'maxSize' => 2, //Maximum Size of files {null, Number(in MB's)}
        'extensions' => array('jpg', 'png', 'gif'), //Whitelist for file extension. {null, Array(ex: array('jpg', 'png'))}
        'required' => false, //Minimum one file is required for upload {Boolean}
        'uploadDir' => UPLOAD, //Upload directory {String}
        'title' => array('auto', 30), //New file name {null, String, Array} *please read documentation in README.md
        'removeFiles' => true, //Enable file exclusion {Boolean(extra for jQuery.filer), String($_POST field name containing json data with file names)}
        'onRemove' => 'onFilesRemoveCallback' //A callback function name to be called by removing files (must return an array) | ($removed_files) | Callback
    ));

    if($data['isComplete']){
        $files = $data['data'];

        foreach($files["metas"] as $value){  

        $gallery[]=$value["name"];

        imageResize($value["file"], UPLOAD.'thumb/'.$value["name"], '190', '114', 0);

    }

    $sql_update="UPDATE `".PREFIX."users` SET `gallery`='".serialize($gallery)."' WHERE `id`=".$_POST["id"];
    query($sql_update);

       // echo '<pre>';print_r($files);echo '</pre>';
    }

    if($data['hasErrors']){
        $errors = $data['errors'];
        //print_r($errors);
    }

    function onFilesRemoveCallback($removed_files){
        foreach($removed_files as $key=>$value){
            $file = UPLOAD . $value;
            $thumb = UPLOAD.'thumb/' . $value;

            if(file_exists($file)){
                unlink($file);
            }
            if(file_exists($thumb)){
                unlink($thumb);
            }
        }

        return $removed_files;
    }