首页 \ 问答 \ 在python中将字符串作为变量调用(calling string as variable in python)

在python中将字符串作为变量调用(calling string as variable in python)

我在python中创建了一个名为SignalParam的类,包含不同的属性(频率,电压,时间等)

我想创建这种类型的许多实例

vars()['Segment'+str(segment_number)] = SignalParam()

这条线工作,我可以创建变量“Segment1”,“Segment2”,....

我的问题是:我想把那些变种称为

"Segment"+segment_number.freqency=33

I created a class called SignalParam in python containing different properties (frequency, voltage, time, etc)

I would like to create many instances of this type

vars()['Segment'+str(segment_number)] = SignalParam()

this line is working and i can create variables "Segment1", "Segment2", ....

My question is: i would like to call those variabes like

"Segment"+segment_number.freqency=33

原文:https://stackoverflow.com/questions/30851272
更新时间:2024-04-23 17:04

最满意答案

与事务类似,语句也是原子的。 一旦语句开始执行数据更改,就会保存原始状态(实际上会记录更改)。 如果语句因任何原因失败(超时,与刚刚提交的事务冲突),则必须将更改恢复为原始状态。 该语句将报告失败但事务仍处于打开状态,您可以继续执行该事务,就像从未执行过该语句一样。

这实际上类似于保存点 - 您可以想象在记录每个语句保存点之前和语句完成之后,保存点已提交。 但是,这对外部事务或保存点没有影响。


Similarly to transaction, statement is atomic as well. Once the statement starts performing the data changes, the original state is saved (actually the changes are recorded). If statement fails for whatever reason (timeout, conflict with just committed transaction) the changes must be reverted to the original state. The statement will report a failure but the transaction is still open and you can continue with the transaction just like the statement was never executed.

This is actually similar to savepoint - you can imagine that before each statement savepoint is recorded and after statement is completed, the savepoint is committed. This has no influence on outer transaction or savepoints however.

相关问答

