foo.py:
i = 10
def fi():
global i
i = 99
Run Code Online (Sandbox Code Playgroud)
bar.py:
import foo
from foo import i
print i, foo.i
foo.fi()
print i, foo.i
Run Code Online (Sandbox Code Playgroud)
这是有问题的.i变化时为什么不foo.i改变?
可能重复:
为什么++ i被认为是l值,但i ++不是?
在C++(以及C语言)中,如果我写:
++x--
++(x--)
Run Code Online (Sandbox Code Playgroud)
我得到错误:左值作为增量操作数
然而(++x)--编译.我很迷惑.
为了使工件分离,包的来源不同,我的开发环境也很干净; 我settings.xml为项目组使用单独的文件.所以我用命令调用maven:
mvn -s $PROJECT_ROOT/mvn_settings.xml compile
Run Code Online (Sandbox Code Playgroud)
如何以类似的方式配置sbt?我的工作区提供了一个内部托管的JFrog存储库,它启用了sbt和Ivy插件.我尝试用各种关键字查找搜索引擎,但找不到匹配的文档.如果这是相关的,我使用带有Scala插件的IntelliJ Idea CE.
编辑1: 我希望能够控制我的工件存储位置,它们的来源以及它们与各个项目的关联.
编辑2:考虑两个settings.xml
对于我来自maven central的最小lib的随机项目:https://pastebin.com/nLc1PGa3
我公司的项目在一个大垃圾箱中:https://pastebin.com/R6a4jGQC所有来自不同的来源,在各自的文件夹中.此外,我可以独立移动我的项目,而不用担心哪个依赖链接可能会破坏其他无关的东西.
此 Scala 代码在 Scala 2.13 下编译
val res = new scala.collection.mutable.StringBuilder
"hello".foreach { c =>
if (true) {
(0 until 10).foreach( res += c )
}
}
Run Code Online (Sandbox Code Playgroud)
如果您看到该foreach方法缺少匿名函数的参数。当它被执行时,它给出了一个令人费解的异常StringIndexOutOfBoundsException,res += c因为它StringBuilder应该总是可附加的。
以下代码运行良好,没有例外。唯一的变化是添加_为foreach参数函数的占位符:
val res = new scala.collection.mutable.StringBuilder()
"hello".foreach { c =>
if (true) {
(0 until 10).foreach( _ => res += c )
}
}
Run Code Online (Sandbox Code Playgroud) 我有一些项目中没有正确格式化的Java文件.另外由于执行共同风格,很多人都引入了自己的编码风格.我想将所有这些代码整合为一致的格式.是否有可用的自动格式化程序,我可以在所有文件上作为脚本运行.我想重新思考并微调以下选项:
用于缩进的空格数.
运营商周围的空间如+ - */等
括号之间的分隔.
等等
我看着Netbeans自动格式,看起来很酷.此外,可以从选项对话框中设置参数.但是我无法完全掌握如何使用API
使用模式产生于以下原因:
如果条件不存在,我需要读取线程来等待数据.
读锁不支持条件,因此应该从写锁中获取条件.
由于读线程会等待条件,所以它也应该要求写锁定等待.
我在课堂上有以下锁定定义:
private final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
protected final Lock readLock = rwl.readLock();
protected final Lock writeLock = rwl.writeLock();
protected final Condition hasData = writeLock.newCondition();
Run Code Online (Sandbox Code Playgroud)
在我的编写器方法中,我有以下模式:
try {
writeLock.lock();
//...
if( something_written ) {
hasData.signalAll();
}
}
finally {
writeLock.unlock();
}
Run Code Online (Sandbox Code Playgroud)
在我的阅读方法中,我有以下模式
try {
readLock.lock();
while( data_absent ) {
// I need to acquire write lock to wait for condition!
try {
// first releasing read lock since we can't acquire write lock otherwise
// …Run Code Online (Sandbox Code Playgroud) 我在Qt编程,在一个事件处理程序之间,我写了这个:
void PaintedTextBrowser::mouseMoveEvent(QMouseEvent *ev)
{
...
QPoint *point = new QPoint(0, ev->pos.y());
...
}
Run Code Online (Sandbox Code Playgroud)
我在编译时遇到错误:
错误:'ev-> QMouseEvent :: pos'没有类类型
但是当我将代码修改为:
void PaintedTextBrowser::mouseMoveEvent(QMouseEvent *ev)
{
...
QPoint pos = ev->pos();
QPoint *point = new QPoint(0, pos.y());
...
}
Run Code Online (Sandbox Code Playgroud)
它工作正常.我在这里失踪的概念是什么?
有了iPhone和Android,我觉得Symbian已经过时了.但它将是开源的.然而,API看起来非常不同.有这么多不同类型的discriptors,数组和Active对象让人感到毛骨悚然.维基百科上的文章:
http://en.wikipedia.org/wiki/Symbian_OS#Developing_on_Symbian_OS
http://en.wikipedia.org/wiki/Active_objects
我认为,当它开放时,社区应该做的第一件事就是清理它.虽然很困难,但我认为这是必要的.
大多数语言都提供了使用下划线(python,C等)或camel-casing(Java)来分隔名称的不同单词的指南.但问题是何时将名称视为单独的.选项是:
1)在英语词典中出现单独的单词时,例如create_gui(),recv_msg(),createGui(),recvMsg()等.
2)使用一些直觉决定何时执行此操作以及何时不执行此操作,例如recvmsg()可以,但最好使用create_gui().
这种直觉是什么?
这个问题看起来微不足道.但它提出了一个常见问题,每个实例出现时至少需要5秒钟.
void trim(string &str)
{
string::iterator it = str.begin();
string::iterator end = str.end() - 1;
// trim at the starting
for(; it != str.end() && isspace(*it); it++)
;
str.replace(str.begin(), it, "");
// trim at the end
for(; end >= str.begin() && isspace(*end); end--)
;
str.replace(str.end(), end, ""); // i get the out_of_range exception here
}
Run Code Online (Sandbox Code Playgroud)
我想修剪一串空格.首先我从起点开始行程并且它工作正常,然后我从末尾找到空格的位置并尝试将其删除并抛出异常.
为什么?