Rust 程序设计语言 简体中文版 1.85.0
env::args().collect(); 251/562Rust 程序设计语言 简体中文版 let query = &args[1]; let file_path = &args[2]; println!("Searching for {query}"); println!("In file {file_path}"); } 示例 12-2:创建变量来存放查询参数和文件路径参数 时所看到的,程序的名称占据了 vector 的第一个值 args[0],所以我 们从索引为 1 的参数开始。minigrep 获取的第一个参数是需要搜索的字符串,所以将第一个 参数的引用存放在变量 query 中。第二个参数将是文件路径,所以将第二个参数的引用放入变 量 file_path 中。 我们将临时打印出这些变量的值来证明代码如我们期望的那样工作。使用参数 test 和 sample.txt 函数处理的独立任务也会增加。当函数承担了更多责任,它就更难以 推导,更难以测试,并且更难以在不破坏其他部分的情况下做出修改。最好能分离出功能以便 每个函数各司其职。 这同时也关系到第二个问题:query 和 file_path 是程序中的配置变量,而像 contents 则用 来执行程序逻辑。随着 main 函数的增长,就需要引入更多的变量到作用域中,而当作用域中 有更多的变量时,将更难以追踪每0 码力 | 562 页 | 3.23 MB | 9 天前3Tornado 6.5 Documentation
in the formats used by HTML forms will be parsed for you and is made available in methods like get_query_argument and get_body_argument. class MyFormHandler(tornado.web.RequestHandler): def get(self): methods to allow the application to indicate whether or not it expects a list. For lists, use get_query_arguments and get_body_arguments instead of their singular counterparts. Files uploaded via a form import uimodules class HomeHandler(tornado.web.RequestHandler): def get(self): entries = self.db.query("SELECT * FROM entries ORDER BY date DESC") self.render("home.html", entries=entries) class EntryHandler(tornado0 码力 | 272 页 | 1.12 MB | 2 月前3Tornado 6.5 Documentation
in the formats used by HTML forms will be parsed for you and is made available in methods like get_query_argument and get_body_argument. class MyFormHandler(tornado.web.RequestHandler): def get(self): methods to allow the application to indicate whether or not it expects a list. For lists, use get_query_arguments and get_body_arguments instead of their singular counterparts. Files uploaded via a form import uimodules class HomeHandler(tornado.web.RequestHandler): def get(self):entries = self.db.query("SELECT * FROM entries ORDER BY date DESC") self.render("home.html", entries=entries)0 码力 | 437 页 | 405.14 KB | 2 月前3
共 3 条
- 1