对于循环头痛 [英] For loop headache

查看:73
本文介绍了对于循环头痛的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究最终的igpay atinlay任务。我已经定义了一个具有一个功能的模块:def igpay(word):它的唯一目的是将一个单词处理成猪拉丁语。它似乎运行良好。


现在,赋值的第二部分:定义一个在命令行上接受参数的模块(由于之前的问题,这是完整的)和进程整个文件进入猪拉丁语。


首先,我进行了一些基本的测试来处理文件:找到一个空格(用于分隔符),找到标点符号并测试资本。当我把它放到一个循环中时,我的逻辑似乎没有超过第一个单词。

展开 | < span class =codeLinkonclick =selectAll(this);>选择 | 换行 | 行号

解决方案

我会稍微看一下你的代码。同时,需要考虑的是文件对象本身是可迭代的。文本文件显示为行尾终止字符串的列表。所以你可以写:

展开 | 选择 | Wrap | 行号



我会看看你的代码有点。同时,需要考虑的是文件对象本身是可迭代的。文本文件显示为行尾终止字符串的列表。所以你可以写:

展开 | 选择 | Wrap | 行号


展开 | 选择 | 换行 | 行号

I''m working on the definitive igpay atinlay assignment. I''ve defined a module that has one function: def igpay(word): Its sole purpose is to process a word into pig latin. It seems to work well.

Now, the 2nd part of the assignment: Define a module that takes an argument on the command line (thanks to previous questions, this is complete) and processes the entire file into pig latin.

First I went through some basic tests to process the file: Find a space (for the delimiter), find punctuation and test for a capital. When I put this into a loop my logic doesn''t seem to get it past the first word.

Expand|Select|Wrap|Line Numbers

解决方案

I''ll look at your code in a bit. In the mean time, something to consider is that file objects, themselves, are iterable. Text files appear as lists of end-of-line terminated strings. So you can write:

Expand|Select|Wrap|Line Numbers


I''ll look at your code in a bit. In the mean time, something to consider is that file objects, themselves, are iterable. Text files appear as lists of end-of-line terminated strings. So you can write:

Expand|Select|Wrap|Line Numbers


Expand|Select|Wrap|Line Numbers


这篇关于对于循环头痛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