python

时间:2018-07-10 11:45:49

标签: python

我想基于python脚本的名称动态生成yaml文件的名称。通常,这是我的命名约定:

  

如果测试名称为test_action_01.py

     

然后yaml文件名应为action_01.yml

所以要确保我在python脚本中有这两行(在test_action_01.py内部):

    file_name = (os.path.basename(__file__).replace("test_", "")).replace(".py", ".yml")
    pb_path = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '../playbooks', file_name))
    with open(pb_path, 'r') as f:
        pb = yaml.load(f)

当我运行脚本时,出现这个奇怪的错误:

    Traceback (most recent call last):
  File "test_create_01.py", line 22, in setUp
    with open(pb_path, 'r') as f:
IOError: [Errno 2] No such file or directory: '/data/jenkins/workspace/aws-s3-tests/aws-s3/playbooks/create_01.ymlc'

我不知道多余的“ c”字符来自哪里? 我正在使用Python2.7

2 个答案:

答案 0 :(得分:4)

您还有一个<?php if ( $query->have_posts() ) : ?> <?php while ( $query->have_posts() ) : $query->the_post(); ?> <div class="testimonials-carousel-content"><?php echo get_the_post_thumbnail();?></div> <?php endwhile; wp_reset_postdata(); ?> <?php endif; ?> 文件,其中包含(字节码),您需要检查一下,也许:

test_action_01.pyc

答案 1 :(得分:0)

cPython compiles its code to bytecode。该字节码就是执行的内容,它存储在import React from 'react'; import PropTypes from 'prop-types'; import { withStyles } from '@material-ui/core/styles'; import Table from '@material-ui/core/Table'; import TableBody from '@material-ui/core/TableBody'; import TableCell from '@material-ui/core/TableCell'; import TableHead from '@material-ui/core/TableHead'; import TableRow from '@material-ui/core/TableRow'; import Paper from '@material-ui/core/Paper'; const styles = theme => ({ root: { width: '100%', marginTop: theme.spacing.unit * 3, overflowX: 'auto', }, table: { minWidth: 700, }, }); let id = 0; function createData(name, calories, fat, carbs, protein) { id += 1; return { id, name, calories, fat, carbs, protein }; } const data = [ createData('Frozen yoghurt', 159, 6.0, 24, 4.0), createData('Ice cream sandwich', 237, 9.0, 37, 4.3), createData('Eclair', 262, 16.0, 24, 6.0), createData('Cupcake', 305, 3.7, 67, 4.3), createData('Gingerbread', 356, 16.0, 49, 3.9), ]; function SimpleTable(props) { const { classes } = props; return ( <Paper className={classes.root}> <Table className={classes.table}> <TableHead> <TableRow> <TableCell>Dessert (100g serving)</TableCell> <TableCell numeric>Calories</TableCell> <TableCell numeric>Fat (g)</TableCell> <TableCell numeric>Carbs (g)</TableCell> <TableCell numeric>Protein (g)</TableCell> </TableRow> </TableHead> <TableBody> {data.map(n => { return ( <TableRow key={n.id}> <TableCell component="th" scope="row"> {n.name} </TableCell> <TableCell numeric>{n.calories}</TableCell> <TableCell numeric>{n.fat}</TableCell> <TableCell numeric>{n.carbs}</TableCell> <TableCell numeric>{n.protein}</TableCell> </TableRow> ); })} </TableBody> </Table> </Paper> ); } SimpleTable.propTypes = { classes: PropTypes.object.isRequired, }; export default withStyles(styles)(SimpleTable); 文件中,从而可以对其进行缓存。因此,当您运行脚本时,*.pyc实际上是__file__

您可以调用test_action_01.pyc来清除它是否存在(如果没有要删除的内容,pb_path.rstrip('c')只会返回输入字符串)。