首页 \ 问答 \ 如何在python文件的每一行上追加某些单词的任一侧的字符?(How do append characters on either side of certain words on every line in a file in python?)

如何在python文件的每一行上追加某些单词的任一侧的字符?(How do append characters on either side of certain words on every line in a file in python?)

假设我有一个文件my_file,并且要在文件的每一行上搜索某个单词x,并且如果该单词存在,请将我的变量y附加到单词的左侧和右侧。 然后我想用my_new_file中新的修改过的行替换旧行。 我该怎么做呢? 到目前为止我有:

output = open(omy_new_file, "w")

for line in open(my_file):

    if (" " + x + "") in line:

Say I have a file my_file, and I want to search for a certain word x on every line of the file, and if the word exists, attach my variable y to the left and right side of the word. Then I want replace the old line with the new, modified line in my_new_file. How do I do this? So far I have:

output = open(omy_new_file, "w")

for line in open(my_file):

    if (" " + x + "") in line:

原文:https://stackoverflow.com/questions/46984319
更新时间:2022-08-05 14:08

最满意答案

使用下面的代码可能会帮助你。

SELECT * FROM (`ea_users` ea) 

LEFT JOIN (SELECT GROUP_CONCAT(data) AS custom_data, id AS dataid, u_id FROM
ea_user_cfields userc GROUP BY id) AS tt ON tt.`u_id` =
`ea`.`id` 

LEFT JOIN (SELECT GROUP_CONCAT(name) AS
custom_name, id AS customid FROM ea_customfields AS cf GROUP BY id) AS
te ON tt.`c_id` = `cf`.`id` WHERE `id_roles` = '3'

Use the below code may be it helps you.

SELECT * FROM (`ea_users` ea) 

LEFT JOIN (SELECT GROUP_CONCAT(data) AS custom_data, id AS dataid, u_id FROM
ea_user_cfields userc GROUP BY id) AS tt ON tt.`u_id` =
`ea`.`id` 

LEFT JOIN (SELECT GROUP_CONCAT(name) AS
custom_name, id AS customid FROM ea_customfields AS cf GROUP BY id) AS
te ON tt.`c_id` = `cf`.`id` WHERE `id_roles` = '3'

相关问答

更多
  • 您不能在单个查询中混合隐式和显式联接。 所以解决方案是重写 FROM Grupos G, Equipa E 部分到 FROM Grupos G INNER JOIN Equipa E PS:我也没有看到连接E和G表的连接条件。 我打赌你会得到一个笛卡尔积。 You cannot mix implicit and explicit joins in a single query. So the solution is to rewrite FROM Grupos G, Equipa E part to ...
  • 两个问题。 您正在使用反引号来分隔字符串。 反引号分隔字段 ,所以MySQL认为你想给它一个列名。 该错误消息表明,实际上,它认为是列名的这个值是空的。 所以你的值$uniqueUnits[a]可能被破坏,或者没有正确插入。 您应该执行以下操作: 用“复杂语法”明确插入变量以确保字符串形式正确; 检查 $query的值,以便您可以看到发生了什么: print $query; 使用实际的引号来分隔字符串: $query = "SELECT * FROM Units WHERE ID = '{$uniqueU ...
  • 你可以试试这个: SELECT p1.order_id, p1.job_id, j1.`status` AS p1_status FROM wildcard_orders AS p1 INNER JOIN wildcard_orders AS p2 ON p1.order_id = p2.order_id LEFT JOIN wildcard_jobs AS j1 ON p1.job_id = j1.id LEFT JOIN wildcard_jobs AS j2 ON p2.job_id ...
  • 在这里你可以这样做: $id = implode("','",$selected); 此查询将运行: $query = "SELECT u.id, p.brand, n.number FROM `user` u LEFT OUTER JOIN `phone` p ON u.id = p.id LEFT OUTER JOIN `number` n ON p.id = n.id WHERE u.id in ('$id')"; Here you can do it like : $id = implode( ...
  • 您的表没有名为type的列。 此查询将失败。 要么需要将列type添加到表中,要么需要更改查询以排除引用以完全type 。 type是指什么? 我想了解你想用这个查询来达到什么目的: SELECT * FROM注释WHERE target_id ='{$ movieid}'AND user_id ='{$ user_id}'AND comment ='{$ comment}' AND type = 2 表格本身没有type时,数据库系统如何过滤结果? 经验法则首先尝试使用一些IDE或命令行直接在数据库上执行 ...
  • 尝试 SELECT `ps`.`employeeId` FROM tablePS AS `ps` CROSS JOIN tableFO AS `fo` LEFT JOIN tableWA AS `wa` ON `wa`.`employeeId` = `ps`.`employeeId` Try SELECT `ps`.`employeeId` FROM tablePS AS `ps` CROSS JOIN tableFO AS `fo` LEFT ...
  • 你正在对表格进行别名: LEFT JOIN `user` as sender 这意味着,就查询的其余部分而言,没有user表。 有一个sender表。 所以你需要在ON子句中使用别名: LEFT JOIN `user` as sender ON `sender`.`id` = `message`.`user_id` You're aliasing the table: LEFT JOIN `user` as sender Which means, as far as the rest of the q ...
  • 使用下面的代码可能会帮助你。 SELECT * FROM (`ea_users` ea) LEFT JOIN (SELECT GROUP_CONCAT(data) AS custom_data, id AS dataid, u_id FROM ea_user_cfields userc GROUP BY id) AS tt ON tt.`u_id` = `ea`.`id` LEFT JOIN (SELECT GROUP_CONCAT(name) AS custom_name, id AS custo ...
  • 您的表questions_answer可能没有列question_id Your table questions_answer may not have the column question_id
  • 如果我理解你的问题,你需要给max(id)命名 UPDATE vm s , (SELECT MAX(id) as id FROM vm) as p SET s.title = 'TEST' WHERE s.id = p.id; If I understand your question right, you need to give a name to the max(id) UPDATE vm s , (SELECT MAX(id) as id FROM vm) as p SET s.title ...

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)