---
title: "python脚本参数处理的一个技巧"
author: "standalone"
date: "2009-07-23T23:20:22Z"
tags: []
slug: "python"
draft: false
lastmod: "2009-07-23T23:21:43Z"
id: 431945
url: "https://standalone.iteye.com/blog/431945"
---

```
import sys        
        width = int(sys.argv[1]) 
        height = int(sys.argv[2]) 
        count = int(sys.argv[3]) 
        length = int(sys.argv[4]) 
        base = sys.argv[5] 
        type = sys.argv[6] 
```

 

 比较简便的做法：

```
[width, height, count, length, base, type] = sys.argv[1:] 
```

 但是这样得到的都是string，如果前面三个是int，后面两个是string呢，可以使用map函数。

```
 [width, height, count, length] = map(int, sys.argv[1:5]) 
 [base, type] = sys.argv[5:] 

 #or

 width, height, count, length = map(int, sys.argv[1:5]) 
 base, type = sys.argv[5:] 
```