小编Fer*_*l.P的帖子

从文件中读取以特定字符开头的每一行

嗨,我只是学习python,我试图读取以'X:'开头的文件中的每一行。我不想读“ X:”本身,而是接下来的其余部分。

这是到目前为止我得到的:

with open("hnr1.abc","r") as file: f = file.read()
id = []
for line in f:
    if line.startswith("X:"):
        id.append(f.line[2:])
print(id)
Run Code Online (Sandbox Code Playgroud)

它没有任何错误,但不会打印出任何内容。

python

2
推荐指数
1
解决办法
1万
查看次数

Victory Native 饼图动画

我正在尝试为我的 Victory Native 饼图中的数据变化添加动画效果。我根据 ComponentDidMount 方法中设置的重复超时从 API 获取数据。检索到数据后,我将其设置为一个状态变量,该变量将传递到 VictoryPie 组件中的 data 属性,并启用动画属性,如文档所示。

我正在关注这篇文章胜利图动画文档,但我的动画的行为方式与这些示例不同。

目前它正确设置了数据,但没有任何平滑的动画。它立即从初始状态值跳转到获取的数据值。我看到动画的唯一时间是在上次获取的值不为零之后,获取的数据返回零值。

export default class HaloXPChart extends Component {
    constructor(props) {
        super(props);
        this.state = {
            gamertag: this.props.gamertag ? this.props.gamertag : '',
            dateRetrievalInterval: 1,
            totalXp: 0,
            startXp: 0,
            spartanRank: 0,
            xpChartData: [
                {x: 'xp earned', y: 0},
                {x: 'xp remaining', y: 1}
            ],
            loading: false
        };   
    }
       
    componentDidMount() {
        this.setState({loading: true});
        this.recursiveGetData();
    }

    async recursiveGetData(){
        this.setState({indicator: true}, async () => {
            await this.getData()
            this.setState({indicator: false}); …
Run Code Online (Sandbox Code Playgroud)

react-native victory-charts victory-native

2
推荐指数
1
解决办法
2496
查看次数