Efficient way to convert strings from split function to ints in Python

后端 未结 4 1372
执笔经年
执笔经年 2020-12-02 20:08

I have a string of data with the following format: xpos-ypos-zoom (i.e. 8743-12083-15) that I want to split up and store in the variables xpos, ypos, and zoom. Since I need

4条回答
  •  死守一世寂寞
    2020-12-02 20:50

    note: you might want to pick a different name for file as it shadows the buildtin

    this works in Python 2 and 3

    
    xval,yval,zval = map(int,file.split('-'))
    

提交回复
热议问题