更多
  • 与事务类似,语句也是原子的。 一旦语句开始执行数据更改,就会保存原始状态(实际上会记录更改)。 如果语句因任何原因失败(超时,与刚刚提交的事务冲突),则必须将更改恢复为原始状态。 该语句将报告失败但事务仍处于打开状态,您可以继续执行该事务,就像从未执行过该语句一样。 这实际上类似于保存点 - 您可以想象在记录每个语句保存点之前和语句完成之后,保存点已提交。 但是,这对外部事务或保存点没有影响。 Similarly to transaction, statement is atomic as well. On ...
  • 只需在测试之上添加@Transactional注释: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"testContext.xml"}) @Transactional public class StudentSystemTest { 默认情况下,Spring将会围绕你的测试方法和@Before / @After回调开始一个新的事务,最后回滚。 默认情况下,在上下文中有一些事务管理器就足够了。 来自 ...
  • 使用您的代码,将只执行一次回滚,具体取决于条件。 您可以编写多个DB::rollback() ,只要只执行一个。 要回答这个问题,可以进行多次回滚,如果使用嵌套事务,并使用回滚/提交返回上一级别。 With your code, only one rollback will be executed, depending on the conditions. You can write multiple DB::rollback(), as long as only one gets executed. To ...
  • 您将需要在两个过程中处理事务,但是调用另一个过程的proc应检查返回值并基于此回滚它的事务。 这是内部过程的一个例子: 如何检测MySQL存储过程中的回滚? 然后,您将检查p_return_code并执行父事务的回滚。 编辑: 我认为发生的是内部SP COMMIT或ROLLBACK影响外部SP TRANSACTION。 这段代码对我有用,如果内部SP失败,它会回滚两个插入语句。 首先调用ab()工作,插入新的用户记录并插入新的游戏记录,如果我们从游戏表中删除记录并再次运行ab(),因为用户ID已经存在,它回 ...
  • 如果您需要交易,请确保您使用的是InnoDb存储引擎,而不是MyIsam。 本文有一些很好的解释和建议。 Make sure you are using InnoDb storage engine and not MyIsam if you need transactions. This article has some good explanations and advises.
  • 您的OPTIMIZE TABLE语句导致隐式提交。 我不确定你要做什么,但它看起来你可以缩短你的代码: $dbh->exec("OPTIMIZE TABLE `reservations`"); 所有其他代码只是使工作更复杂,没有任何好处。 我还假设您正在使用InnoDB表,因为MyISAM表无论如何都不支持事务。 MyISAM表上的每个DDL或DML操作都会立即隐式提交。 顺便说一下,缓冲查询与事务无关。 它们与一次获取一行SELECT结果集有关,而不是在PHP中将整个结果集提取到内存中,然后迭代它。 请 ...
  • 要在同一事务中执行多个命令,请确保将事务对象分别分配给每个命令: Dim selectCmd As MySqlCommand = con.CreateCommand() Dim insertCmd As MySqlCommand = con.CreateCommand() selectCmd.CommandText = "SELECT ..." insertCmd.CommandText = "INSERT ..." Dim sqlTran As MySqlTransaction = con.Begin ...
  • 有不同类型的崩溃。 MySQL服务器可能崩溃(就像你杀了它)或整个操作系统可能崩溃(就像拔掉机器一样)。 您应该开始阅读的内容是关于二进制日志及其工作原理以及InnoDB引擎的恢复过程 There are different kind of crashes. The MySQL server can crash (like if you kill it) or the whole Operating system can crash (like if you unplug the machine). Whe ...
  • 经过一些调试,我发现了背后的原因。 基本上这个方法: Model::createOrUpdate($data); 正在调用存储过程,所以如果有人遇到此问题,请检查是否包含此问题。 After some debugging, I found the reason behind that. Basically the method: Model::createOrUpdate($data); is calling a stored procedure within, so if anyone is havi ...
  • MySQL Workbench默认启用自动提交。 在SQL编辑器中有一个工具栏按钮,可用于随意切换自动提交: MySQL Workbench enables auto commit by default. In the SQL editor there is a toolbar button that can be used to toggle auto commit at will:

相关文章

更多

最新问答

更多
  • CSS修复容器和溢出元素(CSS Fix container and overflow elements)
  • SQL多个连接在与where子句相同的表上(SQL Multiple Joins on same table with where clause)
  • nginx 80端口反向代理多个域名,怎样隐藏端口的
  • xcode提醒样式,swift 3(xcode alert style, swift 3)
  • 在Chrome控制台中调试JavaScript(debugging javascript in Chrome console)
  • Javascript - 试图围绕自定义事件(Javascript - Trying to wrap my head around custom events)
  • 边栏链接不可点击(Sidebar links aren't clickable)
  • 使用recpatcha gem时如何显示其他表单错误?(How do I display other form errors when using the recpatcha gem?)
  • boost.python避免两次注册内部类,但仍然在python中公开(boost.python Avoid registering inner class twice but still expose in python)
  • Android 现在软件很少吗?以后会多起来吗
  • 如何在ActiveAdmin 0.5.0中为资源全局指定预先加载?(How to specify eager loading globally for a resource in ActiveAdmin 0.5.0?)
  • matlab代码为黄金比例持续分数(matlab code for golden ratio continued fraction)
  • Android浏览器触摸事件位置(Android browser touch event location)
  • 将cURL输出分配给Bash中的变量(Assign output to variable in Bash)
  • 我如何在MVC视图上没有时间获取当前日期(how i can get current date without time on MVC view)
  • sql连接函数(sql join of function)
  • 为什么在Xamarin Media插件中使用ImageSource.FromStream而不是FromFile?(Why use ImageSource.FromStream instead of FromFile in Xamarin Media plugin?)
  • 这段代码是否真的可以防止SQL注入?(Will this code actually work against SQL-injection? [duplicate])
  • 信阳方远计算机学校大专证被国家认可么
  • React / Rails AJAX POST请求返回404(React/Rails AJAX POST request returns 404)
  • Android与php服务器交互(Android interact with php server)
  • 自动刷新QTableWidget可能吗?(Refresh QTableWidget automatically possible?)
  • JVM / Compiler优化对象的未使用属性(optimization of unused properties of object by JVM / Compiler)
  • 插入表格时,乌克兰字符会更改为问号(Ukrainian character change to question mark when insert to table)
  • 在头文件中包含异常类(Including an exception class in a header file)
  • 完成c#中的执行后关闭sqlcmd(Close sqlcmd after finishing executing in c#)
  • 使用软导航栏正确检测屏幕尺寸(Detecting screensize correctly with soft navigation bar)
  • Typescript:从输入更新值(Typescript : update value from input)
  • 如何在执行某些行后仅在断点处停止?(How to only stop at a breakpoint after some line was executed?)
  • 以未定义的元素在JSON中循环(loop in JSON with undefined elements)